コード例 #1
0
ファイル: DecNoteInter.cs プロジェクト: itktc/projectktc-v2
        private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox13.Text == "")
                {
                    MessageBox.Show("กรุณาเลือกลูกค้า");
                    return;
                }
                if (Class.Function.GetTextId(textBox13.Text) == null)
                {
                    MessageBox.Show("กรุณาเลือกลูกค้า");
                    return;
                }

                Dialog.frmDialogSearchRequis frm = new Dialog.frmDialogSearchRequis(textBox11.Text.Trim(), Class.Function.GetTextId(textBox13.Text).ToString());
                frm.ShowDialog();

                if (frm.DialogResult == DialogResult.OK)
                {
                    String sid = frm.GetShipperId();
                    //String sql = "select d.productid,p.productname,d.saleappdetailquantitypack,up.unitpackname,d.saleappdetailquantity,u.unitsalename,d.saleappdetailweight,d.productapptype," +
                    //    "h.sdateid from sale_app_detail d " +
                    //    "inner join sale_app_head h on h.saleappheadid = d.saleappheadid inner join product p on d.productid = p.productid inner join unitsale u on u.unitsaleid = p.unitsaleid " +
                    //    "inner join unitpack up on up.unitpackid = p.unitpackid where h.sid = " + sid;

                    String sql = "select d.productid,p.productname,d.InvDetailQuantityPack,up.unitpackname,d.InvDetailQuantity," +
                       "u.unitsalename,d.InvDetailWeight,d.detailType,h.InvHeadId,d.InvDetailId,d.ProductBorderId,b.ProductBorderName " +
                       "from INVOICE_ORIGINAL_DETAIL d " +
                       "inner join INVOICE_ORIGINAL_HEAD h on h.InvHeadId = d.InvHeadId " +
                       "inner join product p on d.productid = p.productid " +
                       "inner join unitsale u on u.unitsaleid = p.unitsaleid " +
                       "INNER JOIN PRODUCT_BORDER b ON b.ProductBorderId=d.ProductBorderId " +
                       "inner join unitpack up on up.unitpackid = p.unitpackid where h.InvHeadId = " + sid;

                    List<string> sidNew = new List<string>();

                    List<string> ProductId = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("productid")).ToList();
                    List<string> ProductName = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("productname")).ToList();
                    List<string> ProductBorderName = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("ProductBorderName")).ToList();
                    List<string> QuantityPack = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<double>("saleappdetailquantitypack").ToString()).ToList();
                    List<string> Quantity = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<double>("saleappdetailquantity").ToString()).ToList();
                    List<string> UnitPackName = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("unitpackname")).ToList();
                    List<string> UnitSaleName = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("unitsalename")).ToList();
                    List<string> Weight = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<double>("saleappdetailweight").ToString()).ToList();
                    List<string> type = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<int>("productapptype").ToString()).ToList();
                    List<string> sdate = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("sdateid")).ToList();
                    for (int i = 0; i < ProductId.Count; i++)
                    {
                        sidNew.Add(sid);
                    }

                    if (sidNew.Intersect(sidOld).Count() > 0)
                    {
                        MessageBox.Show("ใบเบิกนี้ถูกเลือกแล้ว");
                        return;
                    }
                    else
                    {
                        sidOld.Add(sid);
                        for (int i = 0; i < ProductId.Count; i++)
                        {
                            String w = "";
                            String sqlw = "select * from sale_app_weight w inner join sale_app_head h on w.saleappheadid = h.saleappheadid where w.productid = '" + ProductId[i] + "' " +
                            "AND h.sid = '" + sid + "' ";

                            System.Data.SqlClient.SqlDataReader readerw = Class.DBConnString.clsDB.QueryDataReader(sqlw);
                            if (type[i] != "3")
                            {
                                while (readerw.Read())
                                {
                                    w += readerw["SaleAppPackId"].ToString() + "#";
                                    w += readerw["SaleAppPack"].ToString() + "#";
                                    if (type[i] == "1")
                                    {
                                        w += readerw["SaleAppWeight"].ToString() + "#";
                                    }
                                }
                            }
                            lProidOld.Add(new ListId
                            {
                                ProductId = ProductId[i],
                                ProductName = ProductName[i],
                                ProductBorderName = ProductBorderName[i],
                                UnitPackName = UnitPackName[i],
                                UnitSaleName = UnitSaleName[i],
                                QuantityPack = QuantityPack[i],
                                Quantity = Quantity[i],
                                Weight = Weight[i],
                                type = type[i],
                                sdate = sdate[i],
                                price = "0.00",
                                distext = "0",
                                disper = "0.00",
                                dis = "0.00",
                                total = "0.00"
                            });
                            loadGridSale(ProductId[i], ProductName[i], ProductBorderName[i], Convert.ToDouble(QuantityPack[i]).ToString("#,##0.00"), UnitPackName[i],
                                Convert.ToDouble(Quantity[i]).ToString("#,##0.00"), UnitSaleName[i], "0.00",
                                Convert.ToDouble(Weight[i]).ToString("#,##0.00"), Convert.ToInt16(type[i]).ToString(), w, sdate[i].ToString(),
                                "0", "0.00", "0.00", "0.00");
                            //loadGridSale(ProductId[i], ProductName[i], UnitPackName[i], UnitSaleName[i], "0.00",
                            //    Convert.ToDouble(QuantityPack[i]).ToString("#,##0.00"), Convert.ToDouble(Quantity[i]).ToString("#,##0.00"),
                            //    Convert.ToDouble(Weight[i]).ToString("#,##0.00"), Convert.ToInt16(type[i]).ToString(), w, sdate[i].ToString(),
                            //    "0", "0.00", "0.00", "0.00");
                        }
                        //Convert.ToDouble(Class.Function.SaleTopReturnPriceAndDate(ProductId[i], Class.DBConnString.sDb, Class.Function.GetTextId(textBox13.Text))).ToString("#,##0.00")
                        ///////////////
                        setCalulate();
                        ///////////////
                    }
                    Class.Function.SetDgvWeightFnc(dataGridView1.Rows[0].Cells[17].Value.ToString(), dataGridView2, dataGridView1.Rows[0].Cells[18].Value.ToString());
                }
            }
        }
