Showing posts with label Dropbox Api in c#. Show all posts
Showing posts with label Dropbox Api in c#. Show all posts

Sunday, April 1, 2012

Product Catelog App class in asp.net c# -7


view_product.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="view_product.aspx.cs" Inherits="view_product" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table>
        <tr>
            <td width="63%" align="right" valign="top">
                <table width="90%" border="0" align="right" cellpadding="0" cellspacing="0" style="padding: 40px 0 0 0;
                    margin-top: 10px;">
                    <tr>
                        <td width="90%" align="right" valign="top">
                            <table width="90%" border="0" align="right" cellpadding="0" cellspacing="0" style="margin-bottom: 25px;">
                                <tr>
                                    <td align="left">
                                        <table width="98%" align="left" cellpadding="0" cellspacing="0" style="margin: 25px 0 0 0;">
                                            <tr>
                                                <td align="left" valign="top" class="style13">
                                                    VIEW PRODUCT
                                                </td>
                                                <td width="198" height="35" align="right" valign="middle" class="style4">
                                                </td>
                                            </tr>
                                            </TBODY>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left">
                                        <table width="535" border="0" align="center" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td height="10">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <table align="center" border="0" cellpadding="0" cellspacing="0" width="535">
                                                        <tr>
                                                            <td height="10">
                                                                <table style="width: 100%">
                                                                    <tr>
                                                                        <td align="left" style="width: 50%">
                                                                            <asp:TextBox ID="txtsearch" Text="Search by ProductName" runat="server" OnClick="this.value = ''; this.style.color = 'black'" OnBlur="javascript:changeText(this.id)"></asp:TextBox>
                                                                            <asp:Button ID="Submit" runat="server" Text="Button" OnClick="Submit_Click" />
                                                                        </td>
                                                                        <td align="right" style="width: 50%">
                                                                            <asp:DropDownList ID="drpcategory" runat="server" OnSelectedIndexChanged="drpcategory_SelectedIndexChanged">
                                                                            </asp:DropDownList>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="top" width="520">
                                                                <table border="0" cellpadding="0" cellspacing="0" width="90%">
                                                                    <tr>
                                                                        <td align="center" colspan="3" height="15" valign="middle">
                                                                            <h1>
                                                                                <asp:GridView ID="gvcategory" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                                                                    CellPadding="5" DataKeyNames="CategoryId" OnPageIndexChanging="gvcategory_PageIndexChanging"
                                                                                    OnRowDeleting="gvcategory_RowDeleting" OnRowEditing="gvcategory_RowEditing" Width="80%">
                                                                                    <HeaderStyle CssClass="Head" />
                                                                                    <RowStyle CssClass="rowtext" />
                                                                                    <Columns>
                                                                                        <asp:TemplateField HeaderText="ID" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="7%">
                                                                                            <ItemTemplate>
                                                                                                <%#Container.DataItemIndex+1 %>
                                                                                            </ItemTemplate>
                                                                                            <ItemStyle HorizontalAlign="Center" Width="7%" />
                                                                                        </asp:TemplateField>
                                                                                        <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" ItemStyle-HorizontalAlign="Left">
                                                                                            <ItemStyle HorizontalAlign="Left" />
                                                                                        </asp:BoundField>
                                                                                        <asp:BoundField DataField="productname" HeaderText="ProductName" ItemStyle-HorizontalAlign="Left">
                                                                                            <ItemStyle HorizontalAlign="Left" />
                                                                                        </asp:BoundField>
                                                                                        <asp:BoundField DataField="productcode" HeaderText="ProductCode" ItemStyle-HorizontalAlign="Left">
                                                                                            <ItemStyle HorizontalAlign="Left" />
                                                                                        </asp:BoundField>
                                                                                        <asp:TemplateField HeaderText="ProductImage">
                                                                                            <ItemTemplate>
                                                                                                <img src="CreateThumbnail.aspx?image=upload/product/<%# Eval("image") %>&width=50" />
                                                                                            </ItemTemplate>
                                                                                        </asp:TemplateField>
                                                                                        <asp:CommandField ControlStyle-CssClass="link" ItemStyle-HorizontalAlign="Center"
                                                                                            ShowEditButton="True">
                                                                                            <ControlStyle CssClass="link" />
                                                                                            <ItemStyle HorizontalAlign="Center" />
                                                                                        </asp:CommandField>
                                                                                        <asp:CommandField ControlStyle-CssClass="link" ItemStyle-HorizontalAlign="Center"
                                                                                            ShowDeleteButton="True">
                                                                                            <ControlStyle CssClass="link" />
                                                                                            <ItemStyle HorizontalAlign="Center" />
                                                                                        </asp:CommandField>
                                                                                    </Columns>
                                                                                </asp:GridView>
                                                                            </h1>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="center" colspan="3" valign="middle">
                                                                            <table border="0" cellpadding="0" cellspacing="0" width="82%">
                                                                                <tr>
                                                                                    <td width="60">
                                                                                        &nbsp;
                                                                                    </td>
                                                                                </tr>
                                                                            </table>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="left" colspan="3" height="60" valign="middle">
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="left" valign="middle">
                                                                            &nbsp;
                                                                        </td>
                                                                        <td>
                                                                            &nbsp;
                                                                        </td>
                                                                        <td align="left" valign="middle">
                                                                            <a class="thickbox" style="border: none;">&nbsp;</a>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                &nbsp;
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left" valign="top">
                                                                &nbsp;
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="left" valign="top">
                                                    &nbsp;
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>







view_product.aspx.cs



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class view_product : System.Web.UI.Page
{
    BALProductMaster bal = new BALProductMaster();
    DALProductMaster dal = new DALProductMaster();
    BALCategoryMaster catbal = new BALCategoryMaster();
    DALCategoryMaster catdal = new DALCategoryMaster();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            drpcategory.DataSource = catdal.SelectCategory();
            drpcategory.DataBind();
            drpcategory.SelectedItem.Text = "category";
            drpcategory.SelectedValue = "id";
            gvbind();
        }
    }
    public void gvbind()
    {
        DataTable dt = dal.Select_ProductMaster();
        gvcategory.DataSource = dt;
        gvcategory.DataBind();
        ViewState["dtpro"] = dt;
    }
    protected void gvcategory_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string productid = gvcategory.DataKeys[e.NewEditIndex].Value.ToString();
        Response.Redirect("Add_product.aspx?id=" + productid);
    }
    protected void gvcategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int productid = int.Parse(gvcategory.DataKeys[e.RowIndex].Value.ToString());
        bal.ProductID = productid;
        dal.delete_ProductMaster(bal);
        gvbind();
    }
    protected void gvcategory_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvcategory.PageIndex = e.NewPageIndex;
        gvcategory.DataSource = (DataTable)ViewState["dtpro"];
        gvcategory.DataBind();
    }
    protected void drpcategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        catbal.CategoryId = int.Parse(drpcategory.SelectedValue.ToString());
        DataTable dt = dal.selectR_ProductMasterByCategoryId(catbal);
        gvcategory.DataSource = dt;
        gvcategory.DataBind();
        ViewState["dtpro"] = dt;
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        string search = txtsearch.Text.ToString();
        DataTable dt = dal.Select_ProductMasterSearch(search);
        gvcategory.DataSource = dt;
        gvcategory.DataBind();
        ViewState["dtcat"] = dt;
    }
}

 

Dropbox API For asp.net c#

