private void btnSaveExit_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(cbb_Supplier.Text)) { XtraMessageBox.Show("Chưa chọn nhà cung cấp!"); cbb_Supplier.Focus(); return; } if (String.IsNullOrEmpty(cbb_Staff.Text)) { XtraMessageBox.Show("Chưa chọn nhân viên !"); cbb_Staff.Focus(); return; } Username = Program.UserName; if (IdEnter != null) { if (!_enter.IsEnterCoupon(IdEnter)) { int updateEnter = _enter.UpdateEnterCoupon(txt_ID.Text, cbb_Supplier.SelectedValue.ToString(), cbb_Staff.SelectedValue.ToString(), Username, dtP_DayCreate.Text, CheckReson(), txt_SumMoney.Text); if (updateEnter == 1) { for (int i = 0; i < dgV_DetailsCoupon.Rows.Count; i++) { string iditem = dgV_DetailsCoupon.Rows[i].Cells["ID_ITEM"].Value.ToString(); string num = dgV_DetailsCoupon.Rows[i].Cells["NUMBER"].Value.ToString(); string price = dgV_DetailsCoupon.Rows[i].Cells["PRICE_IN_2"].Value.ToString(); string money = dgV_DetailsCoupon.Rows[i].Cells["SUM_MONEY"].Value.ToString(); int UpdateDT = _item.UpdateDtEnterCoupon(txt_ID.Text, iditem, num, price, money); //if (UpdateDT != 1) //{ // XtraMessageBox.Show("Có lỗi trong lúc cập nhật !"); // return; //} } for (int i = 0; i < listIDDelete.Count; i++) { bool delete = _item.DeleteDetailEC(IdEnter, listIDDelete[i].ToString(), listNumberDelete[i].ToString()); } XtraMessageBox.Show("Cập nhật thành công"); this.Close(); return; } } } if (dgV_DetailsCoupon.Rows.Count != 0) { //Them phieu nhap int addEnter = _enter.InsertEnterCoupon(txt_ID.Text, cbb_Supplier.SelectedValue.ToString(), cbb_Staff.SelectedValue.ToString(), Username, dtP_DayCreate.Text, CheckReson(), txt_SumMoney.Text); if (addEnter == 2) { //Them chi tiet phieu nhap int check = 0; for (int i = 0; i < dgV_DetailsCoupon.Rows.Count; i++) { string iditem = dgV_DetailsCoupon.Rows[i].Cells["ID_ITEM"].Value.ToString(); string num = dgV_DetailsCoupon.Rows[i].Cells["NUMBER"].Value.ToString(); string price = dgV_DetailsCoupon.Rows[i].Cells["PRICE_IN_2"].Value.ToString(); string money = dgV_DetailsCoupon.Rows[i].Cells["SUM_MONEY"].Value.ToString(); int addDtItem = _item.InsertOneDtailItem(txt_ID.Text, iditem, num, price, money); if (addDtItem == 1) { check++; } else { XtraMessageBox.Show("Có lỗi trong lúc tạo phiếu nhập !"); return; } } if (check == dgV_DetailsCoupon.Rows.Count)//Đồng nghĩa lúc nào chi tiet phieu nhap da them thanh cong { //Cap nhat so luong kho int count = 0; for (int i = 0; i < dgV_DetailsCoupon.Rows.Count; i++) { string iditem = dgV_DetailsCoupon.Rows[i].Cells["ID_ITEM"].Value.ToString(); string num = dgV_DetailsCoupon.Rows[i].Cells["NUMBER"].Value.ToString(); int update = _item.UpdateNumberItemTerminal(iditem, num); if (update == 1) { count++; } else { break; } } if (count == dgV_DetailsCoupon.Rows.Count) { XtraMessageBox.Show("Tạo phiếu nhập và lưu thành công !"); this.Close(); } } } else if (addEnter == 1) { XtraMessageBox.Show("Đã tồn tại phiếu nhập này !"); //Thì cập nhật lại phiếu nhập return; } else { XtraMessageBox.Show("Thêm thất bại !"); return; } } else { XtraMessageBox.Show("Chưa có mặt hàng nào cần nhập ! Hãy thêm mặt hàng nhập"); return; } }