private void gridView1_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { try { gridView1.GetFocusedValue(); var mahang = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colMaHang).ToString(); var db = new MyDBContextDataContext(); var lst = db.tbVatLieus.Single(s => s.MaHang == mahang); gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "DonViTinh", lst.DonViTinh); gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "QuyCach", lst.QuyCach); gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "TenHangHoa", lst.TenHangHoa); gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "MaAD", lst.MaAvery); //var mahang = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colMaHang).ToString(); var lo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colLo).ToString(); //var db = new MyDBContextDataContext(); var lst2 = db.LoadData_TonKhoNVL_Lot_View(tungay, denngay).ToList(); foreach (var item in lst2) { if (item.mahang == mahang && item.Lo == lo) { gridView1.SetRowCellValue(gridView1.FocusedRowHandle, colHanSuDung, item.HanSuDung); } } } catch (Exception) { //MessageBox.Show("Lỗi: " + ex.Message, "Lỗi"); //null } }
public void nhapsolot() { var db = new MyDBContextDataContext(); var a = db.LoadData_TonKhoNVL_Lot_View(tungay, denngay).ToList(); foreach (var item in a) { var tong = 0; var sl1 = 0; for (var i = 0; i < gridView1.RowCount; i++) { var dr = gridView1.GetDataRow(i); if (!string.IsNullOrEmpty(dr["Lo"].ToString())) { continue; } if (item.mahang != dr["MaHang"].ToString()) { continue; } if (string.IsNullOrEmpty(item.Lo)) { continue; } if (i == 0) { tong = Convert.ToInt32(dr["SoLuongXuat"]); } if (i > 0) { sl1 = Convert.ToInt32(dr["SoLuongXuat"]); } tong = sl1 + tong; if (item.toncuoiky >= tong) { dr["Lo"] = item.Lo; dr["HanSuDung"] = item.HanSuDung; //MessageBox.Show(tong + " " + item.mahang + " " + item.Lo); } else { tong = tong - sl1; //MessageBox.Show(tong + " " + item.mahang + " " + item.Lo); } } } }
private void checkEdit1_CheckedChanged(object sender, EventArgs e) { if (checkEdit1.Checked == true) { txttungay.DateTime = Convert.ToDateTime(GetFirstDayOfMonth(DateTime.Now).ToString("yyyy/MM/dd") + " 00:00:00"); txtdenngay.DateTime = Convert.ToDateTime(GetLastDayOfMonth(DateTime.Now).ToString("yyyy/MM/dd") + " 23:59:59"); var db = new MyDBContextDataContext(); var lst = (from s in db.LoadData_TonKhoNVL_Lot_View(txttungay.DateTime, txtdenngay.DateTime) select s).ToList(); procTonKhoNVL_ViewGridControl.DataSource = lst; Gridview1.Columns["HanSuDung"].Visible = true; Gridview1.Columns["Lo"].Visible = true; } else { frmKhoNVLTonKho_Load(sender, e); } }
private void btnTinh_Click(object sender, EventArgs e) { try { var db = new MyDBContextDataContext(); var khonvl = db.LoadData_TonKhoNVL_Lot_View(tungay, denngay).ToList(); foreach (var item in khonvl) { var tong = 0; var sl1 = 0; for (var i = 0; i < gridView1.RowCount - 1; i++) { var dr = gridView1.GetDataRow(i); if (!string.IsNullOrEmpty(dr["Lo"].ToString())) { continue; } if (item.mahang != dr["MaHang"].ToString() || item.Kho != KhoCongTytxt.Text) { continue; } if (string.IsNullOrEmpty(item.Lo)) { continue; } if (i == 0) { tong = Convert.ToInt32(dr["SoLuongXuat"]); } if (i > 0) { sl1 = Convert.ToInt32(dr["SoLuongXuat"]); } tong = sl1 + tong; if (item.toncuoiky >= tong) { dr["Lo"] = item.Lo; dr["HanSuDung"] = item.HanSuDung; //MessageBox.Show(tong + " " + item.mahang + " " + item.Lo); } else { tong = tong - sl1; //MessageBox.Show(tong + " " + item.mahang + " " + item.Lo); } } } } catch (Exception) { //Console.WriteLine(exception); //throw; } //try //{ // var db = new MyDBContextDataContext(); // var a = db.LoadData_TonKhoNVL_View(tungay, denngay).ToList(); // foreach (var item in a) // { // var tong = 0; // var sl1 = 0; // for (var i = 0; i < gridView1.RowCount - 1; i++) // { // var dr = gridView1.GetDataRow(i); // if (!string.IsNullOrEmpty(dr["Lo"].ToString())) continue; // if (item.mahang != dr["MaHang"].ToString() || item.Kho != KhoCongTytxt.Text) continue; // if (string.IsNullOrEmpty(item.Lo)) continue; // if (i == 0) tong = Convert.ToInt32(dr["SoLuongXuat"]); // if (i > 0) sl1 = Convert.ToInt32(dr["SoLuongXuat"]); // tong = sl1 + tong; // if (item.toncuoiky >= tong) // { // dr["Lo"] = item.Lo; // dr["HanSuDung"] = item.HanSuDung; // //MessageBox.Show(tong + " " + item.mahang + " " + item.Lo); // } // else // { // tong = tong - sl1; // //MessageBox.Show(tong + " " + item.mahang + " " + item.Lo); // } // } // } //} //catch (Exception) //{ // //Console.WriteLine(exception); // //throw; //} }