static public class FileUtils
    {
        public enum FolderMode
        {
            /// <summary>
            /// Operate on sub-folders recursively
            /// </summary>
            Recursive,

            /// <summary>
            /// Operate on just the specified folder
            /// </summary>
            NonRecursive,
        }

        public enum CopyFileMode
        {
            /// <summary>
            /// Replace all existing files
            /// </summary>
            Replace,

            /// <summary>
            /// Replace existing files if the file write date is newer
            /// </summary>
            ReplaceIfNewer,

            /// <summary>
            /// Do not replace existing files
            /// </summary>
            SkipIfExists
        }

        /// <summary>
        /// Copy a folder to another folder with optional recursive behavior.
        /// </summary>
        static public void CopyFolder(string source, string dest, FolderMode mode, CopyFileMode fileMode)
        {
            DirectoryInfo sourceDI = new DirectoryInfo(source);
            DirectoryInfo destDI = new DirectoryInfo(dest);

            CopyFolder(sourceDI, destDI, mode, fileMode);
        }

        /// <summary>
        /// Create a folder if it does not exist
        /// </summary>
        static public void CreateFolderIfDoesNotExist(string path)
        {
            DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(path));
            if (!di.Exists)
            {
                di.Create();
            }
        }

        /// <summary>
        /// Moves a folder to another location. If the folders are on different volumes,
        /// the source folder will be copied to the destination folder then deleted.
        /// </summary>
        static public void MoveFolder(string source, string dest)
        {
            MoveFolder(new DirectoryInfo(source), new DirectoryInfo(dest));
        }

        /// <summary>
        /// Moves a folder to another location. If the folders are on different volumes,
        /// the source folder will be copied to the destination folder then deleted.
        /// </summary>
        static public void MoveFolder(DirectoryInfo source, DirectoryInfo dest)
        {
            if (source.Root == dest.Root)
            {
                source.MoveTo(dest.FullName);
            }
            else
            {
                dest.Create();
                CopyFolder(source, dest, FolderMode.Recursive, CopyFileMode.Replace);
                DeleteFolder(source.FullName);
            }
        }

        /// <summary>
        /// Copy a folder to another folder with optional recursive behavior.
        /// </summary>
        static public void CopyFolder(DirectoryInfo sourceInfo, DirectoryInfo destInfo, FolderMode mode, CopyFileMode fileMode)
        {
            if (!destInfo.Exists)
            {
                destInfo.Create();
            }

            foreach (FileInfo fi in sourceInfo.GetFiles())
            {
                CopyFile(fi, destInfo, fileMode);
            }

            if (mode == FolderMode.Recursive)
            {
                foreach (DirectoryInfo di in sourceInfo.GetDirectories())
                {
                    DirectoryInfo childDestDir = new DirectoryInfo(destInfo.FullName + "\\" + di.Name);
                    CopyFolder(di, childDestDir, mode, fileMode);
                }
            }
        }

        /// <summary>
        /// Copy a list of specified files.
        /// </summary>
        static public void CopyFiles(string sourceDir, string destDir, List<string> relativeFiles, CopyFileMode fileMode)
        {
            foreach (string file in relativeFiles)
            {
                FileInfo sourceInfo = new FileInfo(sourceDir + "\\" + file);
                DirectoryInfo destInfo = new DirectoryInfo(Path.GetDirectoryName(destDir + "\\" + file));

                CopyFile(sourceInfo, destInfo, fileMode);
            }
        }

        /// <summary>
        /// Copy a specified file.
        /// </summary>
        /// <param name="source">Source file or directory</param>
        /// <param name="dest">Destination file or directory</param>
        static public void CopyFile(string source, string dest, CopyFileMode mode)
        {
            FileInfo sourceInfo = new FileInfo(source);
            if (!sourceInfo.Exists)
            {
                return;
            }

            DirectoryInfo destInfo = new DirectoryInfo(dest);

            CopyFile(sourceInfo, destInfo, mode);
        }

        /// <summary>
        /// Copy a specified file.
        /// </summary>
        /// <param name="sourceInfo">Source file to copy.</param>
        /// <param name="destInfo">Destination directory.</param>
        static public void CopyFile(System.IO.FileInfo sourceInfo, System.IO.DirectoryInfo destInfo, CopyFileMode mode)
        {
            System.Diagnostics.Debug.Assert(sourceInfo.Exists == true, "Source file does not exist!");

            // Avoid a missing folder exception
            if (!destInfo.Exists)
            {
                destInfo.Create();
            }

            // Avoid copying over a read only file exception
            FileInfo destPathInfo = new FileInfo(destInfo.FullName + "\\" + sourceInfo.Name);

            if (destPathInfo.Exists)
            {
                if (mode == CopyFileMode.Replace ||
                    (mode == CopyFileMode.ReplaceIfNewer && destPathInfo.LastWriteTime < sourceInfo.LastWriteTime))
                {
                    destPathInfo.IsReadOnly = false;
                    destPathInfo.Delete();
                }
                else // SkipIfExists or ReplaceIfNewer fails
                {
                    return;
                }
            }

            // Perform the actual copy
            sourceInfo.CopyTo(destPathInfo.FullName, true);
        }

        /// <summary>
        /// Make the specified file read/writable
        /// </summary>
        static public void MakeFileWritable(System.IO.FileInfo fileInfo)
        {
            if (fileInfo.Exists)
            {
                fileInfo.IsReadOnly = false;
            }
        }

        /// <summary>
        /// Make the specified file read/writable
        /// </summary>
        static public void MakeFolderContentsWritable(System.IO.DirectoryInfo dirInfo, FolderMode mode)
        {
            foreach (FileInfo fi in dirInfo.GetFiles())
            {
                MakeFileWritable(fi);
            }

            if (mode == FolderMode.Recursive)
            {
                foreach (DirectoryInfo di in dirInfo.GetDirectories())
                {
                    DirectoryInfo childDestDir = new DirectoryInfo(dirInfo.FullName + "\\" + di.Name);
                    MakeFolderContentsWritable(childDestDir, mode);
                }
            }
        }

        /// <summary>
        /// Delete the specified folder (and any sub-folders/files)
        /// </summary>
        static public void DeleteFolder(string dir)
        {
            DeleteFolder(new DirectoryInfo(dir));
        }

        /// <summary>
        /// Delete the specified folder (and any sub-folders/files)
        /// </summary>
        static public void DeleteFolder(DirectoryInfo dirInfo)
        {
            if (dirInfo.Exists)
            {
                MakeFolderContentsWritable(dirInfo, FolderMode.Recursive);
                dirInfo.Delete(true);
            }
        }

        /// <summary>
        /// Given a directory select a random file from it.
        /// </summary>
        static public string SelectRandomFileFromFolder(string folderName)
        {
            DirectoryInfo di = new DirectoryInfo(folderName);

            if (di.Exists)
            {
                FileInfo[] files = di.GetFiles();
                if (files.Length > 0)
                {
                    Random randGenerator = new Random();
                    int index = randGenerator.Next(0, files.Length - 1);
                    return files[index].FullName;
                }
            }

            return null;
        }
      
        /// <summary>
        /// Computes the MD5 checksum for a single file.
        /// </summary>
        public static string ComputeMD5ForFile(string file)
        {
            FileInfo finfo = new FileInfo(file);
            BinaryReader br = new BinaryReader(finfo.OpenRead());
            byte[] fileBytes = br.ReadBytes((int)finfo.Length);
            br.Close();

            MD5 hasher = MD5.Create();
            byte[] hash = hasher.ComputeHash(fileBytes);

            StringBuilder hashString = new StringBuilder();
            foreach (byte b in hash)
            {
                hashString.Append(b.ToString("x2"));
            }
            return hashString.ToString();
        }
    }