private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         //DateTime ngayGhi = dateNgayGhi.EditValue != null ? dateNgayGhi.DateTime : DateTime.Now;
         //objChungTu.sohieu = txtSoHieu_CT.Text;
         //objChungTu.ngay = dateNgay_CT.EditValue != null ? dateNgay_CT.DateTime : DateTime.Now;
         int       soLuong   = Convert.ToInt32(txtSoLuong.EditValue);
         TinhTrang tinhTrang = TinhTrang.getById(lookUpTinhTrang.EditValue);
         String    ghiChu    = txtGhiChu.Text;
         CTTaiSan  re        = objCTTaiSan.chuyenTinhTrang(objCTTaiSan.chungtu, tinhTrang, soLuong, ghiChu);
         if (re != null && DBInstance.commit() > 0)
         {
             XtraMessageBox.Show("Chuyển tình trạng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             //Guid id = CTTaiSan.getQuery().Where(c => c.taisan_id == objCTTaiSan.taisan_id && c.tinhtrang_id == tinhTrang.id && c.soluong == soLuong).FirstOrDefault().id;
             if (reloadAndFocused != null)
             {
                 reloadAndFocused(re.id);
             }
             this.Close();
         }
         else
         {
             XtraMessageBox.Show("Chuyển tình trạng không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->btnOK_Click: " + ex.Message);
     }
 }
        public static bool AddTaiSan(String fileName, String sheet)
        {
            try
            {
                int line = 0;
                System.Data.DataTable dt = new System.Data.DataTable();

                const int STT = 0;
                const int NGAY = 3;
                const int SOHIEU_CT = 1;
                const int TEN = 6;
                const int LOAI = 18;
                //const int DONVITINH = 5;
                //const int NGAY_SD = 6;
                //const int NUOC_SX = 7;
                //const int SOLUONG = 8;
                const int DONGIA = 13;
                //const int THANHTIEN = 10;
                const int TINHTRANG = 21;
                //const int VITRI = 12;
                const int PHONG = 20;
                const int DONVI_QL = 19;
                const int GHICHU = 22;
                const int CHECK = 23;

                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("Đang Import... " +
                            String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.00}", (line * 1.0 / lines) * 100) + "%");
                        if (row[CHECK] == DBNull.Value || !row[CHECK].Equals("Pass"))
                        {
                            if (row[TEN] != DBNull.Value && !String.IsNullOrWhiteSpace(row[TEN].ToString()) && row[LOAI] != DBNull.Value && !String.IsNullOrWhiteSpace(row[LOAI].ToString()))
                            {
                                TinhTrang objTinhTrang = null;
                                if (row[TINHTRANG] != DBNull.Value && !String.IsNullOrWhiteSpace(row[TINHTRANG].ToString()))
                                {
                                    String ten_tinhtrang = row[TINHTRANG].ToString().Trim().ToUpper();
                                    objTinhTrang = TinhTrang.getQuery().Where(c => c.value.ToUpper().Equals(ten_tinhtrang)).FirstOrDefault();
                                    if (objTinhTrang == null)
                                    {
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có tình trạng)");
                                        continue;
                                    }
                                }
                                DonVi objDonVi = null;
                                if (row[DONVI_QL] != DBNull.Value && !String.IsNullOrWhiteSpace(row[DONVI_QL].ToString()))
                                {
                                    String ten_donvi_ql = row[DONVI_QL].ToString().Trim();
                                    objDonVi = DonVi.getQuery().Where(c => c.subId.Equals(ten_donvi_ql)).FirstOrDefault();
                                    if (objDonVi == null)
                                    {
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có đơn vị quản lý)");
                                        continue;
                                    }
                                }
                                Phong objPhong = null;
                                if (row[PHONG] != DBNull.Value && !String.IsNullOrWhiteSpace(row[PHONG].ToString()))
                                {
                                    String ten_phong = row[PHONG].ToString().Trim().ToUpper();
                                    objPhong = Phong.getQuery().Where(c => c.ten.ToUpper().Equals(ten_phong)).FirstOrDefault();
                                    if (objPhong == null)
                                    {
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có phòng)");
                                        continue;
                                    }
                                }

                                try
                                {
                                    TaiSan obj = new TaiSan();
                                    obj.ten = row[TEN].ToString().Trim();
                                    String str = row[DONGIA].ToString().Trim().Replace(" ", "");
                                    long dongia = long.Parse(str);
                                    obj.dongia = dongia;
                                    string str1 = row[LOAI].ToString().Trim();
                                    obj.loaitaisan = LoaiTaiSan.getQuery().Where(c => c.ten.Equals(str1)).FirstOrDefault();
                                    CTTaiSan objCTTaiSan = new CTTaiSan();
                                    objCTTaiSan.taisan = obj;
                                    objCTTaiSan.ngay = row[NGAY] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAY]) : null;
                                    objCTTaiSan.tinhtrang = TinhTrang.getQuery().FirstOrDefault(c => c.value.Equals("Đang sử dụng"));
                                    objCTTaiSan.soluong = 1;
                                    ChungTu chungtu = new ChungTu();
                                    chungtu.ngay = row[NGAY] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAY]) : null;
                                    chungtu.sohieu = row[SOHIEU_CT] != DBNull.Value ? row[SOHIEU_CT].ToString().Trim() : "";
                                    objCTTaiSan.chungtu = chungtu;
                                    objCTTaiSan.ghichu = row[GHICHU] != DBNull.Value ? row[GHICHU].ToString().Trim() : "";
                                    if (objCTTaiSan.add() > 0)
                                    {
                                        if (objDonVi != null)
                                        {
                                            if (objCTTaiSan.chuyenDonVi(objDonVi, null, null, objPhong, objCTTaiSan.parent, objCTTaiSan.chungtu, objCTTaiSan.soluong, "", objCTTaiSan.ngay) != null && DBInstance.commit() > 0)
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass");
                                            }
                                            else
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Chuyển vị trí)");
                                                continue;
                                            }
                                        }
                                        if (objTinhTrang != null)
                                        {
                                            if (objCTTaiSan.chuyenTinhTrang(objCTTaiSan.chungtu, objTinhTrang, objCTTaiSan.soluong, objCTTaiSan.ghichu) != null && DBInstance.commit() > 0)
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass");
                                            }
                                            else
                                            {
                                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Chuyển tình trạng)");
                                                continue;
                                            }
                                        }
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Pass");
                                    }
                                    else
                                    {
                                        WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine("ExcelDataBaseHelper->AddTaiSan: " + ex.Message);
                                    WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error");
                                }
                            }
                            else
                            {
                                WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không đủ thông tin)");
                            }
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ExcelDataBaseHelper->ImportTaiSan: " + ex.Message);
                return false;
            }
        }
