private void btnLuu_Click(object sender, EventArgs e) { ThietBi tb = new ThietBi(); tb.Id = Convert.ToInt32(txtSTT.Text.ToString().Trim()); tb.MaTB = txtMa.Text.ToString().Trim(); tb.MaNhom = txtMa.Text.ToString().Trim(); tb.TenTB = txtTen.Text.ToString().Trim(); tb.NoiSX = txtNoiSX.Text.ToString().Trim(); tb.DVT = txtDVT.Text.ToString().Trim(); tb.GhiChu = txtGhiChu.Text.ToString().Trim(); if (otp == 1) { ThietBiTienNghiBUS.Instance.NewThietBiTienNghi(tb); ThietBiTienNghiBUS.Instance.Xem(gcThietBi); MessageBox.Show("Thêm thành công!"); otp = 0; } else { ThietBiTienNghiBUS.Instance.EditThietBiTienNghi(tb); ThietBiTienNghiBUS.Instance.Xem(gcThietBi); MessageBox.Show("Sửa thành công!"); } enableEditing(false); }
private void cbMaTB_SelectedIndexChanged(object sender, EventArgs e) { string mathietbi = cbMaTB.SelectedItem.ToString(); ThietBi tb = tbbus.ThietBiTheoMa(mathietbi); txtTenTB.Text = tb.Tenthietbi + ""; }
private void btnDeleteTB_Click(object sender, EventArgs e) { idx = 3; for (int i = 0; i < lvThietBi.Items.Count; i++) { if (lvThietBi.Items[i].Selected) { if (lvThietBi.SelectedIndices.Count == 0) { return; } ThietBi tb = new ThietBi(); ListViewItem liv = lvThietBi.SelectedItems[0]; tb.MaTB = liv.SubItems[0].Text; tb.TenTB = liv.SubItems[1].Text; tb.TinhTrang = liv.SubItems[2].Text; string[] date = liv.SubItems[3].Text.Split('-'); DateTime dt = new DateTime(int.Parse(date[2]), int.Parse(date[1]), int.Parse(date[0])); tb.HanBH = dt; tb.solanBH = Convert.ToInt32(liv.SubItems[3].Text); tb.MaPM = liv.SubItems[4].Text; lstXoa.Add(tb); lvThietBi.Items[i].Remove(); i--; } } }
public static List <ThietBi> ShowThietBi() { OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "LoadThietBi"; cmd.Connection = conn; SqlDataReader reader = cmd.ExecuteReader(); List <ThietBi> dsTB = new List <ThietBi>(); while (reader.Read()) // điều kiện đọc { string matb = reader.GetString(0); string tentb = reader.GetString(1); string tinhtrang = reader.GetString(2); DateTime ngaybh = reader.GetDateTime(3); int solanbh = reader.GetInt32(4); string mapm = reader.GetString(5); ThietBi tb = new ThietBi(matb, tentb, tinhtrang, ngaybh, solanbh, mapm); dsTB.Add(tb); } reader.Close(); return(dsTB); }
// GET: PhieuGiaoNhan/Details/5 public ActionResult Details(int?id) { if (id == null) { id = 0; } PhieuGiaoNhan phieuGiaoNhan = db.PhieuGiaoNhan.Find(id); List <List <string> > chiTietLoai = new List <List <string> >(); List <ChiTietPhieuGiaoNhan> listChiTietPhieuGiaoNhan = Model.Database.SelectChiTietPhieuGiaoNhan(id ?? default(int)); foreach (ChiTietPhieuGiaoNhan ct in listChiTietPhieuGiaoNhan) { ThietBi tb = Model.Database.SelectThietBiByMa(ct.MaThietBi); Loai loai = (from l in db.Loai where l.MaLoai == tb.MaLoai select l).FirstOrDefault(); TinhTrang tt = (from t in db.TinhTrang where t.MaTinhTrang == ct.TinhTrang select t).FirstOrDefault(); chiTietLoai.Add((new string[] { tb.MaThietBi.ToString(), loai.TenLoai, loai.DonGia.ToString(), loai.ThongSoKyThuat, loai.NamSanXuat, tt.TenTinhTrang }).ToList()); } ViewBag.ChiTietLoai = chiTietLoai; if (phieuGiaoNhan == null) { return(HttpNotFound()); } return(View(phieuGiaoNhan)); }
public ActionResult ThemSanPham(ThietBi m) { if (m?.TenThietBi == null || m.TenThietBi.Trim().Length == 0) { ModelState.AddModelError("TenThietBi", "Tên thiết bị bị bỏ trống."); } if (m == null || !ModelState.IsValid) { ViewBag.DMTB = db.DanhMucThietBis.Select(o => new SelectListItem { Value = o.MaDMTB, Text = o.TenDMTB }).ToList(); return(View(m)); } try { m.MaThietBi = Guid.NewGuid().ToString(); m.TenThietBi = m.TenThietBi.Trim(); db.ThietBis.Add(m); db.SaveChanges(); TempData["Message"] = $"Thêm thành công {m.MaThietBi}"; return(RedirectToAction("SanPham")); } catch (Exception ex) { TempData["Message"] = (ex.InnerException ?? ex).Message; return(RedirectToAction("SanPham")); } }
public static List <ThietBi> SearchThietBi(string key, string x) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM dbo.ThietBi WHERE " + key + " LIKE N'%" + x + "%'"; //cmd.CommandText = "TimKiemNV"; cmd.Connection = conn; OpenConnection(); //cmd.Parameters.Add("@MaNV", SqlDbType.NVarChar).Value = nv.MaNV; SqlDataReader reader = cmd.ExecuteReader(); List <ThietBi> dsTB = new List <ThietBi>(); while (reader.Read()) // điều kiện đọc { string matb = reader.GetString(0); string tentb = reader.GetString(1); string tinhtrang = reader.GetString(2); DateTime ngaybh = reader.GetDateTime(3); int solanbh = reader.GetInt32(4); string mapm = reader.GetString(5); ThietBi tb = new ThietBi(matb, tentb, tinhtrang, ngaybh, solanbh, mapm); dsTB.Add(tb); } reader.Close(); return(dsTB); }
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 void NewThietBiTienNghi(ThietBi cus) { var list = this.ThietBi.ToList(); this.ThietBi.Add(cus); this.SaveChanges(); }
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 void DelThietBiTienNghi(int id) { ThietBi kh = this.ThietBi.FirstOrDefault(c => c.Id == id); this.ThietBi.Remove(kh); this.SaveChanges(); }
public async Task <IActionResult> DeleteConfirm(int id) { string webRootPath = _hostingEnvironment.WebRootPath; ThietBi thietBi = await _unitOfWork.thietBiRepository.GetByIdAsync(id); if (thietBi == null) { return(NotFound()); } else { string upload = Path.Combine(webRootPath, SD.ImageFolder); var extenstion = Path.GetExtension(thietBi.HinhAnh); if (System.IO.File.Exists(Path.Combine(upload, thietBi.Id + extenstion))) { System.IO.File.Delete(Path.Combine(upload, thietBi.Id + extenstion)); } _unitOfWork.thietBiRepository.Delete(thietBi); await _unitOfWork.Complete(); return(RedirectToAction(nameof(Index))); } }
private void barButtonItem15_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { ThietBi tb = new ThietBi(); tb.MdiParent = this; tb.Show(); }
public bool checkworking() { try { if (!txtTen.Properties.ReadOnly) { ThietBi obj = objCTThietBi.thietbi; return obj.subId != txtMa.Text || obj.ten != txtTen.Text || obj.mota != txtMoTa.Text || obj.loaithietbi != _ucTreeLoaiTB.getLoaiThietBi() || obj.ngaymua != dateMua.DateTime || objCTThietBi.ngay != dateLap.DateTime || obj.hinhanhs.Except(listHinh).Count() > 0 || listHinh.Except(obj.hinhanhs).Count() > 0; } else { return false; } } catch { return true; } }
//Sửa thiết bị public static int EditThietBi(ThietBi tb) { int result = 0; SqlConnection conn = GetConnect.GetDBConnection(); conn.Open(); String sql = "UPDATE ThietBi \n" + "SET ten='" + tb.Tentb + "',gia=" + tb.Dongia + ",soluong=" + tb.SL + ",loai='" + tb.Loaitb + "'\n" + "WHERE id='" + tb.Matb + "'"; Console.WriteLine(sql); try { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; result = cmd.ExecuteNonQuery(); return(result); } catch (Exception e) { Console.WriteLine("Error: " + e); Console.WriteLine(e.StackTrace); return(result); } finally { conn.Close(); conn.Dispose(); } }
private void editObj() { try { ThietBi obj = objCTThietBi.thietbi; obj.subId = txtMa.Text; obj.ten = txtTen.Text; obj.mota = txtMoTa.Text; obj.loaithietbi = _ucTreeLoaiTB.getLoaiThietBi(); obj.ngaymua = dateMua.EditValue != null ? dateMua.DateTime : obj.ngaymua; obj.hinhanhs = listHinh; if (obj.update() > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Sửa thiết bị thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); reLoadCTThietBisOnlyAndFocused(objCTThietBi.id); } else { XtraMessageBox.Show("Không thể sửa thiết bị!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Debug.WriteLine(this.Name + "=>editObj:" + ex.Message); } }
private void Xoa() { try { if (vtIndex != -1) //khi click lên tiêu đề header của datagrid thì bỏ qua { if (MSG.BanCoChacChanMuonXoaKhong() == System.Windows.Forms.DialogResult.Yes) { ThietBi temp = Utils.DataGridViewRow_to_ThietBi(DataGridView.Rows[vtIndex]); int kq = ThietBiBiz.DeleteThietBi(temp); //if (kq > 0) MSG.XoaThanhCong(); //else MSG.XoaThatBai(); if (kq <= 0) { MSG.XoaThatBai(); } HienThi(); } } } catch (Exception ex) { MSG.Error(ex); } }
private void loadID() { ThietBi lastDV = db.ThietBis.OrderByDescending(x => x.ID_PC).FirstOrDefault(); string lastID = lastDV != null ? lastDV.ID_PC : ""; string nextID = IdGenerate.genId(lastID, "PC"); txtMaPC.Text = nextID; }
public static ThietBi DataGridViewRow_to_ThietBi(System.Windows.Forms.DataGridViewRow Input) { ThietBi kq = new ThietBi(); kq.MaThietBi = Input.Cells["MaThietBi"].Value.ToString(); kq.TenThietBi = Input.Cells["TenThietBi"].Value.ToString(); return(kq); }
private void dgvPC_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { currentTB = (dgvPC.DataSource as List <ThietBi>).Skip(e.RowIndex).FirstOrDefault(); bindToTextbox(); btnThem.Hide(); btnLuu.Show(); btnLuu.Enabled = false; unlockControl(); }
public int addNewDevice(ThietBi thietBi, bool isUpdate) { DataBaseManager.initializeInstance(); DataBaseManager dbmg = DataBaseManager.getInstance(); SqlConnection con = dbmg.openDatabase(); string insertNewCmd = "INSERT THIETBI (Id, Ten, NgayBatDau, NgayKetThuc, ViTri, BaoHanh, LOG, TinhTrang, MaNhom, TangSuat, Model, Seri, Hang, NgayThucHienCuoi) " + " VALUES (@Id,@Ten,@NgayBatDau,@NgayKetThuc,@ViTri,@BaoHanh,@LOG,@TinhTrang,@MaNhom, @TangSuat, @Model, @Seri, @Hang, @NgayThucHienCuoi)"; string updateCmd = "UPDATE THIETBI SET Id = @Id, Ten = @Ten, NgayBatDau = @NgayBatDau," + " NgayKetThuc = @NgayKetThuc, ViTri = @ViTri, BaoHanh = @BaoHanh, LOG = @LOG, TinhTrang = @TinhTrang," + " MaNhom = @MaNhom, TangSuat = @TangSuat, Model = @Model, Seri = @Seri, Hang = @Hang,NgayThucHienCuoi = @NgayThucHienCuoi" + " WHERE Id = @Id"; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; if (!isUpdate) { cmd.CommandText = insertNewCmd; } else { cmd.CommandText = updateCmd; } cmd.Parameters.AddWithValue("@Id", thietBi.deviceID); cmd.Parameters.AddWithValue("@Ten", thietBi.deviceName); cmd.Parameters.AddWithValue("@NgayBatDau", thietBi.startDate); cmd.Parameters.AddWithValue("@NgayKetThuc", thietBi.endDate); cmd.Parameters.AddWithValue("@ViTri", thietBi.position); cmd.Parameters.AddWithValue("@BaoHanh", thietBi.warranty); cmd.Parameters.AddWithValue("@LOG", thietBi.LOG); cmd.Parameters.AddWithValue("@TinhTrang", thietBi.status); cmd.Parameters.AddWithValue("@MaNhom", thietBi.deviceIDGroup); cmd.Parameters.AddWithValue("@TangSuat", thietBi.tangSuat); cmd.Parameters.AddWithValue("@Model", thietBi.model); cmd.Parameters.AddWithValue("@Seri", thietBi.serial); cmd.Parameters.AddWithValue("@Hang", thietBi.hangsx); cmd.Parameters.AddWithValue("@NgayThucHienCuoi", thietBi.lanCuoi); int ret = -1; try { ret = cmd.ExecuteNonQuery(); } catch (Exception e) { Debug.WriteLine("The product name is -------> " + e.Message); } dbmg.closeDatabase(); Debug.WriteLine("DEVICE IS REGISTERED "); return((ret > 0) ? ret : -1); }
private bool KiemTraTB(ThietBi thietBi) { foreach (PCTHD item in pnlCTHD) { if (item.ThietBi.Matb == thietBi.Matb) { return(false); } } return(true); }
public void EditThietBiTienNghi(ThietBi cus) { ThietBi kh = this.ThietBi.FirstOrDefault(c => c.Id == cus.Id); kh.Id = cus.Id; kh.TenTB = cus.TenTB; kh.NoiSX = cus.NoiSX; kh.DVT = cus.DVT; kh.GhiChu = cus.GhiChu; this.SaveChanges(); }
public ActionResult ThemMoi(ThietBi thietBi) { if (!CheckLogin(QuyenDangNhap.BPQuanLy)) { return(Redirect("/Login/DangNhap")); } var db = new DB(); db.ThietBis.Add(thietBi); db.SaveChanges(); return(RedirectToAction("DanhSachThietBi")); }
public ThietBi GETTHIETBI() { string ma = txtmatb.Text; string ten = txttentb.Text; string ttrang = txttinhtrang.Text; DateTime hbh = dtpNgayBH.Value; int slbh = int.Parse(txtsolanbh.Text); string mapm = cbmaPM.Text; ThietBi tb = new ThietBi(ma, ten, ttrang, hbh, slbh, mapm); return(tb); }
private void reLoad() { try { _ucTreeLoaiTB = new ucTreeLoaiTB(); _ucTreeLoaiTB.loadData(listLoaiThietBi); _ucTreeLoaiTB.Dock = DockStyle.Fill; _ucTreeLoaiTB.setReadOnly(true); panelControlLoaiThietBi.Controls.Clear(); panelControlLoaiThietBi.Controls.Add(_ucTreeLoaiTB); if (isAdd && !loaiChung) { listThietBi = ThietBi.getAllByTypeLoaiNoPhong(loaiChung); } else { if (state == 0 || state == 1) { listThietBi = ThietBi.getAllByTypeLoai(loaiChung); } else if (state == 2) { listThietBi = ThietBi.getAllByTypeLoaiHavePhong(loaiChung); } else if (state == 3) { listThietBi = ThietBi.getAllByTypeLoaiNoPhong(loaiChung); } } gridControlThietBi.DataSource = listThietBi; if (listThietBi.Count() == 0) { enableEdit(false); function = ""; deleteData(); btnR_Sua.Enabled = false; btnR_Xoa.Enabled = false; barButtonSuaThietBi.Enabled = false; barButtonXoaThietBi.Enabled = false; } else { btnR_Sua.Enabled = true && canEdit; btnR_Xoa.Enabled = true && canDelete; barButtonSuaThietBi.Enabled = true && canEdit; barButtonXoaThietBi.Enabled = true && canDelete; } } catch (Exception ex) { Debug.WriteLine(this.Name + " : reLoad : " + ex.Message); } }
public StockTakingView(ThietBi thietBi) { InitializeComponent(); this.thietBi = thietBi; LoadDataPicker(); SetData(); var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += async(s, e) => { await App.Current.MainPage.Navigation.PopAsync(); }; backLabel.GestureRecognizers.Add(tapGestureRecognizer); }
public frmXuLyDMThietBi(DataGridViewRow dgvr) {//Sửa InitializeComponent(); try { Them = false; ThietBi temp = Utils.DataGridViewRow_to_ThietBi(dgvr); txtMa.Text = temp.MaThietBi; txtMa.Enabled = false; txtTen.Text = temp.TenThietBi; } catch { } }
private void setDataObj() { try { objLoaiThietBi.ten = txtTen.Text; objLoaiThietBi.mota = txtMoTa.Text; if (ceTBsoluonglon.Checked) { if (objLoaiThietBi.thietbis.Count == 0) { ThietBi obj = new ThietBi(); obj.ten = txtTen.Text; obj.mota = txtMoTa.Text; obj.hinhanhs = listHinhs; objLoaiThietBi.thietbis.Add(obj); } else { ThietBi obj = objLoaiThietBi.thietbis.FirstOrDefault(); obj.ten = txtTen.Text; obj.mota = txtMoTa.Text; obj.hinhanhs = listHinhs; } } LoaiThietBi parentLoaiThietBi = (LoaiThietBi)lueThuoc.GetSelectedDataRow(); if (parentLoaiThietBi.id != Guid.Empty) { objLoaiThietBi.parent = LoaiThietBi.getById(parentLoaiThietBi.id); } else { if (function.Equals("edit")) { objLoaiThietBi.parent_id = null; } } if (ceTBsoluonglon.Checked) { objLoaiThietBi.loaichung = true; } else { objLoaiThietBi.loaichung = false; } } catch (Exception ex) { Debug.WriteLine(this.Name + " : setDataObj : " + ex.Message); } }
public fCapNhatTB() { InitializeComponent(); TruyenGiaTri(); string loaitaikhoan = fDangNhap.LoaiTK; if (loaitaikhoan == "user" || loaitaikhoan == "USER") { txtTenTB.ReadOnly = true; txtLoai.ReadOnly = true; txtSoLuong.ReadOnly = true; } tb = new ThietBi(); }
public List <ThietBi> ListThietBiofPhong(string maphong) { List <ThietBi> list = new List <ThietBi>(); string query = string.Format("List_ThietBi_of_Phong '{0}'", maphong); DataTable table = new DataTable(); table = SQL.ThuVienSQL.Instance.Execute_Query(query); foreach (DataRow i in table.Rows) { ThietBi tktb = new ThietBi(i); list.Add(tktb); } return(list); }
private void setDataObj() { try { objLoaiThietBi.ten = txtTen.Text; objLoaiThietBi.mota = txtMoTa.Text; if (ceTBsoluonglon.Checked) { if (objLoaiThietBi.thietbis.Count == 0) { ThietBi obj = new ThietBi(); obj.ten = txtTen.Text; obj.mota = txtMoTa.Text; obj.hinhanhs = listHinhs; objLoaiThietBi.thietbis.Add(obj); } else { ThietBi obj = objLoaiThietBi.thietbis.FirstOrDefault(); obj.ten = txtTen.Text; obj.mota = txtMoTa.Text; obj.hinhanhs = listHinhs; } } LoaiThietBi parentLoaiThietBi = (LoaiThietBi)lueThuoc.GetSelectedDataRow(); if (parentLoaiThietBi.id != Guid.Empty) objLoaiThietBi.parent = LoaiThietBi.getById(parentLoaiThietBi.id); else { if (function.Equals("edit")) { objLoaiThietBi.parent_id = null; } } if (ceTBsoluonglon.Checked) objLoaiThietBi.loaichung = true; else objLoaiThietBi.loaichung = false; } catch (Exception ex) { Debug.WriteLine(this.Name + " : setDataObj : " + ex.Message); } }
private void CRUD() { try { switch (function) { case "add": objThietBi = new ThietBi(); setDataObj(); if (objThietBi.add() > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Thêm thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); reLoadAndFocused(objThietBi.id); } break; case "edit": setDataObj(); if (objThietBi.update() > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Sửa thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); reLoadAndFocused(objThietBi.id); } break; case "delete": //Xóa sạch, ko luyến tiếc int[] indexCacRow = gridViewThietBi.GetSelectedRows(); String message = ""; Boolean thanhcong = true; if (indexCacRow.Count() == 1) message = "Bạn có chắc là xóa thiết bị này?"; if (indexCacRow.Count() > 1) message = "Bạn có chắc là xóa những thiết bị đã chọn?"; if (indexCacRow.Count() > 0) { if (XtraMessageBox.Show(message, "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { //splashScreenManager.ShowWaitForm(); //splashScreenManager.SetWaitFormCaption("Đang xóa thiết bị"); for (int i = 0; i < indexCacRow.Count(); i++) { try { objThietBi = gridViewThietBi.GetRow(indexCacRow[i]) as ThietBi; if (objThietBi.ctthietbis != null) { for (int j = 0; j < objThietBi.ctthietbis.Count; j++) { //KHÔNG NÊN XÓA BĂNG TAY KIÊU NÀY //objThietBi.ctthietbis.ElementAt(j).delete(); } } if (objThietBi.logthietbis != null) { for (int j = 0; j < objThietBi.logthietbis.Count; j++) { //KHÔNG NÊN XÓA BĂNG TAY KIÊU NÀY //objThietBi.logthietbis.ElementAt(j).delete(); } } thanhcong = objThietBi.delete() > 0 && DBInstance.commit() > 0; } catch { thanhcong = false; break; } } if (thanhcong) { reLoad(); //splashScreenManager.CloseWaitForm(); XtraMessageBox.Show("Xóa thiết bị thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { reLoad(); //splashScreenManager.CloseWaitForm(); XtraMessageBox.Show("Đã xảy ra lỗi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } break; } } catch (Exception ex) { Debug.WriteLine(this.Name + " : CRUD : " + ex.Message); } }
private void gridViewThietBi_DataSourceChanged(object sender, EventArgs e) { try { enableAllBarButton(true); if (gridViewThietBi.FocusedRowHandle > -1) { objThietBi = gridViewThietBi.GetFocusedRow() != null ? gridViewThietBi.GetFocusedRow() as ThietBi : new ThietBi(); enableEdit(false); function = ""; setData(); } else { deleteData(); } } catch (Exception ex) { Debug.WriteLine(this.Name + " : gridViewThietBi_FocusedRowChanged : " + ex.Message); } }
private void gridViewThietBi_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { try { enableAllBarButton(true); if (gridViewThietBi.FocusedRowHandle > -1) { objThietBi = gridViewThietBi.GetFocusedRow() != null ? gridViewThietBi.GetFocusedRow() as ThietBi : new ThietBi(); enableEdit(false); function = ""; setData(); } else { deleteData(); } } catch (Exception ex) { Debug.WriteLine(this.Name + "->gridViewThietBi_RowClick: " + 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; } }