示例#1
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            double       agentcredit  = 0.00;
            double       emp          = 0.00;
            double       agentcash    = 0.00;
            double       totalsales   = 0.00;
            DataSet      ds           = new DataSet();
            DispatchData dispatchData = new DispatchData();
            string       Date         = Convert.ToDateTime(txtOrderDate.Text).ToString("dd-MM-yyyy");

            int salesmanid = Convert.ToInt32(dpSalesman.SelectedItem.Value);

            ds = dispatchData.GetCashier(Date, salesmanid, Convert.ToInt32(dpRoute.SelectedItem.Value), Convert.ToInt32(dpBrand.SelectedItem.Value));
            if (!Comman.Comman.IsDataSetEmpty(ds))
            {
                //Label1.Text = string.Empty;
                //Label2.Text = string.Empty;
                //Label3.Text = string.Empty;
                //Label4.Text = string.Empty;



                //try
                //{
                //    agentcash = Convert.ToDouble(ds.Tables[1].Rows[0]["AgencySale"]);
                //}
                //catch { agentcash = 0.00; }
                //try
                //{
                //    emp = Convert.ToDouble(ds.Tables[2].Rows[0]["EmployeeSale"]);
                //}
                //catch { emp = 0.00; }
                //totalsales = agentcredit + agentcash + emp;
                //Label1.Text = totalsales.ToString();
                //Label2.Text = emp.ToString();

                //Label4.Text = agentcash.ToString();
                //rpRouteList.Visible = true;
                //uprouteList.Update();

                if (ds.Tables[3].Rows.Count != 0)
                {
                    rpRouteList.DataSource = ds.Tables[3];
                    rpRouteList.DataBind();
                    uprouteList.Update();

                    Session["flag"] = "Yes";
                }
                //else if (ds.Tables[4].Rows.Count != 0)
                //{
                //    rpRouteList.DataSource = ds.Tables[4];
                //    rpRouteList.DataBind();
                //    uprouteList.Update();
                //}

                else if (ds.Tables[4].Rows.Count == 0)
                {
                    DataTable dt = new DataTable();
                    if (Label4.Text == "0" || Label4.Text == string.Empty)
                    {
                        this.BindRepeater(dt);
                        rpRouteList.Visible = true;
                        uprouteList.Update();
                    }
                    else
                    {
                        rpRouteList.DataSource = dt;
                        rpRouteList.DataBind();
                        Control FooterTemplate = rpRouteList.Controls[rpRouteList.Controls.Count - 1].Controls[0];
                        FooterTemplate.FindControl("trEmpty1").Visible = true;
                    }
                }

                double totalpaymentamt = 0.00;
                double totalpendingamt = 0.00;
                foreach (RepeaterItem item in rpRouteList.Items)
                {
                    TextBox txtpaymentamt = item.FindControl("txtPayment") as TextBox;
                    TextBox txtpendingamt = item.FindControl("txtPending") as TextBox;
                    double  paymentamt;
                    try { paymentamt = Convert.ToDouble(txtpaymentamt.Text); } catch { paymentamt = 0.00; }
                    double pendingamt;
                    try { pendingamt = Convert.ToDouble(txtpendingamt.Text); } catch { pendingamt = 0.00; }
                    totalpaymentamt += paymentamt;
                    totalpendingamt += pendingamt;
                }
                //txtPendingTotal.Text = totalpendingamt.ToString();
                double a = Math.Round(totalpaymentamt);
                //double b = Math.Round(4.5);
                //double c = Math.Round(5.5);
                //double d = Math.Round(5.51);
                //double f = Math.Round(5.49);
                Label4.Text = a.ToString();

                try
                {
                    emp = Convert.ToDouble(ds.Tables[2].Rows[0]["EmployeeSale"]);
                }
                catch { emp = 0.00; }
                Label2.Text = emp.ToString();
                double creditSchem = 0;
                if (dpBrand.SelectedItem.Value == "1")
                {
                    foreach (DataRow row in ds.Tables[4].Rows)
                    {
                        creditSchem = creditSchem + Convert.ToDouble(row["Scheme"]);
                    }
                }
                try
                {
                    agentcredit = Convert.ToDouble(ds.Tables[0].Rows[0]["AgencySale"]);
                }
                catch { agentcredit = 0.00; }
                Label3.Text = (agentcredit + creditSchem).ToString();
                Label1.Text = (totalpaymentamt + emp + creditSchem + agentcredit).ToString();

                double salesmancr = string.IsNullOrEmpty(ds.Tables[5].Rows[0]["Pending"].ToString()) ? 0 : Convert.ToDouble(ds.Tables[5].Rows[0]["Pending"].ToString());
                if (salesmancr > 0)
                {
                    lblSalesmanCr.Text      = dpSalesman.SelectedItem.Text + " has pending amt: " + salesmancr;
                    lblSalesmanCr.ForeColor = System.Drawing.Color.Red;
                    Session["flag"]         = "YesPending";
                }
                else if (salesmancr < 0)
                {
                    lblSalesmanCr.Text      = dpSalesman.SelectedItem.Text + " has Excess amt: " + Math.Abs(salesmancr);
                    lblSalesmanCr.ForeColor = System.Drawing.Color.Green;
                    Session["flag"]         = "YesExcess";
                }
                else
                {
                    lblSalesmanCr.Text      = dpSalesman.SelectedItem.Text + " has pending amt: " + Math.Abs(salesmancr);
                    lblSalesmanCr.ForeColor = System.Drawing.Color.Black;
                }
            }
            else
            {
                Label1.Text = string.Empty;
                Label2.Text = string.Empty;
                Label3.Text = string.Empty;
                Label4.Text = string.Empty;
                DataTable dt = new DataTable();
                this.BindRepeater(dt);
                rpRouteList.Visible = true;
                uprouteList.Update();
            }
        }