Exemple #1
0
 public void loadData(int _state, bool loadLeft = false)
 {
     DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(this.ParentForm, typeof(WaitForm1), true, true, false);
     DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormCaption("Đang tải dữ liệu...");
     try
     {
         checkPermission();
         layout.load(gridViewThietBi);
         state = _state;
         if (_state == 0)
         {
             loaiChung = true;
         }
         else
         {
             loaiChung = false;
         }
         if (loadLeft)
         {
             _ucQuanLyThietBi_Control.FocusedNode(_state);
         }
         listLoaiThietBi = LoaiThietBi.getQuery().Where(c => c.loaichung == loaiChung).ToList();//getTheoLoai(loaiChung);
         listLoaiThietBi.Insert(0, loaiThietBiNULL);
         editGUIforView();
         reLoad();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "=>loadData: " + ex.Message);
     }
     DevExpress.XtraSplashScreen.SplashScreenManager.CloseForm(false);
 }
 // Load dữ liệu
 public void loadData(Phong obj = null)
 {
     try
     {
         layout.load(gridViewCTThietBi);
         working = false;
         enableEdit(false);
         List<LoaiThietBi> listLoai = LoaiThietBi.getAll();
         _ucTreeLoaiTB.loadData(listLoai);
         List<ViTriHienThi> listVitris = ViTriHienThi.getAllHavePhong();
         _ucTreeViTri.loadData(listVitris);
         if (obj != null)
         {
             objPhong = obj;
             _ucTreeViTri.setPhong(objPhong);
         }
         else
         {
             objPhong = _ucTreeViTri.getPhong();
         }
         gridControlCTThietBi.DataSource = null;
         listCTThietBis = ChiTietTBHienThi.getAllByPhongId(objPhong.id);
         gridControlCTThietBi.DataSource = listCTThietBis;
         editGUI();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->loadData:" + ex.Message);
     }
 }
 public LoaiThietBi getLoaiThietBi()
 {
     if (obj.id != Guid.Empty)
     {
         return(LoaiThietBi.getById(obj.id));
     }
     return(null);
 }
 private Boolean checkLoaiThietBiConCoThietBiKhong(LoaiThietBi parent)
 {
     foreach (LoaiThietBi loaiThietBiCon in parent.childs)
     {
         if (loaiThietBiCon.thietbis.Count > 0)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
        public async Task <IActionResult> Create(LoaiThietBi loaiThietBi)
        {
            if (ModelState.IsValid)
            {
                _unitOfWork.loaiThietBiRepository.Create(loaiThietBi);
                await _unitOfWork.Complete();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(loaiThietBi));
        }
 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);
     }
 }
Exemple #7
0
        public async Task <IActionResult> Edit(int id, LoaiThietBi loaiThietBi)
        {
            if (id != loaiThietBi.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _unitOfWork.loaiThietBiRepository.Update(loaiThietBi);
                await _unitOfWork.Complete();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(loaiThietBi));
        }
 public void setLoai(LoaiThietBi _loai)
 {
     try
     {
         if (_loai != null)
         {
             obj = _loai;
             treeListLoaiTB.CollapseAll();
             TreeListNode node = treeListLoaiTB.FindNodeByFieldValue(colid.FieldName, _loai.id);
             treeListLoaiTB.FocusedNode = node;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setLoai: " + ex.Message);
     }
 }
 private void treeListLoaiTB_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
 {
     try
     {
         if (treeListLoaiTB.GetDataRecordByNode(e.Node) != null)
         {
             enableEdit(false, "");
             SetTextGroupControl("Chi tiết", Color.Black);
             //objLoaiThietBi = (LoaiThietBi)treeListLoaiTB.GetDataRecordByNode(e.Node);
             objLoaiThietBi = LoaiThietBi.getById(GUID.From(e.Node.GetValue(colid)));
             setData();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + " : treeListLoaiTB_FocusedNodeChanged : " + ex.Message);
     }
 }
 public void reLoad()
 {
     try
     {
         checkPermission();
         enableEdit(false, "");
         loaiThietBis = LoaiTBHienThi.getAll();
         treeListLoaiTB.DataSource = loaiThietBis;
         listLoaiThietBiCha        = LoaiThietBi.getAllParent().OrderBy(l => l.order).ToList();
         listLoaiThietBiCha.Insert(0, loaiThietBiNULL);
         lueThuoc.Properties.DataSource = listLoaiThietBiCha;
         checkSuaXoa();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + " : reLoad : " + ex.Message);
     }
 }
 public List <LoaiThietBi> getListLoaiTB()
 {
     try
     {
         List <LoaiThietBi>  list     = new List <LoaiThietBi>();
         List <TreeListNode> listNode = treeListLoaiTB.GetAllCheckedNodes();
         foreach (TreeListNode node in listNode)
         {
             LoaiThietBi obj = LoaiThietBi.getById(GUID.From(node.GetValue(colid)));
             list.Add(obj);
         }
         return(list);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->getListLoaiTB: " + ex.Message);
         return(null);
     }
 }
        private void CRU()
        {
            try
            {
                switch (function)
                {
                case "add":
                    objLoaiThietBi = new LoaiThietBi();
                    setDataObj();
                    if (objLoaiThietBi.add() > 0 && DBInstance.commit() > 0)
                    {
                        XtraMessageBox.Show("Thêm loại thiết bị thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Guid id = objLoaiThietBi.id;
                        reLoadAndFocused(id);
                    }
                    else
                    {
                        XtraMessageBox.Show("Đã có lỗi xảy ra!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        reLoad();
                    }
                    break;

                case "edit":
                    setDataObj();
                    if (objLoaiThietBi.update() > 0 && DBInstance.commit() > 0)
                    {
                        XtraMessageBox.Show("Sửa loại thiết bị thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Guid id = objLoaiThietBi.id;
                        reLoadAndFocused(id);
                    }
                    else
                    {
                        XtraMessageBox.Show("Đã có lỗi xảy ra!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        reLoad();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(this.Name + " : CRU : " + ex.Message);
            }
        }
 private void treeListLoaiTB_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
 {
     try
     {
         if (!haveCheck)
         {
             obj = (LoaiThietBi)treeListLoaiTB.GetDataRecordByNode(e.Node);
             popupContainerEdit1.Text = obj.ten;
             popupContainerEdit1.ClosePopup();
             //if (type.Equals("add"))
             //{
             //    if (this.ParentForm != null)
             //    {
             //        frmNewThietBi frm = this.ParentForm as frmNewThietBi;
             //        frm.LoaiTB_FocusedChanged(obj.loaichung);
             //    }
             //}
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->treeListLoaiTB_FocusedNodeChanged: " + ex.Message);
     }
 }
        public void loadData()
        {
            checkedComboBoxEdit_tinhTrang.Properties.DataSource =
                TinhTrang.getAll();

            //ucTreeLoaiTB2
            ucTreeLoaiTB2.loadData(LoaiThietBi.getAll());
            ucTreeLoaiTB2.Dock = DockStyle.Fill;
            panelLoaiTB.Controls.Clear();
            panelLoaiTB.Controls.Add(ucTreeLoaiTB2);

            checkedComboBoxEdit_coso.Properties.DataSource = null;
            checkedComboBoxEdit_coso.Properties.DataSource = CoSo.getAll();

            //datetime
            dateEdit_to.EditValue = ServerTimeHelper.getNow();

            gridControlThongKe.DataSource = null;

            //checkPermission
            btnOK.Enabled = /*btnPrint.Enabled =*/ simpleButton_View.Enabled = simpleButton_Design.Enabled = Permission.canDo(Permission._THONGKE_INBAOCAO);

            layout.load(gridViewThongKe);
        }
 private void treeListLoaiTB_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
 {
     try
     {
         if (treeListLoaiTB.GetDataRecordByNode(e.Node) != null)
         {
             enableEdit(false, "");
             SetTextGroupControl("Chi tiết", Color.Black);
             //objLoaiThietBi = (LoaiThietBi)treeListLoaiTB.GetDataRecordByNode(e.Node);
             objLoaiThietBi = LoaiThietBi.getById(GUID.From(e.Node.GetValue(colid)));
             setData();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + " : treeListLoaiTB_FocusedNodeChanged : " + ex.Message);
     }
 }
 private void treeListLoaiTB_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
 {
     try
     {
         if (!haveCheck)
         {
             obj = (LoaiThietBi)treeListLoaiTB.GetDataRecordByNode(e.Node);
             popupContainerEdit1.Text = obj.ten;
             popupContainerEdit1.ClosePopup();
             //if (type.Equals("add"))
             //{
             //    if (this.ParentForm != null)
             //    {
             //        frmNewThietBi frm = this.ParentForm as frmNewThietBi;
             //        frm.LoaiTB_FocusedChanged(obj.loaichung);
             //    }
             //}
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->treeListLoaiTB_FocusedNodeChanged: " + ex.Message);
     }
 }
        private Boolean checkInput()
        {
            Boolean check = true;

            errorProvider1.Clear();
            if (txtTen.Text.Length == 0)
            {
                check = false;
                errorProvider1.SetError(txtTen, "Chưa điền tên thiết bị");
            }
            else
            {
                if (function.Equals("add"))
                {
                    if (loaiThietBis.Where(c => c.ten.ToUpper().Equals(txtTen.Text.ToUpper())).Count() > 0)
                    {
                        check = false;
                        errorProvider1.SetError(txtTen, "Tên loại thiết bị này đã tồn tại");
                    }
                }
                else if (function.Equals("edit"))
                {
                    if (!objLoaiThietBi.ten.ToUpper().Equals(txtTen.Text.ToUpper()) && loaiThietBis.Where(c => c.ten.ToUpper().Equals(txtTen.Text.ToUpper())).Count() > 0)
                    {
                        check = false;
                        errorProvider1.SetError(txtTen, "Tên loại thiết bị này đã tồn tại");
                    }
                }
            }
            LoaiThietBi cha = (LoaiThietBi)lueThuoc.GetSelectedDataRow();

            if (cha.id != Guid.Empty)
            {
                if (cha.loaichung)
                {
                    if (!ceTBsoluonglon.Checked)
                    {
                        check = false;
                        errorProvider1.SetError(ceTBsoluonglon, "Thiết bị cha được quản lí theo số lượng lớn, thiết bị con cũng phải thế");
                    }
                }
                else
                {
                    if (ceTBsoluonglon.Checked)
                    {
                        check = false;
                        errorProvider1.SetError(ceTBsoluonglon, "Thiết bị cha được quản lí theo đơn lẻ, thiết bị con cũng phải thế");
                    }
                }
            }
            else
            {
                if (function.Equals("edit"))
                {
                    if (objLoaiThietBi.childs.Count > 0)
                    {
                        LoaiThietBi con = objLoaiThietBi.childs.ElementAt(0);
                        if (con.loaichung)
                        {
                            if (!ceTBsoluonglon.Checked)
                            {
                                check = false;
                                errorProvider1.SetError(ceTBsoluonglon, "Các thiết bị con được quản lí theo số lượng lớn, thiết bị cha cũng phải thế");
                            }
                        }
                        else
                        {
                            if (ceTBsoluonglon.Checked)
                            {
                                check = false;
                                errorProvider1.SetError(ceTBsoluonglon, "Các thiết bị con được quản lí theo đơn lẻ, thiết bị cha cũng phải thế");
                            }
                        }
                    }
                }
            }
            return(check);
        }
 private void CRU()
 {
     try
     {
         switch (function)
         {
             case "add":
                 objLoaiThietBi = new LoaiThietBi();
                 setDataObj();
                 if (objLoaiThietBi.add() > 0 && DBInstance.commit() > 0)
                 {
                     XtraMessageBox.Show("Thêm loại thiết bị thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     Guid id = objLoaiThietBi.id;
                     reLoadAndFocused(id);
                 }
                 else
                 {
                     XtraMessageBox.Show("Đã có lỗi xảy ra!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     reLoad();
                 }
                 break;
             case "edit":
                 setDataObj();
                 if (objLoaiThietBi.update() > 0 && DBInstance.commit() > 0)
                 {
                     XtraMessageBox.Show("Sửa loại thiết bị thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     Guid id = objLoaiThietBi.id;
                     reLoadAndFocused(id);
                 }
                 else
                 {
                     XtraMessageBox.Show("Đã có lỗi xảy ra!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     reLoad();
                 }
                 break;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + " : CRU : " + ex.Message);
     }
 }
 public void setLoai(LoaiThietBi _loai)
 {
     try
     {
         if (_loai != null)
         {
             obj = _loai;
             treeListLoaiTB.CollapseAll();
             TreeListNode node = treeListLoaiTB.FindNodeByFieldValue(colid.FieldName, _loai.id);
             treeListLoaiTB.FocusedNode = node;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setLoai: " + ex.Message);
     }
 }
        public static bool ImportLoaiThietBi(String fileName, String sheet)
        {
            try
            {
                int line = 0;
                System.Data.DataTable dt = new System.Data.DataTable();
                const int STT = 0;
                const int LOAITHIETBI = 1;
                const int MOTA = 2;
                const int PARENT = 3;
                const int LOAICHUNG = 4;
                const int NGAYTAO = 5;
                const int PASS = 6;
                dt = OpenFile(fileName, sheet);
                if (dt != null)
                {
                    int lines = dt.Rows.Count;
                    foreach (System.Data.DataRow row in dt.Rows)
                    {
                        try
                        {
                            line++;
                            DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormCaption("Import Loại TB... " +
                                String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.0}", (line * 1.0 / lines) * 100) + "%");
                            if (row[LOAITHIETBI] != DBNull.Value && !row[PASS].Equals("Pass"))
                            {
                                if (row[LOAITHIETBI] != DBNull.Value && row[PARENT] != DBNull.Value && row[LOAICHUNG] != DBNull.Value)
                                {
                                    LoaiThietBi objParent = LoaiThietBi.getAll().FirstOrDefault(c => c.ten.ToUpper().Equals(row[PARENT].ToString().Trim().ToUpper()));
                                    if (objParent != null)
                                    {
                                        if (objParent.childs.FirstOrDefault(c => c.ten.ToUpper().Equals(row[LOAITHIETBI].ToString().Trim().ToUpper())) == null)
                                        {
                                            if (objParent.loaichung.Equals(Convert.ToBoolean(row[LOAICHUNG])))
                                            {
                                                LoaiThietBi obj = new LoaiThietBi();
                                                obj.ten = row[LOAITHIETBI].ToString().Trim();
                                                obj.mota = row[MOTA].ToString().Trim();
                                                obj.loaichung = Convert.ToBoolean(row[LOAICHUNG]);
                                                obj.date_create = row[NGAYTAO] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAYTAO]) : DateTime.Now;
                                                obj.parent = objParent;
                                                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 (Kiểu quản lý của loại cha và loại con khác nhau)");
                                            }
                                        }
                                        else
                                        {
                                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Exist");
                                        }
                                    }
                                    else
                                    {
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có loại thiết bị cha)");
                                    }

                                }
                                else if (row[LOAITHIETBI] != DBNull.Value && row[PARENT] == DBNull.Value && row[LOAICHUNG] != DBNull.Value)
                                {
                                    if (LoaiThietBi.getAll().FirstOrDefault(c => c.ten.ToUpper().Equals(row[LOAITHIETBI].ToString().Trim().ToUpper())) == null)
                                    {
                                        LoaiThietBi obj = new LoaiThietBi();
                                        obj.ten = row[LOAITHIETBI].ToString().Trim();
                                        obj.mota = row[MOTA].ToString().Trim();
                                        obj.loaichung = Convert.ToBoolean(row[LOAICHUNG]);
                                        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(), "Exist");
                                    }
                                }
                                else
                                {
                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không đủ thông tin)");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                            Debug.WriteLine("ExcelDataBaseHelper->ImportLoaiThietBi : " + ex.Message);
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ExcelDataBaseHelper->ImportLoaiThietBi : " + ex.Message);
                return false;
            }
        }
Exemple #21
0
        private Boolean checkInput()
        {
            Boolean check = true;

            errorProvider1.Clear();
            LoaiThietBi loaithietbi = _ucTreeLoaiTB.getLoaiThietBi();

            if (txtTen.Text.Length == 0)
            {
                check = false;
                errorProvider1.SetError(txtTen, "Chưa điền tên thiết bị");
            }
            if (loaithietbi == null)
            {
                check = false;
                errorProvider1.SetError(panelControlLoaiThietBi, "Chưa chọn loại thiết bị");
            }
            if (!loaiChung)
            {
                //if (dateEditMua.DateTime > dateEditLap.DateTime)
                //{
                //    check = false;
                //    errorProvider1.SetError(dateEditLap, "Ngày lắp phải lớn hơn ngày mua");
                //}
                if (dateEditNgayMua.EditValue != null)
                {
                    if (dateEditNgayMua.DateTime > DateTime.Today)
                    {
                        check = false;
                        errorProvider1.SetError(dateEditNgayMua, "Ngày mua lớn hơn ngày hiện tại");
                    }
                }
                else
                {
                    check = false;
                    errorProvider1.SetError(dateEditNgayMua, "Ngày mua sai");
                }
                //if (dateEditLap.DateTime > DateTime.Today)
                //{
                //    check = false;
                //    errorProvider1.SetError(dateEditLap, "Ngày lắp lớn hơn ngày hiện tại");
                //}
            }
            else
            {
                if (loaithietbi != null)
                {
                    if (function.Equals("edit"))
                    {
                        if (loaithietbi.id != objThietBi.loaithietbi.id && loaithietbi.thietbis.Count > 0)
                        {
                            check = false;
                            errorProvider1.SetError(panelControlLoaiThietBi, "Đã có thiết bị thuộc loại này");
                        }
                    }
                    else if (loaithietbi.thietbis.Count > 0)
                    {
                        check = false;
                        errorProvider1.SetError(panelControlLoaiThietBi, "Đã có thiết bị thuộc loại này");
                    }
                }
            }
            return(check);
        }
 private Boolean checkLoaiThietBiConCoThietBiKhong(LoaiThietBi parent)
 {
     foreach (LoaiThietBi loaiThietBiCon in parent.childs)
     {
         if (loaiThietBiCon.thietbis.Count > 0)
             return true;
     }
     return false;
 }