Пример #1
0
        protected void LinkBtnExportExcel_Click(object sender, EventArgs e)
        {
            try
            {
                System.Threading.Thread.Sleep(2000);
                Response.Clear();
                Response.Buffer = true;
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Charset = "";
                string         FileName       = "CustomerSalesList.xls";
                StringWriter   strwritter     = new StringWriter();
                HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);

                GV_CustSale.GridLines             = GridLines.Both;
                GV_CustSale.HeaderStyle.Font.Bold = true;

                GV_CustSale.RenderControl(htmltextwrtter);

                Response.Write(strwritter.ToString());
                Response.End();
            }
            catch (Exception ex)
            {
                throw;
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true);
                //lblalert.Text = ex.Message;
            }
        }
Пример #2
0
        private void get_custsal(string Custid)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    if (custid != null && fdat != null && ldat != null && monid != null && yrid != null && usrid != null && areaid != null && proid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where custacc = '" + Custid + "' and Month = '" + monid + "' and CreatedAt between '" + fdat + "' and '" + ldat + "'  and year(CreatedAt) = '" + yrid + "' and createdby= '" + usrid + "' and areaid = '" + areaid + "' and ProductID ='" + proid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (custid != null && monid != null && yrid != null && usrid != null && areaid != null && proid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where custacc = '" + Custid + "' and Month = '" + monid + "' and year(CreatedAt) = '" + yrid + "' and createdby= '" + usrid + "' and areaid = '" + areaid + "' and ProductID ='" + proid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (custid != null && usrid != null && areaid != null && proid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where custacc = '" + Custid + "' and createdby= '" + usrid + "' and areaid = '" + areaid + "' and ProductID ='" + proid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (custid != null && areaid != null && proid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where custacc = '" + Custid + "' and areaid = '" + areaid + "' and ProductID ='" + proid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (custid != null && proid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where custacc = '" + Custid + "' and ProductID ='" + proid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (usrid != null && areaid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where createdby= '" + usrid + "' and areaid = '" + areaid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (custid != null && usrid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where custacc = '" + Custid + "' and createdby = '" + usrid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (usrid != null && proid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where createdby = '" + usrid + "' and ProductID ='" + proid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (usrid != null && fdat != null && ldat != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where createdby= '" + usrid + "' and CreatedAt between '" + fdat + "' and '" + ldat + "'and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    else if (custid != null)
                    {
                        cmd.CommandText = "select * from v_rptSal where custacc = '" + Custid + "' and CompanyId='" + Session["CompanyID"] + "' and BranchId='" + Session["BranchID"] + "'";
                    }
                    cmd.Connection = con;
                    con.Open();

                    DataTable      dtcustsal = new DataTable();
                    SqlDataAdapter adp       = new SqlDataAdapter(cmd);
                    adp.Fill(dtcustsal);
                    if (dtcustsal.Rows.Count > 0)
                    {
                        lbl_cust.Text = dtcustsal.Rows[0]["CustomerName"].ToString();
                        lbl_add.Text  = dtcustsal.Rows[0]["Address"].ToString();
                        lbl_phno.Text = dtcustsal.Rows[0]["PhoneNo"].ToString();

                        GV_CustSale.DataSource = dtcustsal;
                        GV_CustSale.DataBind();
                    }
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }