コード例 #1
0
ファイル: RptReport.cs プロジェクト: itktc/projectktc-v2
        private void btnOK_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            #region
            string base_ = " SELECT " +
            "c.ChId, " +
            "c.ChDate, " +
            "'KTC' Base, " +
            "c.SaleHeadId, " +
            "c.SaleReturnHeadId, " +
            "c.ChStatus, " +
            "p.SaleHeadPayTypeName, " +
            "CASE WHEN c.saleHeadId = 0 " +
            "THEN (SELECT c1.CustomerName FROM [KTC].dbo.SALERETURN_HEAD rh LEFT JOIN [KTC].dbo.CUSTOMER c1 ON c1.CustomerId = rh.CustomerId WHERE rh.SaleReturnHeadId = c.SaleReturnHeadId) " +
            "ELSE (SELECT c2.CustomerName FROM [KTC].dbo.SALE_HEAD sh LEFT JOIN [KTC].dbo.CUSTOMER c2 ON c2.CustomerId = sh.CustomerId WHERE sh.SaleHeadId = c.saleHeadId) " +
            "END CustomerName, " +
            "c.ChAmntSale, " +
            "(c.ChAmntReceive - ISNULL(c.ChChangeDef,0)) ChAmntReceive, " +
            "c.ChAmntDis " +
            "FROM [KTC].dbo.Chashier c " +
            "LEFT JOIN [KTC].dbo.SALE_HEAD h ON h.saleHeadId = c.saleHeadId " +
            "LEFT JOIN [KTC].dbo.SaleHeadPayType p ON p.SaleHeadPayTypeId = h.SaleHeadPayTypeId ";

            string b = base_.Replace("[KTC]","[7CSK]");

            string sql = "SELECT " +
            "t.ChId, " +
            "t.Base, " +
            "t.SaleHeadId, " +
            "t.SaleReturnHeadId, " +
            "t.CustomerName, " +
            "t.ChDate, " +
            "t.ChStatus, " +
            "ISNULL(t.SaleHeadPayTypeName,(CASE WHEN t.ChAmntReceive < 0 THEN 'รับคืน' ELSE 'มัดจำ' END))SaleHeadPayTypeName, ";
            if (comboBox1.SelectedIndex == 0)
            {
                sql += "CASE WHEN t.Base = 'KTC' THEN t.ChAmntReceive ELSE 0 END KTC, " +
                "CASE WHEN t.Base = '7CSK' THEN t.ChAmntReceive ELSE 0 END _7CSK, " +
                "CASE WHEN t.Base = 'SHOP' THEN t.ChAmntReceive ELSE 0 END SHOP, " +
                "CASE WHEN t.Base = 'KTC' THEN t.ChAmntDis ELSE 0 END DisKTC, " +
                "CASE WHEN t.Base = '7CSK' THEN t.ChAmntDis ELSE 0 END Dis_7CSK, " +
                "CASE WHEN t.Base = 'SHOP' THEN t.ChAmntDis ELSE 0 END DisSHOP, ";
            }
            else
            {
                sql += "t.ChAmntReceive SHOP, " +
                    "t.ChAmntDis DisSHOP, ";
            }
            sql += "t.ChAmntReceive AmntList, " +
            "t.ChAmntDis " +
            "FROM " +
            "(";
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    {
                        sql += base_.Replace("KTC", "KTC") + " UNION ALL " +
                        base_.Replace("KTC", "7CSK") + " UNION ALL " +
                        base_.Replace("KTC", "SHOP");
                        break;
                    }
                case 1:
                    {
                        sql += base_.Replace("KTC", "KTC");
                        break;
                    }
                case 2:
                    {
                        sql += base_.Replace("KTC", "7CSK");
                        break;
                    }
                case 3:
                    {
                        sql += base_.Replace("KTC", "SHOP");
                        break;
                    }

            }

            sql += ")t " +
            "WHERE CONVERT(VARCHAR(10),t.ChDate,111) = '2015/11/25' AND t.ChStatus IS NULL " +
            "ORDER BY t.ChDate";
            sql = sql.Replace("2015/11/25", Class.Function.GetDate(dateTimePicker1.Value).Replace("-","/"));

            DataTable dt = cls.QueryDataTable(sql);
            dt.TableName = "DT_CashierSumDaily";
            ds.Tables.Add(dt);

            #endregion

            #region
            string sqlbase = "SELECT 'KTC' Brch, " +
            "cs.SId,cs.SDate,cs.SAmnt,cs.SNote,cs.SPeriod,cs.CashierStatusId " +
            ",'[' + ul.UserName + '] ' + ul.SureName + ' ' + ul.LastName Sender " +
            "FROM [KTC].dbo.CashierSend cs " +
            "INNER JOIN dbo.UserLogin ul ON ul.UserName = cs.UserName ";

            sql = "SELECT " +
            "t.SId,t.Brch,t.SDate,t.SNote,t.Sender,t.SPeriod,t.CashierStatusId, ";
            if (comboBox1.SelectedIndex == 0)
            {
                sql += "CASE t.Brch WHEN 'KTC' THEN t.SAmnt ELSE 0 END KTC, " +
                "CASE t.Brch WHEN '7CSK' THEN t.SAmnt ELSE 0 END _7CSK, " +
                "CASE t.Brch WHEN 'SHOP' THEN t.SAmnt ELSE 0 END SHOP, ";
            }
            else
            {
                sql += " t.SAmnt SHOP, ";
            }
            sql += "t.SAmnt AmntListSum " +
            "FROM( ";

            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    {
                        sql += sqlbase.Replace("KTC", "KTC") + " UNION ALL " +
                        sqlbase.Replace("KTC", "7CSK") + " UNION ALL " +
                        sqlbase.Replace("KTC", "SHOP");
                        break;
                    }
                case 1:
                    {
                        sql += sqlbase.Replace("KTC", "KTC");
                        break;
                    }
                case 2:
                    {
                        sql += sqlbase.Replace("KTC", "7CSK");
                        break;
                    }
                case 3:
                    {
                        sql += sqlbase.Replace("KTC", "SHOP");
                        break;
                    }

            }
            sql += ")t " +
            "WHERE t.SDate = '2015-12-01' AND t.CashierStatusId <> 2 ";

            sql = sql.Replace("2015-12-01", Class.Function.GetDate(dateTimePicker1.Value));

            DataTable dt1 = cls.QueryDataTable(sql);
            dt1.TableName = "DT_CashierSumDaily1";
            ds.Tables.Add(dt1);
            #endregion

            ds.DataSetName = "DataSet";

            if (comboBox1.SelectedIndex == 0)
            {
                Report.CtrCashierSumDaily r = new Report.CtrCashierSumDaily();
                r.Subreports["Sub1"].SetDataSource(dt);
                r.Subreports["Sub2"].SetDataSource(ds);

                r.SetParameterValue("_SumKTC", dt.Select().Sum(q => q.Field<decimal>("KTC")), "Sub2");
                r.SetParameterValue("_Sum7CSK", dt.Select().Sum(q => q.Field<decimal>("_7CSK")), "Sub2");
                r.SetParameterValue("_SumSHOP", dt.Select().Sum(q => q.Field<decimal>("SHOP")), "Sub2");
                r.SetParameterValue("_SumAmnt", dt.Select().Sum(q => q.Field<decimal>("AmntList")), "Sub2");

                r.SetParameterValue("_SumDisKTC", dt.Select().Sum(q => q.Field<decimal>("DisKTC")), "Sub2");
                r.SetParameterValue("_SumDis7CSK", dt.Select().Sum(q => q.Field<decimal>("Dis_7CSK")), "Sub2");
                r.SetParameterValue("_SumDisSHOP", dt.Select().Sum(q => q.Field<decimal>("DisSHOP")), "Sub2");
                r.SetParameterValue("_SumDisAmnt", dt.Select().Sum(q => q.Field<decimal>("ChAmntDis")), "Sub2");

                r.SetParameterValue("_DateTime", dateTimePicker1.Value);

                crystalReportViewer1.ReportSource = r;
                crystalReportViewer1.Show();
                crystalReportViewer1.Refresh();
            }
            else
            {
                Report.CtrCashierSumDailyEach r = new Report.CtrCashierSumDailyEach();
                r.Subreports["Sub1"].SetDataSource(dt);
                r.Subreports["Sub2"].SetDataSource(ds);

                r.SetParameterValue("_SumSHOP", dt.Select().Sum(q => q.Field<decimal>("SHOP")), "Sub2");
                r.SetParameterValue("_SumAmnt", dt.Select().Sum(q => q.Field<decimal>("AmntList")), "Sub2");

                r.SetParameterValue("_SumDisSHOP", dt.Select().Sum(q => q.Field<decimal>("DisSHOP")), "Sub2");
                r.SetParameterValue("_SumDisAmnt", dt.Select().Sum(q => q.Field<decimal>("ChAmntDis")), "Sub2");

                r.SetParameterValue("_DateTime", dateTimePicker1.Value);

                r.SetParameterValue("_Title", comboBox1.Text.Trim());

                r.SetParameterValue("_txtBase", comboBox1.Text.Trim(), "Sub1");
                r.SetParameterValue("_txtBase", comboBox1.Text.Trim(), "Sub2");

                r.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
                //r.PrintOptions.ApplyPageMargins(new CrystalDecisions.Shared.PageMargins(0, 0, 0, 0));

                crystalReportViewer1.ReportSource = r;
                crystalReportViewer1.Show();
                crystalReportViewer1.Refresh();
            }
        }
コード例 #2
0
ファイル: frmRptReport.cs プロジェクト: itktc/projectktc-v2
        private void btnOK_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = "";
            DataTable dt;
            if (this.case_ != Case_.CashierNew)
            {
                #region
                string base_ = " SELECT " +
                "c.ChId, " +
                "c.ChDate, " +
                "'KTC' Base, " +
                "c.SaleHeadId, " +
                "c.SaleReturnHeadId, " +
                "p.SaleHeadPayTypeName, " +
                "CASE WHEN c.saleHeadId = 0 " +
                "THEN (SELECT c1.CustomerName FROM [KTC].dbo.SALERETURN_HEAD rh LEFT JOIN [KTC].dbo.CUSTOMER c1 ON c1.CustomerId = rh.CustomerId WHERE rh.SaleReturnHeadId = c.SaleReturnHeadId) " +
                "ELSE (SELECT c2.CustomerName FROM [KTC].dbo.SALE_HEAD sh LEFT JOIN [KTC].dbo.CUSTOMER c2 ON c2.CustomerId = sh.CustomerId WHERE sh.SaleHeadId = c.saleHeadId) " +
                "END CustomerName, " +
                "c.ChAmntSale, " +
                "(c.ChAmntReceive - ISNULL(c.ChChangeDef,0)) ChAmntReceive, " +
                "c.ChAmntDis " +
                "FROM [KTC].dbo.Chashier c " +
                "LEFT JOIN [KTC].dbo.SALE_HEAD h ON h.saleHeadId = c.saleHeadId " +
                "LEFT JOIN [KTC].dbo.SaleHeadPayType p ON p.SaleHeadPayTypeId = h.SaleHeadPayTypeId ";

                string b = base_.Replace("[KTC]", "[7CSK]");

                sql = "SELECT " +
                "t.ChId, " +
                "t.Base, " +
                "t.SaleHeadId, " +
                "t.SaleReturnHeadId, " +
                "t.CustomerName, " +
                "t.ChDate, " +
                "ISNULL(t.SaleHeadPayTypeName,(CASE WHEN t.ChAmntReceive < 0 THEN 'รับคืน' ELSE 'มัดจำ' END))SaleHeadPayTypeName, ";
                if (comboBox1.SelectedIndex == 0)
                {
                    sql += "CASE WHEN t.Base = 'KTC' THEN t.ChAmntReceive ELSE 0 END KTC, " +
                    "CASE WHEN t.Base = '7CSK' THEN t.ChAmntReceive ELSE 0 END _7CSK, " +
                    "CASE WHEN t.Base = 'SHOP' THEN t.ChAmntReceive ELSE 0 END SHOP, " +
                    "CASE WHEN t.Base = 'KTC' THEN t.ChAmntDis ELSE 0 END DisKTC, " +
                    "CASE WHEN t.Base = '7CSK' THEN t.ChAmntDis ELSE 0 END Dis_7CSK, " +
                    "CASE WHEN t.Base = 'SHOP' THEN t.ChAmntDis ELSE 0 END DisSHOP, ";
                }
                else
                {
                    sql += "t.ChAmntReceive SHOP, " +
                        "t.ChAmntDis DisSHOP, ";
                }
                sql += "t.ChAmntReceive AmntList, " +
                "t.ChAmntDis " +
                "FROM " +
                "(";
                switch (comboBox1.SelectedIndex)
                {
                    case 0:
                        {
                            sql += base_.Replace("KTC", "KTC") + " UNION ALL " +
                            base_.Replace("KTC", "7CSK") + " UNION ALL " +
                            base_.Replace("KTC", "SHOP");
                            break;
                        }
                    case 1:
                        {
                            sql += base_.Replace("KTC", "KTC");
                            break;
                        }
                    case 2:
                        {
                            sql += base_.Replace("KTC", "7CSK");
                            break;
                        }
                    case 3:
                        {
                            sql += base_.Replace("KTC", "SHOP");
                            break;
                        }
                    case 4:
                        {
                            sql += base_.Replace("KTC", "KTC_TEST");
                            break;
                        }

                }

                sql += ")t " +
                "WHERE CONVERT(VARCHAR(10),t.ChDate,111) = '2015/11/25' " +
                "ORDER BY t.ChDate";
                sql = sql.Replace("2015/11/25", Class.Function.GetDate(dateTimePicker1.Value).Replace("-", "/"));

                dt = cls.QueryDataTable(sql);
                dt.TableName = "DT_CashierSumDaily";
                ds.Tables.Add(dt);

                #endregion
            }
            else
            {
                string b;
                switch (comboBox1.SelectedIndex)
                {
                    case 1:
                        {
                            b = "KTC";
                            break;
                        }
                    case 2:
                        {
                            b = "[7CSK]";
                            break;
                        }
                    case 3:
                        {
                            b = "SHOP";
                            break;
                        }
                    case 4:
                        {
                            b = "KTC_TEST";
                            break;
                        }
                    default:
                        {
                            b = "KTC";
                            break;
                        }

                }

                sql = " USE " + b +
                " SELECT * FROM (SELECT " +////////////////////////////////////////
                "c.ChId " +
                ",ISNULL(c.SaleHeadId,c.SaleReturnHeadId)BillNo " +
                ",CASE WHEN substring(ssh.SaleHeadId,1,2) ='SC' THEN 'เงินสด'" +
                "WHEN substring(c.SaleHeadId,1,2) ='SO' THEN 'รับชำระหนี้'" +
                "WHEN c.SaleHeadId IS NULL THEN ( " +
                " CASE WHEN substring(c.SaleReturnHeadId,1,2) = 'CN' THEN 'ลดหนี้' ELSE 'รับคืน' END " +
                ") END Case_" +
                ",c2.CustomerName " +
                ",ISNULL(rsh.ReHeadDate,ssh.SaleHeadDate)ChDate " +
                ",CASE WHEN ssh.Cash IS NULL THEN -rsh.Cash ELSE ssh.Cash END Cash " +
                ",c.ChAmnt " +
                ",c.ChAmntCash - ISNULL(c.ChChangeDef,0) ChAmntRec " +
                //",ISNULL(c.ChAmntTransfer,0) + ISNULL(c.ChComTransfer,0) ChAmntTransfer " +
                ",ISNULL(c.ChAmntTransfer,0) ChAmntTransfer " +
                ",ISNULL(c.ChAmntCheque,0)ChAmntCheque " +
                ",ISNULL(c.ChAmntDepositPay,0) ChAmntDepositPay " +
                ",ISNULL(c.ChChangeDef,0)ChChangeDef " +
                ",ISNULL(c.ChCredit,0)ChCredit " +
                "FROM dbo.ChashierNew c " +
                "INNER JOIN dbo.CUSTOMER c2 ON c2.CustomerId = c.CustomerId " +
                "LEFT JOIN dbo.SALE_STORE_HEAD ssh ON ssh.SaleHeadId = c.SaleHeadId " +
                "LEFT JOIN dbo.RE_STORE_HEAD rsh ON c.SaleReturnHeadId = rsh.ReHeadId " +
                "WHERE c.CashierStatusId <> 2 AND c.ChDate = '" + Class.Function.GetDate(dateTimePicker1.Value) + "' " +
                "UNION ALL " +
                "SELECT c.ChId ,CAST(ISNULL(c.SaleHeadId,c.SaleReturnHeadId) AS varchar(15))BillNo " +
                ",CASE WHEN ssh.SaleHeadPayTypeId = 1 THEN 'เงินสด'WHEN ssh.SaleHeadPayTypeId > 1 THEN 'รับชำระหนี้'WHEN c.SaleHeadId IS NULL THEN 'รับคืน' END Case_ " +
                ",( " +
                "	CASE  " +
                "		WHEN c.SaleHeadId <> 0  " +
                "			THEN " +
                "				(SELECT c2.CustomerName FROM dbo.CUSTOMER c2 INNER JOIN dbo.SALE_HEAD sh ON sh.CustomerId = c2.CustomerId WHERE sh.SaleHeadId = c.SaleHeadId) " +
                "		WHEN c.SaleHeadId = 0  " +
                "			THEN  " +
                "				(SELECT c2.CustomerName FROM dbo.CUSTOMER c2 INNER JOIN dbo.SALERETURN_HEAD sh ON sh.CustomerId = c2.CustomerId WHERE sh.SaleReturnHeadId = c.SaleReturnHeadId)  " +
                "	END " +
                ") CustomerName " +
                ",ISNULL(rsh.SaleReturnHeadDate,ssh.SaleHeadDate)ChDate  " +
                ",c.ChAmntSale Cash ,c.ChAmntSale ChAmnt ,(c.ChAmntReceive - ISNULL(c.ChChangeDef,0)) ChAmntRec ,0 ChAmntTransfer ,0 ChAmntCheque ,0 ChAmntDepositPay ,c.ChAmntDis ChChangeDef ,0 ChCredit  " +
                "FROM dbo.Chashier c " +
                "LEFT JOIN dbo.SALE_HEAD ssh ON ssh.SaleHeadId = c.SaleHeadId  " +
                "LEFT JOIN dbo.SALERETURN_HEAD rsh ON c.SaleReturnHeadId = rsh.SaleReturnHeadId  " +
                "WHERE  c.ChDate = '" + Class.Function.GetDate(dateTimePicker1.Value) + "'  " +
                "UNION ALL " +
                "SELECT  " +
                "eh.EarnestId " +
                ",NULL " +
                ",'มัดจำ' " +
                ",c.CustomerName " +
                ",eh.EarnestDate " +
                ",NULL " +
                ",ISNULL(CASE WHEN EarnestAmntCash IS NULL THEN (CASE WHEN EarnestAmntTransfer IS NULL THEN (CASE WHEN EarnestAmntCheque IS NULL  THEN 0 ELSE EarnestAmntCheque END) ELSE EarnestAmntTransfer END) ELSE EarnestAmntCash END,0)  " +
                ",ISNULL(eh.EarnestAmntCash,0) " +
                ",ISNULL(eh.EarnestAmntTransfer - ISNULL(eh.EarnestChargeTR,0),0)" +
                ",ISNULL(eh.EarnestAmntCheque,0) " +
                ",NULL " +
                ",NULL " +
                ",NULL " +
                "FROM dbo.EarnestHead eh " +
                "INNER JOIN dbo.CUSTOMER c ON c.CustomerId = eh.CustId " +
                "WHERE eh.EarnestDate = '" + Class.Function.GetDate(dateTimePicker1.Value) + "' )AS t ORDER BY t.ChId";
                dt = cls.QueryDataTable(sql);

                foreach (DataRow r in dt.Rows)
                {
                    decimal amntCash = 0;
                    decimal.TryParse(r["ChAmntRec"].ToString(), out amntCash);
                    if (amntCash != 0)
                    {
                        foreach (DataRow rr in dt.Rows)
                        {
                            if (rr["ChId"].ToString() == r["ChId"].ToString() && Convert.ToDecimal(rr["ChAmntTransfer"] == DBNull.Value ? "0" : rr["ChAmntTransfer"]) != 0)
                            {
                                //r["ChAmntTransfer"] = amntCash;
                                r["ChAmntRec"] = amntCash;
                                break;
                            }
                            else if (rr["ChId"].ToString() == r["ChId"].ToString() && Convert.ToDecimal(rr["ChAmntCheque"] == DBNull.Value ? "0" : rr["ChAmntCheque"]) != 0)
                            {
                                //r["ChAmntCheque"] = amntCash;
                                r["ChAmntRec"] = amntCash;
                                break;
                            }
                            else if (rr["ChId"].ToString() == r["ChId"].ToString() && Convert.ToDecimal(rr["ChAmntDepositPay"] == DBNull.Value ? "0" : rr["ChAmntDepositPay"]) != 0)
                            {
                                //r["ChAmntCheque"] = amntCash;
                                //r["ChAmntRec"] = 0;
                                break;
                            }
                        }
                    }
                }

                dt.TableName = "DT_CashierSumDailyEachNew";
                ds.Tables.Add(dt);
                //goto pl;
            }

            #region
            string sqlbase = "SELECT 'KTC' Brch, " +
            "cs.SId,cs.SDate,cs.SAmnt,cs.SNote,cs.SPeriod,cs.CashierStatusId " +
            ",'[' + ul.UserName + '] ' + ul.SureName + ' ' + ul.LastName Sender " +
            "FROM [KTC].dbo.CashierSend cs " +
            "INNER JOIN dbo.UserLogin ul ON ul.UserName = cs.UserName ";

            sql = "SELECT " +
            "t.SId,t.Brch,t.SDate,t.SNote,t.Sender,t.SPeriod,t.CashierStatusId, ";
            if (comboBox1.SelectedIndex == 0)
            {
                sql += "CASE t.Brch WHEN 'KTC' THEN t.SAmnt ELSE 0 END KTC, " +
                "CASE t.Brch WHEN '7CSK' THEN t.SAmnt ELSE 0 END _7CSK, " +
                "CASE t.Brch WHEN 'SHOP' THEN t.SAmnt ELSE 0 END SHOP, ";
            }
            else
            {
                sql += " t.SAmnt SHOP, ";
            }
            sql += "t.SAmnt AmntListSum " +
            "FROM( ";

            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    {
                        sql += sqlbase.Replace("KTC", "KTC") + " UNION ALL " +
                        sqlbase.Replace("KTC", "7CSK") + " UNION ALL " +
                        sqlbase.Replace("KTC", "SHOP");
                        break;
                    }
                case 1:
                    {
                        sql += sqlbase.Replace("KTC", "KTC");
                        break;
                    }
                case 2:
                    {
                        sql += sqlbase.Replace("KTC", "7CSK");
                        break;
                    }
                case 3:
                    {
                        sql += sqlbase.Replace("KTC", "SHOP");
                        break;
                    }
                default:
                    {
                        sql += sqlbase.Replace("KTC", "KTC_TEST");
                        break;
                    }

            }
            sql += ")t " +
            "WHERE t.SDate = '2015-12-01' AND t.CashierStatusId <> 2 ";

            sql = sql.Replace("2015-12-01", Class.Function.GetDate(dateTimePicker1.Value));

            DataTable dt1 = cls.QueryDataTable(sql);
            dt1.TableName = "DT_CashierSumDaily1";
            ds.Tables.Add(dt1);
            #endregion

            ds.DataSetName = "DataSet";

            //pl:

            if (this.case_ != Case_.CashierNew)
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    Report.CtrCashierSumDaily r = new Report.CtrCashierSumDaily();
                    r.Subreports["Sub1"].SetDataSource(dt);
                    r.Subreports["Sub2"].SetDataSource(ds);

                    r.SetParameterValue("_SumKTC", dt.Select().Sum(q => q.Field<decimal>("KTC")), "Sub2");
                    r.SetParameterValue("_Sum7CSK", dt.Select().Sum(q => q.Field<decimal>("_7CSK")), "Sub2");
                    r.SetParameterValue("_SumSHOP", dt.Select().Sum(q => q.Field<decimal>("SHOP")), "Sub2");
                    r.SetParameterValue("_SumAmnt", dt.Select().Sum(q => q.Field<decimal>("AmntList")), "Sub2");

                    r.SetParameterValue("_SumDisKTC", dt.Select().Sum(q => q.Field<decimal>("DisKTC")), "Sub2");
                    r.SetParameterValue("_SumDis7CSK", dt.Select().Sum(q => q.Field<decimal>("Dis_7CSK")), "Sub2");
                    r.SetParameterValue("_SumDisSHOP", dt.Select().Sum(q => q.Field<decimal>("DisSHOP")), "Sub2");
                    r.SetParameterValue("_SumDisAmnt", dt.Select().Sum(q => q.Field<decimal>("ChAmntDis")), "Sub2");

                    r.SetParameterValue("_DateTime", dateTimePicker1.Value);

                    crystalReportViewer1.ReportSource = r;
                    crystalReportViewer1.Show();
                    crystalReportViewer1.Refresh();
                }
                else
                {
                    Report.CtrCashierSumDailyEach r = new Report.CtrCashierSumDailyEach();
                    r.Subreports["Sub1"].SetDataSource(dt);
                    r.Subreports["Sub2"].SetDataSource(ds);

                    r.SetParameterValue("_SumSHOP", dt.Select().Sum(q => q.Field<decimal>("SHOP")), "Sub2");
                    r.SetParameterValue("_SumAmnt", dt.Select().Sum(q => q.Field<decimal>("AmntList")), "Sub2");

                    r.SetParameterValue("_SumDisSHOP", dt.Select().Sum(q => q.Field<decimal>("DisSHOP")), "Sub2");
                    r.SetParameterValue("_SumDisAmnt", dt.Select().Sum(q => q.Field<decimal>("ChAmntDis")), "Sub2");

                    r.SetParameterValue("_DateTime", dateTimePicker1.Value);

                    r.SetParameterValue("_Title", comboBox1.Text.Trim());

                    r.SetParameterValue("_txtBase", comboBox1.Text.Trim(), "Sub1");
                    r.SetParameterValue("_txtBase", comboBox1.Text.Trim(), "Sub2");

                    crystalReportViewer1.ReportSource = r;
                    crystalReportViewer1.Show();
                    crystalReportViewer1.Refresh();
                }
            }
            else
            {
                if (comboBox1.SelectedIndex == 0)
                {

                }
                else
                {
                    Report.CtrCashierNewSumDailyEach r = new Report.CtrCashierNewSumDailyEach();
                    r.SetDataSource(ds);//_AmntCashRec
                    r.Subreports["sub1"].SetDataSource(dt1);

                    decimal sum = 0;
                    for (int i = 0; i < dt.Rows.Count; ++i)
                        sum += dt.Rows[i]["ChAmntRec"] == DBNull.Value ? 0 : Convert.ToDecimal(dt.Rows[i]["ChAmntRec"]);

                    r.SetParameterValue("_AmntCashRec", sum, "Sub1");
                    r.SetParameterValue("_DateTime",dateTimePicker1.Value.ToShortDateString());
                    r.SetParameterValue("_Title", comboBox1.Text.Trim());
                    crystalReportViewer1.ReportSource = r;
                    crystalReportViewer1.Show();
                    crystalReportViewer1.Refresh();
                }
            }
        }