Exemple #3
0
        private Guid editObj()
        {
            try
            {
                objCTTaiSan.taisan.ten    = txtTen.Text;
                objCTTaiSan.taisan.dongia = txtDonGia.EditValue != null?long.Parse(txtDonGia.EditValue.ToString()) : 0;

                objCTTaiSan.taisan.loaitaisan = ucComboBoxLoaiTS1.LoaiTS;
                objCTTaiSan.taisan.subId      = txtMa.Text;

                objChungTu.ngay     = dateNgay_CT.EditValue != null ? dateNgay_CT.DateTime : DateTime.Now;
                objChungTu.sohieu   = txtSoHieu_CT.Text;
                objCTTaiSan.chungtu = objChungTu;

                objCTTaiSan.ngay          = dateNgaySD.EditValue != null ? dateNgaySD.DateTime : DateTime.Now;
                objCTTaiSan.taisan.nuocsx = txtNSX.Text;
                objCTTaiSan.nguongoc      = txtNguonGoc.Text;
                objCTTaiSan.soluong       = Convert.ToInt32(txtSoLuong.EditValue);
                objCTTaiSan.tinhtrang     = TinhTrang.getById(GUID.From(lookUpTinhTrang.EditValue));
                objCTTaiSan.mota          = txtGhiChu.Text;
                objCTTaiSan.childs        = listCTTaiSan;
                int re = objCTTaiSan.update();//ONly call add on CTTaiSan
                //chuyen don vi
                int    soLuongDV = Convert.ToInt32(spinSoLuongDonVi.EditValue);
                Phong  phong     = ucComboBoxViTri1.Phong;
                ViTri  viTri     = ucComboBoxViTri2.ViTri;
                DonVi  donViQL   = ucComboBoxDonVi1.DonVi;
                String ghiChuDV  = txtGhiChuDonVi.Text;
                if (!Object.Equals(objCTTaiSan.phong, phong) || !Object.Equals(objCTTaiSan.vitri, viTri) || !Object.Equals(objCTTaiSan.donviquanly, donViQL))
                {
                    CTTaiSan tmp = objCTTaiSan.chuyenDonVi(donViQL, null, viTri, phong, objCTTaiSan.parent, objCTTaiSan.chungtu, soLuongDV, ghiChuDV);
                    if (tmp != null)
                    {
                        objCTTaiSan = tmp;
                    }
                    else
                    {
                        XtraMessageBox.Show("Sửa tài sản không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(Guid.Empty);
                    }
                }
                //chuyen tinh trang
                int       soLuongTT = Convert.ToInt32(spinSoLuongTinhTrang.EditValue);
                TinhTrang tinhTrang = TinhTrang.getById(lookUpChuyenTinhTrang.EditValue);
                String    ghiChuTT  = txtGhiChuTinhTrang.Text;
                if (!Object.Equals(objCTTaiSan.tinhtrang, tinhTrang))
                {
                    CTTaiSan tmp = objCTTaiSan.chuyenTinhTrang(objCTTaiSan.chungtu, tinhTrang, soLuongTT, ghiChuTT);
                    if (tmp == null)
                    {
                        XtraMessageBox.Show("Sửa tài sản không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(Guid.Empty);
                    }
                }
                if (!isChild)
                {
                    re = DBInstance.commit();
                }
                if (re > 0)
                {
                    XtraMessageBox.Show("Sửa tài sản thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(objCTTaiSan.id);
                }
                else
                {
                    XtraMessageBox.Show("Sửa tài sản không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(Guid.Empty);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(this.Name + "->editObj:" + ex.Message);
                return(Guid.Empty);
            }
        }