コード例 #2
0
ファイル: SalePos.cs プロジェクト: itktc/projectktc-v2
        /*ดึงข้อมูลจากใบเบิก*/
        private void valuesRO()
        {
            if (textBox13.Text == "")
            {
                MessageBox.Show("กรุณาเลือกลูกค้า");
                return;
            }
            if (Class.Function.GetTextId(textBox13.Text) == null)
            {
                MessageBox.Show("กรุณาเลือกลูกค้า");
                return;
            }

            Dialog.frmDialogSearchRequis frm = new Dialog.frmDialogSearchRequis(textBox12.Text.Trim(), Class.Function.GetTextId(textBox13.Text).ToString());
            frm.ShowDialog();

            tempLastPrice.Clear();

            if (frm.DialogResult == DialogResult.OK)
            {
                String sid = frm.GetShipperId();
                String sql = "select cast(saleappdetailid as varchar(20)) AS SaleDetailId, " +
                    "d.productid,p.productname, d.saleappdetailquantitypack,up.unitpackname,d.saleappdetailquantity,u.unitsalename," +
                        "d.saleappdetailweight,d.productapptype,h.sdateid from sale_app_detail d " +
                        "inner join sale_app_head h on h.saleappheadid = d.saleappheadid " +
                        "inner join product p on d.productid = p.productid " +
                        "inner join unitsale u on u.unitsaleid = p.unitsaleid " +
                        "inner join unitpack up on up.unitpackid = p.unitpackid where h.sid = " + sid;

                List<string> sidNew = new List<string>();
                List<string> DetailId = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("SaleDetailId")).ToList();
                List<string> ProductId = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("productid")).ToList();
                List<string> ProductName = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("productname")).ToList();
                List<string> QuantityPack = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<double>("saleappdetailquantitypack").ToString()).ToList();
                List<string> Quantity = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<double>("saleappdetailquantity").ToString()).ToList();
                List<string> UnitPackName = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("unitpackname")).ToList();
                List<string> UnitSaleName = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("unitsalename")).ToList();
                List<string> Weight = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<double>("saleappdetailweight").ToString()).ToList();
                List<string> type = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<int>("productapptype").ToString()).ToList();
                List<string> sdate = Class.DBConnString.clsDB.QueryDataTable(sql).Rows.OfType<DataRow>().Select(dr => dr.Field<string>("sdateid")).ToList();

                for (int i = 0; i < ProductId.Count; i++)
                {
                    sidNew.Add(sid);
                }

                if (sidNew.Intersect(sidOld).Count() > 0)
                {
                    MessageBox.Show("ใบโอนนี้ถูกเลือกแล้ว");
                    return;
                }
                else
                {
                    sidOld.Add(sid);
                    String Price = "";
                    for (int i = 0; i < ProductId.Count; i++)
                    {
                        String w = "";
                        String sqlw = "select * from sale_app_weight w inner join sale_app_head h on w.saleappheadid = h.saleappheadid where w.productid = '" + ProductId[i] + "' " +
                        "AND h.sid = '" + sid + "' ";

                        System.Data.SqlClient.SqlDataReader readerw = Class.DBConnString.clsDB.QueryDataReader(sqlw);
                        if (type[i] != "3")
                        {
                            while (readerw.Read())
                            {
                                w += readerw["SaleAppPackId"].ToString() + "#";
                                w += readerw["SaleAppPack"].ToString() + "#";
                                if (type[i] == "1")
                                {
                                    w += readerw["SaleAppWeight"].ToString() + "#";
                                }
                            }
                        }

                        object costTop = getLastPriceSale(ProductId[i]);
                        Price = (costTop == null) ? "0.00" : ((DataRow)costTop)["cost"].ToString();
                        Price = Convert.ToDouble(Price).ToString("#,##0.00");
                        if (lProidOld.Where(a => a.DetailId == DetailId[i]).FirstOrDefault() != null)
                        {
                            lProidOld.Where(a => a.DetailId == DetailId[i]).FirstOrDefault().price = Price;
                        }

                        lProidOld.Add(new ListId
                        {
                            DetailId =DetailId [i],
                            ProductId = ProductId[i],
                            ProductName = ProductName[i],
                            UnitPackName = UnitPackName[i],
                            UnitSaleName = UnitSaleName[i],
                            QuantityPack = QuantityPack[i],
                            Quantity = Quantity[i],
                            Weight = Weight[i],
                            type = type[i],
                            sdate = sdate[i],
                            price = Price,
                            distext = "0",
                            disper = "0.00",
                            dis = "0.00",
                            total = "0.00",
                            Detail = w
                        });
                        loadGridSale( DetailId [i], ProductId[i], ProductName[i], UnitPackName[i], UnitSaleName[i], "0.00",
                            Convert.ToDouble(QuantityPack[i]).ToString("#,##0.00"), Convert.ToDouble(Quantity[i]).ToString("#,##0.00"),
                            Convert.ToDouble(Weight[i]).ToString("#,##0.00"), Convert.ToInt16(type[i]).ToString(), w, sdate[i].ToString(),
                            "0", "0.00", "0.00", "0.00");
                    }
                    setCalulate();
                }
                Class.Function.SetDgvWeightFnc(dataGridView1.Rows[0].Cells[17].Value.ToString(), dataGridView2, dataGridView1.Rows[0].Cells[18].Value.ToString());
            }
        }