Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dl = MessageBox.Show("Do you Want to Save Sell Products", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dl == DialogResult.Yes)
                {
                    if (rdb_SaleRoom.Checked == true)
                    {
                        cntrl_sell.save_sellProduct(txtBillno.Text.Trim(), txtDate.Text.Trim(), cbRoom.SelectedValue.ToString().Trim(), LoginController.userlogined.Rows[0]["EmpID"].ToString());
                        for (int list_pro = 0; list_pro < dgvProductsList.Rows.Count; list_pro++)
                        {
                            string id    = dgvProductsList.Rows[list_pro].Cells[1].Value.ToString().Trim();
                            double price = double.Parse(dgvProductsList.Rows[list_pro].Cells[4].Value.ToString().Trim());
                            int    Pqty  = int.Parse(dgvProductsList.Rows[list_pro].Cells[5].Value.ToString().Trim());
                            double Total = double.Parse(dgvProductsList.Rows[list_pro].Cells[7].Value.ToString().Trim());
                            cntrl_sell.save_sellProduct_Detail(id.ToString().Trim(), price.ToString().Trim(), Pqty.ToString().Trim(), Total.ToString().Trim(), txtBillno.Text.Trim());
                        }
                        for (int p = 0; p < dgvProductsList.Rows.Count; p++)
                        {
                            string id    = dgvProductsList.Rows[p].Cells[1].Value.ToString().Trim();
                            int    P_qty = int.Parse(dgvProductsList.Rows[p].Cells[5].Value.ToString().Trim());
                            int    Sum   = 0;
                            cn.da = new System.Data.SqlClient.SqlDataAdapter("Select Qty From Product Where ProductID='" + id + "'", cn.cn);
                            cn.ds = new DataSet();
                            cn.da.Fill(cn.ds);
                            Qty = Convert.ToInt32(cn.ds.Tables[0].Rows[0]["Qty"].ToString());
                            Sum = Qty - P_qty;
                            cntrl_sell.Update_instock(Sum.ToString().Trim(), id.Trim());
                        }
                        ms.INSERT_Or_SAVE_Successfull();
                        DialogResult getb = MessageBox.Show("ທ່ານຕ້ອງການພີມໃບບິນຂາຍບໍ", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (getb == DialogResult.Yes)
                        {
                            SengkeoHotel.contrl_Sell.billno.frmSellBill f = new billno.frmSellBill(txtBillno.Text);
                            f.ShowDialog();

                            txtBillno.Text = cntrl_sell.SellBill().ToString();
                            dgvProductsList.Rows.Clear();
                            dgvProStock.DataSource = new DataTable();
                            cbProductType.Text     = "";
                            cbRoom.Text            = "";
                            rdbSaleOther.Checked   = false;
                            rdb_SaleRoom.Checked   = false;
                            rdb_SaleRoom.Enabled   = true;
                            rdbSaleOther.Enabled   = true;
                        }
                        else
                        {
                            txtBillno.Text = cntrl_sell.SellBill().ToString();
                            dgvProductsList.Rows.Clear();
                            dgvProStock.DataSource = new DataTable();
                            cbProductType.Text     = "";
                            cbRoom.Text            = "";
                            rdbSaleOther.Checked   = false;
                            rdb_SaleRoom.Checked   = false;
                            rdb_SaleRoom.Enabled   = true;
                            rdbSaleOther.Enabled   = true;
                            return;
                        }
                    }
                    if (rdbSaleOther.Checked == true)
                    {
                        cntrl_sell.save_SellProductNoRoom(txtBillno.Text.Trim(), txtDate.Text.Trim(), LoginController.userlogined.Rows[0]["EmpID"].ToString());
                        for (int list_pro = 0; list_pro < dgvProductsList.Rows.Count; list_pro++)
                        {
                            string id    = dgvProductsList.Rows[list_pro].Cells[1].Value.ToString().Trim();
                            double price = double.Parse(dgvProductsList.Rows[list_pro].Cells[4].Value.ToString().Trim());
                            int    Pqty  = int.Parse(dgvProductsList.Rows[list_pro].Cells[5].Value.ToString().Trim());
                            double Total = double.Parse(dgvProductsList.Rows[list_pro].Cells[7].Value.ToString().Trim());
                            cntrl_sell.save_sellProduct_Detail(id.ToString().Trim(), price.ToString().Trim(), Pqty.ToString().Trim(), Total.ToString().Trim(), txtBillno.Text.Trim());
                        }
                        for (int p = 0; p < dgvProductsList.Rows.Count; p++)
                        {
                            string id    = dgvProductsList.Rows[p].Cells[1].Value.ToString().Trim();
                            int    P_qty = int.Parse(dgvProductsList.Rows[p].Cells[5].Value.ToString().Trim());
                            int    Sum   = 0;
                            cn.da = new System.Data.SqlClient.SqlDataAdapter("Select Qty From Product Where ProductID='" + id + "'", cn.cn);
                            cn.ds = new DataSet();
                            cn.da.Fill(cn.ds);
                            Qty = Convert.ToInt32(cn.ds.Tables[0].Rows[0]["Qty"].ToString());
                            Sum = Qty - P_qty;
                            cntrl_sell.Update_instock(Sum.ToString().Trim(), id.Trim());
                        }
                        ms.INSERT_Or_SAVE_Successfull();
                        DialogResult getb = MessageBox.Show("ທ່ານຕ້ອງການພີມໃບບິນຂາຍບໍ", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (getb == DialogResult.Yes)
                        {
                            SengkeoHotel.contrl_Sell.billno.frmSellBill f = new billno.frmSellBill(txtBillno.Text);
                            f.ShowDialog();

                            txtBillno.Text = cntrl_sell.SellBill().ToString();
                            dgvProductsList.Rows.Clear();
                            dgvProStock.DataSource = new DataTable();
                            cbProductType.Text     = "";
                            cbRoom.Text            = "";
                            rdbSaleOther.Checked   = false;
                            rdb_SaleRoom.Checked   = false;
                            rdb_SaleRoom.Enabled   = true;
                            rdbSaleOther.Enabled   = true;
                        }
                        else
                        {
                            txtBillno.Text = cntrl_sell.SellBill().ToString();
                            dgvProductsList.Rows.Clear();
                            dgvProStock.DataSource = new DataTable();
                            cbProductType.Text     = "";
                            cbRoom.Text            = "";
                            rdbSaleOther.Checked   = false;
                            rdb_SaleRoom.Checked   = false;
                            rdb_SaleRoom.Enabled   = true;
                            rdbSaleOther.Enabled   = true;
                            return;
                        }
                    }
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }