private void LoadTKCBPB() { try { phongbanBL _ctr = new phongbanBL(); DataTable dt = new DataTable(); dt = _ctr.GetAll(); cbTK_PhongBan.DataSource = dt; cbTK_PhongBan.DisplayMember = "tenphongban"; cbTK_PhongBan.ValueMember = "idphongban"; } catch { } }
private void HienThiDS() { phongbanBL _ctr = new phongbanBL(); DataTable dt = new DataTable(); dt = _ctr.GetAll(); if (dt != null) { c1FlexGrid1.DataSource = dt; dt.Columns.Add("TT", typeof(Int32)); FormatGrid(); } }
private List <phongban> GetData() { phongbanBL ctr = new phongbanBL(); List <phongban> lst = new List <phongban>(); string loi = ""; for (int i = 1; i < c1FlexGrid1.Rows.Count; i++) { if (c1FlexGrid1[i, "TT"].ToString().Equals("0") == false) { try { loi = ""; phongban _obj = new phongban(); if (c1FlexGrid1[i, "tenphongban"].ToString().Trim().Equals("") == true || c1FlexGrid1[i, "tenphongban"] == null) { loi = "Tên phòng ban không được để trắng."; c1FlexGrid1.SetUserData(i, "tenphongban", loi); c1FlexGrid1.Rows[i].Style = cserror; } _obj.tenphongban = c1FlexGrid1[i, "tenphongban"].ToString(); _obj.idphongban = c1FlexGrid1[i, 1].ToString().Trim(); if (c1FlexGrid1[i, "TT"].ToString().Equals("1") == true) { if (ctr.CheckExit("", _obj.tenphongban) == true) { loi = "Tên phòng ban đã có trong cơ sở dữ liệu."; c1FlexGrid1.SetUserData(i, "tenphongban", loi); c1FlexGrid1.Rows[i].Style = cserror; } } if (c1FlexGrid1[i, "TT"].ToString().Equals("2") == true) { if (ctr.CheckExit(_obj.idphongban, _obj.tenphongban) == true) { loi = "Tên phòng ban đã có trong cơ sở dữ liệu."; c1FlexGrid1.SetUserData(i, "tenphongban", loi); c1FlexGrid1.Rows[i].Style = cserror; } } _obj.mota = c1FlexGrid1[i, "mota"].ToString(); lst.Add(_obj); } catch { } } } return(lst); }
private void Delete() { phongbanBL _ctr = new phongbanBL(); string loi = ""; string sten = ""; string sid = ""; int n = c1FlexGrid1.RowSel; if (n >= 1) { try { sten = c1FlexGrid1[c1FlexGrid1.RowSel, "tenphongban"].ToString().Trim(); } catch { } try { sid = c1FlexGrid1[c1FlexGrid1.RowSel, "idphongban"].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(sid); if (loi.Equals("") == true) { HienThiDS(); //c1FlexGrid1.Select(c1FlexGrid1.FindRow(objID.ToString(), 1, c1FlexGrid1.Cols["OBJECTID"].Index, true, true, true), c1FlexGrid1.Cols["SoGPTD"].Index, true); } 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 = ""; phongbanBL _ctr = new phongbanBL(); List <phongban> lst = new List <phongban>(); lst = GetData(); if (lst != null) { for (int i = 0; i < lst.Count; i++) { loi = ""; phongban _obj = new phongban(); try { _obj = _ctr.GetByID(lst[i].idphongban); } catch { } if (_obj == null) { try { loi = c1FlexGrid1.GetUserData(c1FlexGrid1.FindRow(lst[i].idphongban, 1, c1FlexGrid1.Cols["idphongban"].Index, true, true, true), "tenphongban").ToString().Trim(); } catch { } if (loi.Equals("") == true) { loi = _ctr.Insert(lst[i]); if (loi.Equals("") == false) { c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].idphongban, 1, c1FlexGrid1.Cols["idphongban"].Index, true, true, true)].Style = cserror; } else { _ctrlog.Append(Data.use, "Thêm mới phòng ban: " + lst[i].tenphongban.Trim()); } } else { c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].idphongban, 1, c1FlexGrid1.Cols["idphongban"].Index, true, true, true)].Style = cserror; } if (loi.Trim().Equals("") == false) { temploi = loi; } } else { try { loi = c1FlexGrid1.GetUserData(c1FlexGrid1.FindRow(lst[i].idphongban, 1, c1FlexGrid1.Cols["idphongban"].Index, true, true, true), "tenphongban").ToString().Trim(); } catch { } if (loi.Equals("") == true) { loi = _ctr.Update(lst[i]); if (loi.Equals("") == false) { c1FlexGrid1.SetUserData(c1FlexGrid1.FindRow(lst[i].idphongban, 1, c1FlexGrid1.Cols["idphongban"].Index, true, true, true), "tenphongban", loi); c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].idphongban, 1, c1FlexGrid1.Cols["idphongban"].Index, true, true, true)].Style = cserror; } else { _ctrlog.Append(Data.use, "Cập nhật phòng ban: " + lst[i].tenphongban.Trim()); } } else { c1FlexGrid1.SetUserData(c1FlexGrid1.FindRow(lst[i].idphongban, 1, c1FlexGrid1.Cols["idphongban"].Index, true, true, true), "tenphongban", loi); c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].idphongban, 1, c1FlexGrid1.Cols["idphongban"].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); } }