private void grvrootmuahang_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.Column.FieldName == "Mã Hàng") { var mh = grvrootmuahang.GetRowCellValue(e.RowHandle, e.Column); dt = muaHangBUS.LayThongTinHangHoaTheoMaHH(mh.ToString()); if (dt.Rows.Count > 0) { grvrootmuahang.SetRowCellValue(e.RowHandle, "Tên Hàng", dt.Rows[0]["TenHH"].ToString()); grvrootmuahang.SetRowCellValue(e.RowHandle, "Đơn Vị", dt.Rows[0]["TenDVT"].ToString()); grvrootmuahang.SetRowCellValue(e.RowHandle, "Đơn Giá", decimal.Parse(dt.Rows[0]["GiaMua"].ToString())); grvrootmuahang.SetRowCellValue(e.RowHandle, "Số Lượng", 1); grvrootmuahang.FocusedColumn = grvrootmuahang.Columns["Đơn Vị"]; } } if (e.Column == gridSoLuong) { soluong = int.Parse(grvrootmuahang.GetFocusedRowCellValue(gridSoLuong).ToString()); gia = float.Parse(grvrootmuahang.GetFocusedRowCellValue(gridDonGia).ToString()); thanhtien = soluong * gia; grvrootmuahang.SetFocusedRowCellValue(gridThanhTien, thanhtien); } if (e.Column == gridDonGia) { try { soluong = int.Parse(grvrootmuahang.GetFocusedRowCellValue(gridSoLuong).ToString()); gia = float.Parse(grvrootmuahang.GetFocusedRowCellValue(gridDonGia).ToString()); thanhtien = soluong * gia; grvrootmuahang.SetFocusedRowCellValue(gridThanhTien, thanhtien); }catch { } } TinhTien(); }
private void grvrootmuahang_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (e.Column.FieldName == "Mã Hàng") { mh = grvrootbanhang.GetRowCellValue(e.RowHandle, e.Column).ToString(); dt = muaHangBUS.LayThongTinHangHoaTheoMaHH(mh.ToString()); if (dt.Rows.Count > 0) { grvrootbanhang.SetRowCellValue(e.RowHandle, "Tên Hàng", dt.Rows[0]["TenHH"].ToString()); grvrootbanhang.SetRowCellValue(e.RowHandle, "Đơn Vị", dt.Rows[0]["TenDVT"].ToString()); grvrootbanhang.SetRowCellValue(e.RowHandle, "Số Lượng", 1); grvrootbanhang.SetRowCellValue(e.RowHandle, "Đơn Giá", 0); grvrootbanhang.FocusedColumn = grvrootbanhang.Columns["Đơn Vị"]; } try { grvrootbanhang.SetRowCellValue(e.RowHandle, "Loại Giá", 3); } catch { } } if (e.Column.FieldName == "Loại Giá") { dt = muaHangBUS.LayThongTinHangHoaTheoMaHH(mh.ToString()); if (dt.Rows.Count > 0) { var luachon = grvrootbanhang.GetRowCellValue(e.RowHandle, e.Column); if (int.Parse(luachon.ToString()) == 1) { grvrootbanhang.SetRowCellValue(e.RowHandle, "Đơn Giá", decimal.Parse(dt.Rows[0]["GiaMua"].ToString())); } if (int.Parse(luachon.ToString()) == 2) { grvrootbanhang.SetRowCellValue(e.RowHandle, "Đơn Giá", decimal.Parse(dt.Rows[0]["GiaBanSi"].ToString())); } if (int.Parse(luachon.ToString()) == 3) { grvrootbanhang.SetRowCellValue(e.RowHandle, "Đơn Giá", decimal.Parse(dt.Rows[0]["GiaBanLe"].ToString())); } if (int.Parse(luachon.ToString()) == 4) { grvrootbanhang.SetRowCellValue(e.RowHandle, "Đơn Giá", 0); } } grvrootbanhang.SetFocusedRowCellValue(gridColumn7, ThanhTien()); try { float ck = float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn8).ToString()); grvrootbanhang.SetFocusedRowCellValue(gridColumn9, Convert.ToDecimal((ck / 100) * ThanhTien())); } catch { grvrootbanhang.SetFocusedRowCellValue(gridColumn8, "0"); } try { grvrootbanhang.SetFocusedRowCellValue(gridColumn10, float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn7).ToString()) - float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn9).ToString())); } catch { } } if (e.Column.FieldName == "Số Lượng") { grvrootbanhang.SetFocusedRowCellValue(gridColumn7, ThanhTien()); try { float ck = float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn8).ToString()); grvrootbanhang.SetFocusedRowCellValue(gridColumn9, Convert.ToDecimal((ck / 100) * ThanhTien())); } catch { grvrootbanhang.SetFocusedRowCellValue(gridColumn8, "0"); } try { grvrootbanhang.SetFocusedRowCellValue(gridColumn10, float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn7).ToString()) - float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn9).ToString())); } catch { } } if (e.Column.FieldName == "Đơn Giá") { grvrootbanhang.SetFocusedRowCellValue(gridColumn7, ThanhTien()); try { float ck = float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn8).ToString()); grvrootbanhang.SetFocusedRowCellValue(gridColumn9, Convert.ToDecimal((ck / 100) * ThanhTien())); } catch { grvrootbanhang.SetFocusedRowCellValue(gridColumn8, "0"); } try { grvrootbanhang.SetFocusedRowCellValue(gridColumn10, float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn7).ToString()) - float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn9).ToString())); } catch { } } if (e.Column.FieldName == "CK") { try { float ck = float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn8).ToString()); grvrootbanhang.SetFocusedRowCellValue(gridColumn9, Convert.ToDecimal((ck / 100) * ThanhTien())); } catch { grvrootbanhang.SetFocusedRowCellValue(gridColumn8, "1"); } try { grvrootbanhang.SetFocusedRowCellValue(gridColumn10, float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn7).ToString()) - float.Parse(grvrootbanhang.GetFocusedRowCellValue(gridColumn9).ToString())); } catch { } } }