Ejemplo n.º 1
0
        private void dGV_Item_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (txt_Number.Text.Trim() == string.Empty)
            {
                XtraMessageBox.Show("Vui lòng tìm kiếm khách hàng sử dụng trước !");
                btn_SerchCus.Focus();
                return;
            }
            if (dGV_Item.CurrentRow != null && CheckChairOpen("btnChair" + lbl_NameChair.Text.Substring(lbl_NameChair.Text.Length - 3, 3)))
            {
                frmChooseStaff frm = new frmChooseStaff();
                frm.ShowDialog();
                if (String.IsNullOrEmpty(frm.NameStaff) || String.IsNullOrEmpty(frm.IdStaff))
                {
                    return;
                }
                else
                {
                    string idItem    = dGV_Item.CurrentRow.Cells["ID"].Value.ToString();
                    string product   = dGV_Item.CurrentRow.Cells["NAME_ITEM"].Value.ToString();
                    string unit      = dGV_Item.CurrentRow.Cells["NAME_UNIT"].Value.ToString();
                    string price     = dGV_Item.CurrentRow.Cells["PRICE_OUT"].Value.ToString();
                    string idStaff   = frm.IdStaff;
                    string nameStaff = frm.NameStaff;
                    string num       = cbbNumber.Text;
                    string saleoff   = "0";
                    string total     = (double.Parse(num) * double.Parse(price) - (double.Parse(num) * double.Parse(price)) * double.Parse(saleoff)).ToString();

                    for (int i = 0; i < dgv_DetailReceipt.Rows.Count; i++)
                    {
                        if (dgv_DetailReceipt.Rows[i].Cells["ID_ITEM"].Value.ToString().Equals(idItem))
                        {
                            float sl = float.Parse(dgv_DetailReceipt.Rows[i].Cells["NUMBER"].Value.ToString());
                            float dg = float.Parse(dgv_DetailReceipt.Rows[i].Cells["PRICEOUT"].Value.ToString());
                            dgv_DetailReceipt.Rows[i].Cells["NUMBER"].Value = (sl + 1).ToString();
                            dgv_DetailReceipt.Rows[i].Cells["TOTAL"].Value  = ((sl + 1) * dg).ToString();
                            //Cập nhật chi tiết hóa đơn
                            bool flagUpdate = _dtreceipt.UpdateDetailReceipt(txt_Number.Text, idStaff, idItem, saleoff, dgv_DetailReceipt.Rows[i].Cells["NUMBER"].Value.ToString(), price, dgv_DetailReceipt.Rows[i].Cells["TOTAL"].Value.ToString(), "1");
                            if (flagUpdate)
                            {
                                //cập nhật tổng tiền bên hóa đơn,
                                SumMoney();
                                bool flagUpdateReceiptMoney = _receipt.UpdateToTalReceipt(txt_Number.Text, txt_Total.Text);
                                if (flagUpdateReceiptMoney)
                                {
                                    //cập nhật số lượng kho
                                    return;
                                }
                                else
                                {
                                    XtraMessageBox.Show("Có lỗi !");
                                    return;
                                }
                            }
                            else
                            {
                                XtraMessageBox.Show("Có lỗi !");
                                return;
                            }
                        }
                    }

                    string[] row = new string[] { idItem, product, unit, num, price, saleoff, total, idStaff, nameStaff };
                    dgv_DetailReceipt.Rows.Add(row);
                    //Thêm 1 chi tiết hóa đơn mới
                    bool flagAdd = _dtreceipt.AddDetailReceipt(txt_Number.Text, idStaff, idItem, saleoff, num, price, total, "1");
                    if (flagAdd)
                    {
                        //cập nhật tổng tiền bên hóa đơn,
                        SumMoney();
                        bool flagUpdateReceiptMoney = _receipt.UpdateToTalReceipt(txt_Number.Text, txt_Total.Text);
                        if (flagUpdateReceiptMoney)
                        {
                            //cập nhật số lượng kho
                            XtraMessageBox.Show("Thêm dịch vụ thành công !", "Thông báo !");
                            return;
                        }
                        else
                        {
                            XtraMessageBox.Show("Có lỗi !");
                            return;
                        }
                    }
                    else
                    {
                        XtraMessageBox.Show("Có lỗi !");
                        return;
                    }
                }
            }
            else
            {
                XtraMessageBox.Show(lbl_NameChair.Text + "chưa được mở !", "Thông báo");
            }
        }