private void flxMatHang_CellButtonClick(object sender, RowColEventArgs e) { try { frmChonMatHang frm = new frmChonMatHang(); frm.type = 1; frm.ShowDialog(); string sidmathang = ""; try { sidmathang = frm.sreturn; if (sidmathang.Trim().Equals("") == true) { sidmathang = flxMatHang[flxMatHang.RowSel, "id_mathang"].ToString().Trim(); } } catch { } if (CheckMatHang(sidmathang, flxMatHang.RowSel) == true) { MessageBox.Show("Mặt hàng đã có trong đơn hàng này.\nVui lòng chọn một mặt hàng khác.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (flxMatHang.RowSel == flxMatHang.Rows.Count - 1) { flxMatHang.StartEditing(flxMatHang.Rows.Count - 1, 4); } else { flxMatHang.StartEditing(flxMatHang.RowSel, 4); } //flxMatHang.StartEditing(flxMatHang.Rows.Count - 1, 4); return; } tblmathang obj = new tblmathang(); tblmathangBL ctr = new tblmathangBL(); obj = ctr.GetByID(sidmathang); //flxMatHang[flxMatHang.RowSel, "id"] = ""; flxMatHang[flxMatHang.RowSel, "id_hoadon"] = ""; flxMatHang[flxMatHang.RowSel, "id_mathang"] = sidmathang; flxMatHang[flxMatHang.RowSel, "mathang"] = obj.ten.Trim(); //flxMatHang[flxMatHang.RowSel, "soluong"] = ""; flxMatHang[flxMatHang.RowSel, "donvi"] = obj.donvi.Trim(); try { if (txtCapDaiLy.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 1") == true) { flxMatHang[flxMatHang.RowSel, "giaban"] = obj.giadl1.ToString().Trim(); try { flxMatHang[flxMatHang.RowSel, "thanhtien"] = Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "soluong"]) * obj.giadl1; } catch { } } if (txtCapDaiLy.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 2") == true) { flxMatHang[flxMatHang.RowSel, "giaban"] = obj.giadl2.ToString().Trim(); try { flxMatHang[flxMatHang.RowSel, "thanhtien"] = Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "soluong"]) * obj.giadl2; } catch { } } if (txtCapDaiLy.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 3") == true) { flxMatHang[flxMatHang.RowSel, "giaban"] = obj.giadl3.ToString().Trim(); try { flxMatHang[flxMatHang.RowSel, "thanhtien"] = Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "soluong"]) * obj.giadl3; } catch { } } if (txtCapDaiLy.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 4") == true) { flxMatHang[flxMatHang.RowSel, "giaban"] = obj.giadl4.ToString().Trim(); try { flxMatHang[flxMatHang.RowSel, "thanhtien"] = Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "soluong"]) * obj.giadl4; } catch { } } if (txtCapDaiLy.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 5") == true) { flxMatHang[flxMatHang.RowSel, "giaban"] = obj.giadl5.ToString().Trim(); try { flxMatHang[flxMatHang.RowSel, "thanhtien"] = Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "soluong"]) * obj.giadl5; } catch { } } if (txtCapDaiLy.Text.ToUpper().Trim().Equals("KHÁCH LẺ") == true) { flxMatHang[flxMatHang.RowSel, "giaban"] = obj.giadl5.ToString().Trim(); try { flxMatHang[flxMatHang.RowSel, "thanhtien"] = Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "soluong"]) * obj.giadl5; } catch { } } if (Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "tt"]) == 0) { flxMatHang[flxMatHang.RowSel, flxMatHang.Cols.Count - 1] = 2; } flxMatHang_AfterEdit(sender, e); } catch { flxMatHang[flxMatHang.RowSel, "giaban"] = obj.giadl5.ToString().Trim(); try { flxMatHang[flxMatHang.RowSel, "thanhtien"] = Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "soluong"]) * obj.giadl5; } catch { } if (Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "tt"]) == 0) { flxMatHang[flxMatHang.RowSel, flxMatHang.Cols.Count - 1] = 2; } flxMatHang_AfterEdit(sender, e); } } catch { if (Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "tt"]) == 0) { flxMatHang[flxMatHang.RowSel, flxMatHang.Cols.Count - 1] = 2; } flxMatHang_AfterEdit(sender, e); } }
private void flxMatHang_CellButtonClick(object sender, RowColEventArgs e) { try { frmChonMatHang frm = new frmChonMatHang(); frm.type = 1; frm.ShowDialog(); string sidmathang = ""; try { sidmathang = frm.sreturn; if (sidmathang.Trim().Equals("") == true) { sidmathang = flxMatHang[flxMatHang.RowSel, "id_mathang"].ToString().Trim(); } } catch { } if (CheckMatHang(sidmathang, flxMatHang.RowSel) == true) { MessageBox.Show("Mặt hàng đã có trong đơn hàng này.\nVui lòng chọn một mặt hàng khác.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); flxMatHang.StartEditing(flxMatHang.Rows.Count - 1, 4); return; } tblmathang obj = new tblmathang(); tblmathangBL ctr = new tblmathangBL(); obj = ctr.GetByID(sidmathang); //flxMatHang[flxMatHang.RowSel, "id"] = ""; flxMatHang[flxMatHang.RowSel, "id_phieunhapkho"] = ""; flxMatHang[flxMatHang.RowSel, "id_mathang"] = sidmathang; flxMatHang[flxMatHang.RowSel, "mathang"] = obj.ten.Trim(); //flxMatHang[flxMatHang.RowSel, "soluong"] = ""; flxMatHang[flxMatHang.RowSel, "donvi"] = obj.donvi.Trim(); try { if (Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "tt"]) == 0) { flxMatHang[flxMatHang.RowSel, flxMatHang.Cols.Count - 1] = 2; } flxMatHang_AfterEdit(sender, e); } catch { flxMatHang[flxMatHang.RowSel, "gianhap"] = obj.gianhap.ToString().Trim(); try { flxMatHang[flxMatHang.RowSel, "thanhtien"] = Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "soluong"]) * obj.gianhap; } catch { } if (Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "tt"]) == 0) { flxMatHang[flxMatHang.RowSel, flxMatHang.Cols.Count - 1] = 2; } flxMatHang_AfterEdit(sender, e); } } catch { if (Convert.ToInt32(flxMatHang[flxMatHang.RowSel, "tt"]) == 0) { flxMatHang[flxMatHang.RowSel, flxMatHang.Cols.Count - 1] = 2; } flxMatHang_AfterEdit(sender, e); } }