private void LoadCBHangSX() { tblhangsanxuatBL ctr = new tblhangsanxuatBL(); DataTable dt = new DataTable(); dt = ctr.GetAll(); cbHangSX.DataSource = dt; cbHangSX.DisplayMember = "ten"; cbHangSX.ValueMember = "id"; }
private void LoadCBTKHangSX() { flagload = true; tblhangsanxuatBL ctr = new tblhangsanxuatBL(); DataTable dt = new DataTable(); dt = ctr.GetAll(); cbTKHangSX.DataSource = dt; cbTKHangSX.DisplayMember = "ten"; cbTKHangSX.ValueMember = "id"; flagload = false; }
private void HienThiDS() { tblhangsanxuatBL _ctr = new tblhangsanxuatBL(); DataTable dt = new DataTable(); dt = _ctr.GetAll(); if (dt != null) { c1FlexGrid1.DataSource = dt; dt.Columns.Add("TT", typeof(Int32)); FormatGrid(); } }
private List <tblhangsanxuat> GetData() { tblhangsanxuatBL ctr = new tblhangsanxuatBL(); List <tblhangsanxuat> lst = new List <tblhangsanxuat>(); string loi = ""; for (int i = 1; i < c1FlexGrid1.Rows.Count; i++) { if (c1FlexGrid1[i, "TT"].ToString().Equals("0") == false) { try { loi = ""; tblhangsanxuat _obj = new tblhangsanxuat(); if (c1FlexGrid1[i, "ten"].ToString().Trim().Equals("") == true || c1FlexGrid1[i, "ten"] == null) { loi = "Tên hãng sản xuất không được để trắng."; c1FlexGrid1.SetUserData(i, "ten", loi); c1FlexGrid1.Rows[i].Style = cserror; } _obj.ten = c1FlexGrid1[i, "ten"].ToString(); if (c1FlexGrid1[i, "TT"].ToString().Equals("1") == true) { if (ctr.CheckExit("", _obj.ten) == true) { loi = "Tên hãng sản xuất đã có trong cơ sở dữ liệu."; c1FlexGrid1.SetUserData(i, "ten", loi); c1FlexGrid1.Rows[i].Style = cserror; } _obj.id = Guid.NewGuid().ToString(); c1FlexGrid1[i, "id"] = _obj.id.Trim(); } if (c1FlexGrid1[i, "TT"].ToString().Equals("2") == true) { _obj.id = c1FlexGrid1[i, "id"].ToString().Trim(); if (ctr.CheckExit(_obj.id, _obj.ten) == true) { loi = "Tên hãng sản xuất đã có trong cơ sở dữ liệu."; c1FlexGrid1.SetUserData(i, "ten", loi); c1FlexGrid1.Rows[i].Style = cserror; } } _obj.ghichu = c1FlexGrid1[i, "ghichu"].ToString(); lst.Add(_obj); } catch { } } } return(lst); }
private void Delete() { tblhangsanxuatBL _ctr = new tblhangsanxuatBL(); string loi = ""; string sten = ""; string iid = ""; int n = c1FlexGrid1.RowSel; if (n >= 1) { try { sten = c1FlexGrid1[c1FlexGrid1.RowSel, "ten"].ToString().Trim(); } catch { } try { iid = c1FlexGrid1[c1FlexGrid1.RowSel, "id"].ToString().Trim(); } catch { } DialogResult bien; bien = MessageBox.Show("Xác nhận xóa dữ liệu", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (bien == DialogResult.Yes) { loi = _ctr.Delete(iid); if (loi.Equals("") == true) { try { _ctrlog.Append(Data.use, "Xóa hãng sản xuất: " + sten.Trim()); } catch { } HienThiDS(); } else { MessageBox.Show(loi, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Dữ liệu hiện tại đang trắng.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } c1FlexGrid1.Focus(); }
private void Save() { string temploi = ""; string loi = ""; tblhangsanxuatBL _ctr = new tblhangsanxuatBL(); List <tblhangsanxuat> lst = new List <tblhangsanxuat>(); lst = GetData(); if (lst != null) { for (int i = 0; i < lst.Count; i++) { loi = ""; tblhangsanxuat _obj = new tblhangsanxuat(); try { _obj = _ctr.GetByID(lst[i].id); } catch { } if (_obj == null) { try { loi = c1FlexGrid1.GetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "ten").ToString().Trim(); } catch { } if (loi.Equals("") == true) { loi = _ctr.Insert(lst[i]); if (loi.Equals("") == false) { c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror; } else { _ctrlog.Append(Data.use, "Thêm mới hãng sản xuất: " + lst[i].ten.Trim()); } } else { c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror; } if (loi.Trim().Equals("") == false) { temploi = loi; } } else { try { loi = c1FlexGrid1.GetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "ten").ToString().Trim(); } catch { } if (loi.Equals("") == true) { loi = _ctr.Update(lst[i]); if (loi.Equals("") == false) { c1FlexGrid1.SetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "ten", loi); c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror; } else { _ctrlog.Append(Data.use, "Cập nhật hãng sản xuất: " + lst[i].ten.Trim()); } } else { c1FlexGrid1.SetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "ten", loi); c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror; } if (loi.Trim().Equals("") == false) { temploi = loi; } } } } if (temploi.Trim().Equals("") == true) { HienThiDS(); MessageBox.Show("Cập nhật dữ liệu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Cập nhật dữ liệu không thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }