private Guid AddObj(ThietBi objThietBi, TinhTrang objTinhTrang, int SoLuong, String GhiChu) { try { CTThietBi obj = new CTThietBi(); obj.phong = objPhong; obj.thietbi = objThietBi; obj.tinhtrang = objTinhTrang; obj.soluong = SoLuong; obj.mota = GhiChu; obj.ngay = dateEdit1.EditValue == null ? DateTime.Now : dateEdit1.DateTime; if (obj.add() > 0 && DBInstance.commit() > 0) { text += "Thêm thiết bị " + objThietBi.ten + " vào phòng thành công!" + Environment.NewLine; return objPhong.ctthietbis.Where(c=>c.thietbi == objThietBi && c.tinhtrang == objTinhTrang).FirstOrDefault().id; } else text += "Thêm thiết bị " + objThietBi.ten + " vào phòng không thành công!" + Environment.NewLine; return Guid.Empty; } catch (Exception ex) { Debug.WriteLine(this.Name + "->AddObj: " + ex.Message); return Guid.Empty; } }
public frmChuyen(CTThietBi obj) { InitializeComponent(); init(); loadData(); setData(obj); }
private Guid AddObj(ThietBi objThietBi, TinhTrang objTinhTrang, int SoLuong, String GhiChu) { try { CTThietBi obj = new CTThietBi(); obj.phong = objPhong; obj.thietbi = objThietBi; obj.tinhtrang = objTinhTrang; obj.soluong = SoLuong; obj.mota = GhiChu; obj.ngay = dateEdit1.EditValue == null ? DateTime.Now : dateEdit1.DateTime; if (obj.add() > 0 && DBInstance.commit() > 0) { text += "Thêm thiết bị " + objThietBi.ten + " vào phòng thành công!" + Environment.NewLine; return(objPhong.ctthietbis.Where(c => c.thietbi == objThietBi && c.tinhtrang == objTinhTrang).FirstOrDefault().id); } else { text += "Thêm thiết bị " + objThietBi.ten + " vào phòng không thành công!" + Environment.NewLine; } return(Guid.Empty); } catch (Exception ex) { Debug.WriteLine(this.Name + "->AddObj: " + ex.Message); return(Guid.Empty); } }
private void gridViewCTThietBi_RowClick(object sender, RowClickEventArgs e) { if (e.RowHandle >= 0 && gridViewCTThietBi.GetFocusedRow() != null) { //objCTThietBi = CTThietBi.getById(Convert.ToInt32(gridViewCTThietBi.GetRowCellValue(e.RowHandle, colid))); objCTThietBi = (gridViewCTThietBi.GetFocusedRow() as ChiTietTBHienThi).ctthietbi; if (objCTThietBi != null) setThongTinThietBi(objCTThietBi); } }
public void setData(CTThietBi obj) { objCTThietBi = obj; lblMa.Text = obj.thietbi.subId; lblTen.Text = obj.thietbi.ten; lblLoai.Text = obj.thietbi.loaithietbi.ten; lblPhong.Text = obj.phong.ten; lblTinhTrang.Text = obj.tinhtrang.value; lblSoLuong.Text = obj.soluong.ToString(); lookUpTinhTrang.EditValue = obj.tinhtrang_id; txtSoLuong.Properties.MaxValue = obj.soluong; }
private void gridViewCTThietBi_DataSourceChanged(object sender, EventArgs e) { if (working) { enableEdit(false); } if (gridViewCTThietBi.FocusedRowHandle >= 0 && gridViewCTThietBi.GetFocusedRow() != null) { objCTThietBi = (gridViewCTThietBi.GetFocusedRow() as ChiTietTBHienThi).ctthietbi; if (objCTThietBi != null) setThongTinThietBi(objCTThietBi); } }
private void gridViewCTThietBi_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { if (working) { enableEdit(false); } if (e.FocusedRowHandle >= 0 && gridViewCTThietBi.GetFocusedRow() != null) { objCTThietBi = CTThietBi.getById(GUID.From(gridViewCTThietBi.GetRowCellValue(e.FocusedRowHandle, colid))); objCTThietBi = (gridViewCTThietBi.GetFocusedRow() as ChiTietTBHienThi).ctthietbi; if (objCTThietBi != null) setThongTinThietBi(objCTThietBi); } }
private void setThongTinThietBi(CTThietBi _obj) { try { txtMa.Text = _obj.thietbi.subId; txtTen.Text = _obj.thietbi.ten; txtMoTa.Text = _obj.thietbi.mota; lblTenPhong.Text = _obj.phong.ten; dateMua.EditValue = _obj.thietbi.loaithietbi.loaichung ? null : _obj.thietbi.ngaymua; dateLap.EditValue = _obj.ngay; _ucTreeLoaiTB.setLoai(_obj.thietbi.loaithietbi); listHinh = _obj.thietbi.hinhanhs.ToList(); gridControlLog.DataSource = _obj.thietbi.logthietbis.Where(c => c.phong_id == _obj.phong.id && c.soluong > 0).OrderByDescending(c => c.date_create).ToList(); reloadImage(); } catch (Exception ex) { Debug.WriteLine(this.Name + "->setThongTinThietBi:" + ex.Message); } }
public static bool ImportThietBiRieng(String fileName, String sheet) { try { int line = 0; System.Data.DataTable dt = new System.Data.DataTable(); const int STT = 0; const int MATB = 1; const int TENTB = 2; const int MOTA = 3; const int LOAITB = 4; const int PHONG = 5; const int TINHTRANG = 6; const int NGAYTAO = 7; const int NGAYMUA = 8; const int NGAYLAP = 9; const int HINHANH = 10; const int PASS = 11; dt = OpenFile(fileName, sheet); if (dt != null) { int lines = dt.Rows.Count; foreach (System.Data.DataRow row in dt.Rows) { line++; DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormCaption("Import TB theo CT... " + String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.0}", (line * 1.0 / lines) * 100) + "%"); if (!row[PASS].Equals("Pass")) { bool ok = false; if (row[TENTB] != DBNull.Value && row[LOAITB] != DBNull.Value && row[PHONG] != DBNull.Value && row[TINHTRANG] != DBNull.Value) { LoaiThietBi objLoai = LoaiThietBi.getAll().FirstOrDefault(c => c.ten.ToUpper() == row[LOAITB].ToString().Trim().ToUpper()); if (objLoai != null) { try { TinhTrang objTinhTrang = new TinhTrang(); Phong objPhong = Phong.getAll().FirstOrDefault(c => c.ten.ToUpper() == row[PHONG].ToString().Trim().ToUpper()); if (objPhong != null) { objTinhTrang = TinhTrang.getAll().FirstOrDefault(c => c.value.ToUpper() == row[TINHTRANG].ToString().Trim().ToUpper()); if (objTinhTrang != null) { ok = true; } else { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có tình trạng)"); } } else { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có phòng)"); } if (ok) { ThietBi objThietBi = new ThietBi(); objThietBi.subId = row[MATB] != DBNull.Value ? row[MATB].ToString().Trim() : null; objThietBi.ten = row[TENTB].ToString().Trim(); objThietBi.loaithietbi = objLoai; objThietBi.mota = row[MOTA].ToString().Trim(); objThietBi.date_create = row[NGAYTAO] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAYTAO]) : DateTime.Now; objThietBi.ngaymua = row[NGAYMUA] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAYMUA]) : DateTime.Now; if (row[HINHANH] != DBNull.Value) { String[] file_names = row[HINHANH].ToString().Trim().Split(','); objThietBi.hinhanhs = AddImage(fileName, file_names); } if (objThietBi.add() > 0 && DBInstance.commit() > 0) { CTThietBi obj = new CTThietBi(); obj.thietbi = objThietBi; obj.phong = objPhong; obj.tinhtrang = objTinhTrang; obj.soluong = 1; obj.mota = "Import"; obj.ngay = row[NGAYLAP] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAYLAP]) : DateTime.Now; if (obj.add() > 0 && DBInstance.commit() > 0) { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass"); } else { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error"); } } else { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Lỗi khi thêm thiết bị)"); } } } catch (Exception ex) { Debug.WriteLine("ExcelDataBaseHelper->ImportThietBiChung: " + ex.Message); WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error"); } } else { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có loại thiết bị)"); } } else { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không đủ thông tin)"); } } } } return true; } catch (Exception ex) { Debug.WriteLine("ExcelDataBaseHelper->ImportThietBiChung: " + ex.Message); return false; } }
/// <summary> /// /// </summary> /// <param name="list_coso"></param> /// <param name="list_ltb"></param> /// <param name="list_tinhtrang"></param> /// <param name="date_from"></param> /// <param name="date_to"></param> /// <param name="row_per_page">Default: -1 (get ALL)</param> /// <param name="page_index">Default: 1 (valid from 1->n)</param> /// <returns></returns> public static List <TKSLThietBiFilter> getAll(List <Guid> list_coso = null, List <Guid> list_ltb = null, List <Guid> list_tinhtrang = null, DateTime?date_from = null, DateTime?date_to = null, int row_per_page = -1, int page_index = 1, Boolean orderby_id_desc = true) { IQueryable <CTThietBi> query = CTThietBi.getQuery(); //DATETIME if (date_from != null) { query = query.Where(x => x.ngay >= date_from); } if (date_to != null) { //"date_to" have to be the last second of the day, 1 day additional date_to = date_to.Value.AddDays(1); query = query.Where(x => x.ngay <= date_to); } //LTB if (list_ltb != null && list_ltb.Count > 0) { query = query.Where(x => x.thietbi.loaithietbi == null || list_ltb.Contains(x.thietbi.loaithietbi.id)); } //TINHTRANG if (list_tinhtrang != null && list_tinhtrang.Count > 0) { query = query.Where(x => list_tinhtrang.Contains(x.tinhtrang.id)); } //COSO if (list_coso != null && list_coso.Count > 0) { query = query.Where(x => x.phong.vitri.coso == null || list_coso.Contains(x.phong.vitri.coso.id)); } //CTTB phai co SL lon hon 0 query = query.Where(x => x.soluong > 0); //ORDER BY ID if (orderby_id_desc) { query = query.OrderByDescending(x => x.id); } else { query = query.OrderBy(x => x.id); } //PAGINATION if (row_per_page > -1) { page_index = page_index-- >= 0 ? page_index : 0; query = query.Skip(row_per_page * page_index).Take(row_per_page); } //FINAL SELECT List <TKSLThietBiFilter> re = query.Select(x => new TKSLThietBiFilter { cttb = x, idcttb = x.id, soluong = x.soluong, tencoso = x.phong.vitri.coso == null ? "" : x.phong.vitri.coso.ten, tenday = x.phong.vitri.day == null ? "" : x.phong.vitri.day.ten, tentang = x.phong.vitri.tang == null ? "" : x.phong.vitri.tang.ten, tenltb = x.thietbi.loaithietbi.ten, tentinhtrang = x.tinhtrang.value, tenphong = x.phong.ten } ).ToList(); return(re); }