void rep_XoaLich_Click(object sender, EventArgs e) { if (HelpMsgBox.ShowConfirmMessage("Bạn có thực sự muốn xóa không ?") == DialogResult.Yes) { int row = gridViewMaster.FocusedRowHandle; DOLichLamViec Lich = new DOLichLamViec(); Lich.ID = long.Parse(gridViewMaster.GetDataRow(row)["ID"].ToString()); Lich.NV_ID = long.Parse(gridViewMaster.GetDataRow(row)["NV_ID"].ToString()); dsDongXoa.Add(Key, Lich); #region Xu ly phan da xoa DALichLamViec.Install.DeleteRows(dsDongXoa); dsDongXoa = new Dictionary<int, DOLichLamViec>(); Key = 0; #endregion gridViewMaster.DeleteRow(row); ((DataTable)gridViewMaster.GridControl.DataSource).AcceptChanges(); //barButtonItemAdd.Enabled = true; } }
void them_ThemMoiLichTuan(DOLichLamViec LichDTO) { DataTable tb = DALichLamViec.Install.TimKiem(LichDTO.NGAY_DAU_TUAN); tb.Columns.Add(new DataColumn("C", Type.GetType("System.Double"))); gridControlMaster.DataSource = tb; bardateEdit_NgayDauTuan.EditValue = LichDTO.NGAY_DAU_TUAN; }
public bool Create_LichCoDinh(DataTable Input_dsNhanVien) { if (this.Exist_LichCoDinh() == true) { HelpMsgBox.ShowErrorMessage("Lịch cố định đã tồn tại, bạn không thể tạo"); return false; } else { try { FrameworkParams.wait = new WaitingMsg(); if (Input_dsNhanVien == null || Input_dsNhanVien.Rows.Count == 0) { HelpMsgBox.ShowErrorMessage("Chưa có nhân viên trong csdl"); return false; } foreach (DataRow dr in Input_dsNhanVien.Rows) { DOLichLamViec lcdDTO = new DOLichLamViec(); lcdDTO.ID = this.getGenID(); lcdDTO.GHI_CHU = ""; lcdDTO.NV_ID = int.Parse(dr["ID"].ToString()); lcdDTO.NGAY = new string[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; this.Insert_LichCoDinh(lcdDTO); } } finally { if (FrameworkParams.wait != null) FrameworkParams.wait.Finish(); } } return true; }
private void barButtonItemThemNhanVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { FrameworkParams.wait = new WaitingMsg(); #region - Xu ly thong bao int RecordNhanVien = DALichLamViec.Install.CountRecord("DM_NHAN_VIEN"); if ((RecordNhanVien > 0 && RecordNhanVien == gridViewMaster.RowCount) || RecordNhanVien==0) { return; } if (DALichLamViec.Install.CountRecord("LICH_LAM_VIEC") == 0) { HelpMsgBox.ShowNotificationMessage("Lịch làm việc không tồn tại"); return; } #endregion #region - Lấy danh sách nhân viên không có trên lưới String sql = null; DataTable DL = ((DataView)gridViewMaster.DataSource).Table; if (DL.Rows.Count == 0) { sql = "select * from DM_NHAN_VIEN where VISIBLE_BIT = 'Y'"; } else { String NV_ID = "("; for (int i = 0; i < DL.Rows.Count; i++) { if (DL.Rows[i].RowState != DataRowState.Deleted) { NV_ID += DL.Rows[i]["NV_ID"]; if (i < DL.Rows.Count - 1) NV_ID += ","; else NV_ID += ")"; } } if (NV_ID != "(") { sql = "select * from DM_NHAN_VIEN where VISIBLE_BIT = 'Y' and ID not in " + NV_ID; } } //Lay chuoi truyen qua ben form Them nhan vien //Sau khi chon xong form Them nhan vien se tra ve mot chuoi sql DatabaseFB db = HelpDB.getDatabase(); DbCommand cmd = db.GetSQLStringCommand(sql); DataSet NhanVienThem = new DataSet(); db.LoadDataSet(cmd, NhanVienThem, "AA"); #endregion #region - Luu xuong va hien thi foreach (DataRow item in NhanVienThem.Tables[0].Rows) { DOLichLamViec LichDTO = new DOLichLamViec(); LichDTO.ID = DALichLamViec.Install.getGenID(); LichDTO.NV_ID = long.Parse(item["ID"].ToString()); LichDTO.GHI_CHU = ""; LichDTO.NGAY = new string[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; if (LCoDinh) { DALichLamViec.Install.Insert_LichCoDinh(LichDTO); } else { LichDTO.NGAY_DAU_TUAN = HelpDateExt.DayFirstOfWeek((DateTime) bardateEdit_NgayDauTuan.EditValue); DALichLamViec.Install.Insert_LichTuan(LichDTO); } DataRow dr = DL.NewRow(); dr["ID"] = LichDTO.ID; LichDTO.NV_ID = long.Parse(item["ID"].ToString()); dr["NV_ID"] = LichDTO.NV_ID; for (int i = 2; i <= 8; i++) { dr["ST" + i.ToString()] = ""; dr["CT" + i.ToString()] = ""; } dr["GHI_CHU"] = ""; dr["NAME"] = DALichLamViec.Install.getTenNhanVien(LichDTO.NV_ID); if (!LCoDinh) dr["NGAY_DAU_TUAN"] = LichDTO.NGAY_DAU_TUAN; DL.Rows.Add(dr); barButtonItemAdd.Enabled = true; ReportCount(); } #endregion } finally { if (FrameworkParams.wait != null) FrameworkParams.wait.Finish(); } }
public bool UpdateRow(DOLichLamViec Lich) { string sql = "Update LICH_LAM_VIEC set "; int cn = 0; for (int i = 2; i <= 8; i++) { sql += "ST" + i.ToString() + "= '" + Lich.NGAY[cn] + "', "; cn++; sql += "CT" + i.ToString() + "= '" + Lich.NGAY[cn] + "', "; cn++; } sql += "GHI_CHU = '" + Lich.GHI_CHU + "'"; sql += " where ID = @ID"; DatabaseFB db = HelpDB.getDatabase(); DbCommand cmd = db.GetSQLStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int64, Lich.ID); if (db.ExecuteNonQuery(cmd) > 0) return true; return false; }
public bool UpdateDataSet(DataSet ds, bool b_LCD) { string er = string.Empty; ds.AcceptChanges(); try { foreach (DataRow dr in ds.Tables[0].Rows) { if (dr.RowState != DataRowState.Deleted) { dr.SetModified(); DOLichLamViec lichDTO = new DOLichLamViec(); lichDTO.ID = long.Parse(dr["ID"].ToString()); lichDTO.NV_ID = long.Parse(dr["NV_ID"].ToString()); int cn = 0; for (int i = 2; i <= 8; i++) { lichDTO.NGAY[cn] = dr["ST" + i.ToString()].ToString(); cn++; lichDTO.NGAY[cn] = dr["CT" + i.ToString()].ToString(); cn++; } lichDTO.GHI_CHU = dr["GHI_CHU"].ToString(); if ((b_LCD && DALichLamViec.Install.Exist_LCDNhanVien(long.Parse(dr["NV_ID"].ToString()))) || (!b_LCD && DALichLamViec.Install.Exist_LichTuanNhanVien((DateTime)dr["NGAY_DAU_TUAN"], long.Parse(dr["NV_ID"].ToString()))) ) { UpdateRow(lichDTO); } else { if (b_LCD) Insert_LichCoDinh(lichDTO); else { lichDTO.NGAY_DAU_TUAN = (DateTime)dr["NGAY_DAU_TUAN"]; Insert_LichTuan(lichDTO); } } } } } catch (Exception ex) { er = ex.Message; throw new Exception(ex.Message); } if (er == string.Empty) return true; return false; }
public bool Insert_LichTuan(DOLichLamViec dto) { if (Exist_LichTuanNhanVien(dto.NGAY_DAU_TUAN, dto.NV_ID)) return false; string sql = "Insert into LICH_LAM_VIEC(ID,NV_ID,NGAY_DAU_TUAN,ST2,CT2,ST3,CT3,ST4,CT4,ST5,CT5,ST6,CT6,ST7,CT7,ST8,CT8,GHI_CHU) values(@ID,@NV_ID,@NGAY_DAU_TUAN,"; for (int i = 0; i < dto.NGAY.Length; i++) { sql += "'" + dto.NGAY[i] + "',"; } sql += "'" + dto.GHI_CHU + "')"; db = HelpDB.getDatabase(); cmd = db.GetSQLStringCommand(sql); if (dto.ID.ToString() != "") db.AddInParameter(cmd, "@ID", System.Data.DbType.Int64, dto.ID); else db.AddInParameter(cmd, "@ID", System.Data.DbType.Int64, getGenID()); db.AddInParameter(cmd, "@NV_ID", System.Data.DbType.Int64, dto.NV_ID); db.AddInParameter(cmd, "@NGAY_DAU_TUAN", System.Data.DbType.DateTime, dto.NGAY_DAU_TUAN); if (db.ExecuteNonQuery(cmd) > 0) return true; return false; }
public bool Insert_LichCoDinh(DOLichLamViec dto) { if (this.Exist_LCDNhanVien(dto.NV_ID)) return false; string sql = "Insert into LICH_LAM_VIEC(ID,NV_ID,ST2,CT2,ST3,CT3,ST4,CT4,ST5,CT5,ST6,CT6,ST7,CT7,ST8,CT8,GHI_CHU) values(@ID,@NV_ID,"; for (int i = 0; i < dto.NGAY.Length; i++) { sql += "'" + dto.NGAY[i] + "',"; } sql += "@GHI_CHU)"; db = HelpDB.getDatabase(); cmd = db.GetSQLStringCommand(sql); db.AddInParameter(cmd, "@ID", System.Data.DbType.Int64, dto.ID); db.AddInParameter(cmd, "@NV_ID", System.Data.DbType.Int64, dto.NV_ID); db.AddInParameter(cmd, "@GHI_CHU", System.Data.DbType.String, dto.GHI_CHU); if (db.ExecuteNonQuery(cmd) > 0) return true; return false; }
private void btn_thuchien_Click(object sender, EventArgs e) { System.Windows.Forms.Application.DoEvents(); DataTable LichCoDinh = DALichLamViec.Install.getLichCoDinh(); if (LichCoDinh.Rows.Count == 0) { HelpMsgBox.ShowErrorMessage("Chưa có lịch làm việc cố định"); return; } if (dateEdit_NgayDauTuan.DateTime.DayOfWeek.ToString() != "Monday") { HelpMsgBox.ShowErrorMessage("Bạn phải chọn thứ hai đầu tuần"); return; } else { if (DALichLamViec.Install.Exist_LichTuan(HelpDateExt.DayFirstOfWeek(dateEdit_NgayDauTuan.DateTime))) { HelpMsgBox.ShowErrorMessage("Lịch làm việc này đã có trong danh sách lịch làm việc"); return; } try { for (int i = 0; i < LichCoDinh.Rows.Count; i++) { Lich = new DOLichLamViec(); Lich.ID = DALichLamViec.Install.getGenID(); Lich.NV_ID = long.Parse(LichCoDinh.Rows[i]["NV_ID"].ToString()); Lich.NGAY_DAU_TUAN = HelpDateExt.DayFirstOfWeek(dateEdit_NgayDauTuan.DateTime); Lich.GHI_CHU = ""; int cn = -1; for (int j = 2; j <= 8; j++) { Lich.NGAY[++cn] = LichCoDinh.Rows[i]["ST" + j.ToString()].ToString(); Lich.NGAY[++cn] = LichCoDinh.Rows[i]["CT" + j.ToString()].ToString(); } DALichLamViec.Install.Insert_LichTuan(Lich); if (i == LichCoDinh.Rows.Count - 1) { ThemMoiLichTuan(Lich); this.Close(); } } } catch (Exception ex) { HelpMsgBox.ShowErrorMessage(ex.Message); } } }