private void button1_Click(object sender, EventArgs e) { //Chọn files OpenFileDialog x = new OpenFileDialog(); x.Multiselect = true; x.ShowDialog(); string[] file_names = x.FileNames; //Tạo chứng từ mới ct = new ChungTu(); ct.ngay = ServerTimeHelper.getNow(); ct.sohieu = "mã chứng từ"; //Gán attchment foreach (string file_name in file_names) { Attachment tmp = new Attachment(); tmp.LOCAL_FILE_PATH = file_name; ct.attachments.Add(tmp); } //register event ct.onUploadProgress += new SHARED.Libraries.FTPHelper.UploadProgress(this.onChungTu_Uploading); // do in background cancel = new CancellationTokenSource(); var re = ct.upload(cancel.Token).ContinueWith(new Action <Task>(this.onUploadFinish)); }
private void setData(CTTaiSan obj) { try { dateNgaySD.EditValue = obj.ngay; txtSoHieu_CT.Text = obj.chungtu != null ? obj.chungtu.sohieu : ""; dateNgay_CT.EditValue = obj.chungtu != null ? obj.chungtu.ngay : null; txtMa.Text = obj.taisan.subId; txtTen.Text = obj.taisan.ten; ucComboBoxLoaiTS1.LoaiTS = obj.taisan.loaitaisan; txtSoLuong.EditValue = obj.soluong; txtDonGia.EditValue = obj.taisan.dongia; lookUpTinhTrang.EditValue = obj.tinhtrang_id; txtNSX.Text = obj.taisan.nuocsx; txtNguonGoc.Text = obj.nguongoc; txtGhiChu.Text = obj.mota; listCTTaiSan = obj.childs != null?obj.childs.ToList() : null; gridControlTaiSan.DataSource = TaiSanHienThi.Convert(listCTTaiSan); objChungTu = obj.chungtu; //tabDonVi spinSoLuongDonVi.EditValue = spinSoLuongTinhTrang.EditValue = obj.soluong; ucComboBoxViTri1.Phong = objCTTaiSan.phong; ucComboBoxViTri2.ViTri = objCTTaiSan.vitri; ucComboBoxDonVi1.DonVi = objCTTaiSan.donviquanly; spinSoLuongDonVi.Properties.MaxValue = obj.soluong; //tabTinhTrang lookUpChuyenTinhTrang.EditValue = obj.tinhtrang_id; spinSoLuongTinhTrang.Properties.MaxValue = obj.soluong; } catch (Exception ex) { Debug.WriteLine(this.Name + "->setData:" + ex.Message); } }
public frmFileChungTu(ChungTu _obj, bool _save = false) { InitializeComponent(); this.ct2 = _obj; this.save = _save; this.ct.attachments = new List<Attachment>(_obj.attachments); loadData(); }
public frmFileChungTu(ChungTu _obj, bool _save = false) { InitializeComponent(); this.ct2 = _obj; this.save = _save; this.ct.attachments = new List <Attachment>(_obj.attachments); loadData(); }
public XtraReport_BienBanGiaoNhanTSCD(CTTaiSan _CTTaiSan, ChungTu _ChungTu, DonVi _DonVi) { InitializeComponent(); this.objCTTaiSan = _CTTaiSan; this.objChungTu = _ChungTu; this.objDonVi = _DonVi; IntReport(); }
private void barbtnchungtu_ItemClick(object sender, ItemClickEventArgs e) { ChungTu ChungTu = new ChungTu(); if (ExistsForm(ChungTu)) { return; } ChungTu.MdiParent = this; ChungTu.Show(); }
private void btnAttachment_Click(object sender, EventArgs e) { if (objChungTu != null) { frmFileChungTu frm = new frmFileChungTu(objChungTu); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { objChungTu = frm.ct; } } }
private void button1_Click(object sender, EventArgs e) { //Chọn files OpenFileDialog x = new OpenFileDialog(); x.Multiselect = true; x.ShowDialog(); string[] file_names = x.FileNames; //Tạo chứng từ mới ct = new ChungTu(); ct.ngay = ServerTimeHelper.getNow(); ct.sohieu = "mã chứng từ"; //Gán attchment foreach (string file_name in file_names) { Attachment tmp = new Attachment(); tmp.LOCAL_FILE_PATH = file_name; ct.attachments.Add(tmp); } //register event ct.onUploadProgress += new SHARED.Libraries.FTPHelper.UploadProgress(this.onChungTu_Uploading); // do in background cancel = new CancellationTokenSource(); var re = ct.upload(cancel.Token).ContinueWith(new Action<Task>(this.onUploadFinish)); }
public static bool ImportTaiSan2(String fileName, String sheet) { try { int line = 0; System.Data.DataTable dt = new System.Data.DataTable(); const int STT = 0; const int SOHIEU = 1; const int NGAY = 2; const int TEN = 3; const int DONGIA = 6; const int GHICHU = 8; const int DONVI = 9; const int PHONG = 10; //const int TINHTRANG = 11; const int LOAI = 12; const int PASS = 13; dt = OpenFile(fileName, sheet); if (dt != null) { int lines = dt.Rows.Count; foreach (System.Data.DataRow row in dt.Rows) { line++; if (line % 200 == 0) DBInstance.reNew(); //DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormCaption("Đang Import... " + // String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.00}", (line * 1.0 / lines) * 100) + "%"); DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormCaption("Import... " + line + "/" + lines); if (row[PASS] == DBNull.Value || (!row[PASS].Equals("Pass") && !row[PASS].Equals("Error (Không đủ thông tin)"))) { if (row[TEN] != DBNull.Value && !String.IsNullOrWhiteSpace(row[TEN].ToString()) && row[DONGIA] != DBNull.Value) { 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; if (row[LOAI] == DBNull.Value) { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có loai)"); continue; } 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; ChungTu objChungTu = new ChungTu(); objChungTu.sohieu = row[SOHIEU] != DBNull.Value ? row[SOHIEU].ToString() : null; objChungTu.ngay = row[NGAY] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAY]) : null; objCTTaiSan.chungtu = objChungTu; objCTTaiSan.mota = row[GHICHU] != DBNull.Value ? row[GHICHU].ToString() : null; objCTTaiSan.tinhtrang = TinhTrang.getQuery().FirstOrDefault(c => c.value.Equals("Đang sử dụng")); objCTTaiSan.soluong = 1; if (objCTTaiSan.add() > 0) { if (row[DONVI] == DBNull.Value) continue; string str2 = row[DONVI].ToString().Trim(); DonVi objDonVi = DonVi.getQuery().Where(c => c.subId.Equals(str2)).FirstOrDefault(); Phong objPhong = null; ViTri objViTri = null; if (row[PHONG] != DBNull.Value) { string phong = row[PHONG].ToString().Trim(); objPhong = Phong.getQuery().Where(c => c.ten.Equals(phong)).FirstOrDefault(); if (objPhong == null) { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error (Không có phòng)"); continue; } //else //objViTri = objPhong.vitri; } if (objCTTaiSan.chuyenDonVi(objDonVi, null, objViTri, 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"); continue; } } else { WriteFile(fileName, sheet, row[STT].ToString().Trim(), "Error"); continue; } //if (row[TINHTRANG] != DBNull.Value) //{ // String ten_tinhtrang = row[TINHTRANG].ToString().Trim().ToUpper(); // TinhTrang 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; // } // if (obj.chuyenTinhTrang(obj.chungtu, objTinhTrang, obj.soluong, obj.ghichu) > 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 (Không đủ thông tin)"); } } } } return true; } catch (Exception ex) { Debug.WriteLine("ExcelDataBaseHelper->ImportTaiSan: " + ex.Message); return false; } }
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; } }
public static bool ImportChungTu(String fileName, String sheet) { try { int line = 0; System.Data.DataTable dt = new System.Data.DataTable(); const int STT = 0; const int SOHIEU = 1; const int NGAY = 2; const int TEN = 3; const int DONGIA = 6; const int PASS = 8; 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[PASS] == DBNull.Value || !row[PASS].Equals("Pass")) { if (row[TEN] != DBNull.Value && !String.IsNullOrWhiteSpace(row[TEN].ToString()) && row[DONGIA] != DBNull.Value) { String ten = row[TEN].ToString().Trim().ToUpper(); String str = row[DONGIA].ToString().Trim().Replace(" ", ""); long dongia = long.Parse(str); CTTaiSan obj = CTTaiSan.getQuery().Where(c => c.taisan.ten.ToUpper().Equals(ten) && c.taisan.dongia.Equals(dongia) && (c.chungtu == null || (c.chungtu.sohieu == null && c.chungtu.ngay == null))).FirstOrDefault(); if (obj != null) { if (obj.chungtu == null) { ChungTu objChungTu = new ChungTu(); objChungTu.sohieu = row[SOHIEU] != DBNull.Value ? row[SOHIEU].ToString().Trim() : null; objChungTu.ngay = row[NGAY] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAY]) : null; obj.chungtu = objChungTu; } else { obj.chungtu.sohieu = row[SOHIEU] != DBNull.Value ? row[SOHIEU].ToString().Trim() : null; obj.chungtu.ngay = row[NGAY] != DBNull.Value ? (DateTime?)Convert.ToDateTime(row[NGAY]) : null; } if (obj.update() > 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 (Không tìm thấy tài sản)"); } } 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; } }
public ResponseResult Create() { try { string domain; var folderPath = ""; var fileName = ""; var myuri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri); var pathQuery = myuri.PathAndQuery; var appUrl = HttpRuntime.AppDomainAppVirtualPath; domain = myuri.ToString().Replace(pathQuery, "")+ appUrl.Trim(); logger.Trace("domain: ", domain.ToLower()); var httpRequest = HttpContext.Current.Request; var strJson = httpRequest.Form["data"].Trim(); var model = JsonConvert.DeserializeObject<ChungTuModel>(strJson); if (!ModelState.IsValid) { var result = new Response<ChungTuModel> { Message = HttpMessage.INVALID_MODEL, Status = false, }; ActionContext.Response.StatusCode = HttpStatusCode.BadRequest; return new ResponseResult(result, ActionContext); } var postedFile = httpRequest.Files["file"]; if (postedFile != null && postedFile.ContentLength > 0) { var MaxContentLength = 1024 * 1024 * 10; //Size = 10 MB IList<string> allowedFileExtensions = new List<string> {".pdf" }; var ext = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.')); var extension = ext.ToLower(); if (!allowedFileExtensions.Contains(extension)) { logger.Info("Extend file not .pdf .jpg,.gif,.png"); var dataReturnError = new Response<ChungTuModel> { Message = HttpMessage.ERROR_IMG_TYPE, Status = false }; ActionContext.Response.StatusCode = HttpStatusCode.Redirect; return new ResponseResult(dataReturnError, ActionContext); } if (postedFile.ContentLength > MaxContentLength) { logger.Info("Size file > 10mb"); var dataCheckSize = new Response<ChungTuModel> { Message = HttpMessage.ERROR_IMG_SIZE_5, Status = false }; ActionContext.Response.StatusCode = HttpStatusCode.LengthRequired; return new ResponseResult(dataCheckSize, ActionContext); } folderPath = @"~/Uploads/" + model.MaChungTu.Replace("/","").ToString().Trim(); fileName = "CT_" + model.MaChungTu.Replace("/", "").ToString()+ extension; var folderExists = Directory.Exists(HttpContext.Current.Request.MapPath(folderPath)); if (!folderExists) Directory.CreateDirectory(HttpContext.Current.Request.MapPath(folderPath)); var pathUrl = Path.Combine( HttpContext.Current.Request.MapPath(folderPath), fileName ); postedFile.SaveAs(pathUrl); } var chungtu = new ChungTu { MaChungTu = model.MaChungTu, DonViBanHanh = model.DonViBanHanh, MaDonVi = model.MaDonVi, MaVach = "", NgayBanHanh = model.NgayBanHanh, NguoiKy = model.NguoiKy, MaLoaiChungTu = model.MaLoaiChungTu, Ten = model.Ten, TrangThai = 1, FileDinhKem= folderPath+"/"+fileName }; _chungtuService.Create(chungtu); model.FileDinhKem = domain + folderPath.Replace("~/", "") + "/" + fileName; var data = new Response<ChungTuModel> { Message = "Create Success", Status = true, Data = model }; return new ResponseResult(data, ActionContext); } catch (Exception ex) { logger.Error(ex); var data = new Response<ChungTuModel> { Message = HttpMessage.ERROR_CREATE, Status = false }; ActionContext.Response.StatusCode = HttpStatusCode.InternalServerError; return new ResponseResult(data, ActionContext); } }
private void setData(CTTaiSan obj) { try { dateNgaySD.EditValue = obj.ngay; txtSoHieu_CT.Text = obj.chungtu != null ? obj.chungtu.sohieu : ""; dateNgay_CT.EditValue = obj.chungtu != null ? obj.chungtu.ngay : null; txtMa.Text = obj.taisan.subId; txtTen.Text = obj.taisan.ten; ucComboBoxLoaiTS1.LoaiTS = obj.taisan.loaitaisan; txtSoLuong.EditValue = obj.soluong; txtDonGia.EditValue = obj.taisan.dongia; lookUpTinhTrang.EditValue = obj.tinhtrang_id; txtNSX.Text = obj.taisan.nuocsx; txtNguonGoc.Text = obj.nguongoc; txtGhiChu.Text = obj.mota; listCTTaiSan = obj.childs != null ? obj.childs.ToList() : null; gridControlTaiSan.DataSource = TaiSanHienThi.Convert(listCTTaiSan); objChungTu = obj.chungtu; //tabDonVi spinSoLuongDonVi.EditValue = spinSoLuongTinhTrang.EditValue = obj.soluong; ucComboBoxViTri1.Phong = objCTTaiSan.phong; ucComboBoxViTri2.ViTri = objCTTaiSan.vitri; ucComboBoxDonVi1.DonVi = objCTTaiSan.donviquanly; spinSoLuongDonVi.Properties.MaxValue = obj.soluong; //tabTinhTrang lookUpChuyenTinhTrang.EditValue = obj.tinhtrang_id; spinSoLuongTinhTrang.Properties.MaxValue = obj.soluong; } catch (Exception ex) { Debug.WriteLine(this.Name + "->setData:" + ex.Message); } }
private void btnAttachment_Click(object sender, EventArgs e) { if (objChungTu != null) { frmFileChungTu frm = new frmFileChungTu(objChungTu); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) objChungTu = frm.ct; } }