public DataTable GetDataGridDoc(string ASNNo) { InventoryFacade facade = null; if (facade == null) { facade = new InventoryFacade(DataProvider); } object[] objs = facade.QueryInvDoc(FormatHelper.PKCapitalFormat(FormatHelper.CleanString(ASNNo))); //设置DataTable的tableName 否则序列化会报错 DataTable dt = new DataTable("ExampleDataTable"); if (objs != null) { dt.Columns.Add("选择", typeof(string)); dt.Columns.Add("文件名", typeof(string)); dt.Columns.Add("文件大小", typeof(string)); dt.Columns.Add("上传者", typeof(string)); dt.Columns.Add("上传日期", typeof(string)); for (int i = 0; i < objs.Length; i++) { InvDoc doc = objs[i] as InvDoc; dt.Rows.Add("", doc.DocName, doc.DocSize.ToString(), doc.UpUser, FormatHelper.ToDateString(doc.UpfileDate)); } } return(dt); }
//导入 protected void cmdEnter_ServerClick(object sender, EventArgs e) { if (_InventoryFacade == null) { _InventoryFacade = new InventoryFacade(base.DataProvider); } string asnNo = FormatHelper.CleanString(this.txtStorageInASNEdit.Text); if (string.IsNullOrEmpty(asnNo)) { WebInfoPublish.PublishInfo(this, "入库指令号为空", this.languageComponent1); return; } if (this.FileImport.PostedFile != null) { try { HttpPostedFile postedFile = this.FileImport.PostedFile; DBDateTime dbDateTime = FormatHelper.GetNowDBDateTime(base.DataProvider); InvDoc invDoc = _InventoryFacade.CreateNewInvDoc(); invDoc.InvDocNo = asnNo; invDoc.InvDocType = "DirectSign"; invDoc.DocType = Path.GetExtension(postedFile.FileName); invDoc.DocName = Path.GetFileNameWithoutExtension(postedFile.FileName); invDoc.DocSize = postedFile.ContentLength / 1024; invDoc.UpUser = this.GetUserCode(); invDoc.UpfileDate = dbDateTime.DBDate; invDoc.MaintainUser = this.GetUserCode(); invDoc.MaintainDate = dbDateTime.DBDate; invDoc.MaintainTime = dbDateTime.DBTime; invDoc.Dirname = "InvDoc"; string path = Server.MapPath(this.VirtualHostRoot + "InvDoc/" + "直发入库客户接受凭证/"); string fileName = string.Format("{0}_DirectSign_{1}{2}{3}", this.txtStorageInASNEdit.Text, dbDateTime.DBDate, dbDateTime.DBTime, invDoc.DocType); invDoc.ServerFileName = fileName; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } invDoc.Dirname = "直发入库客户接受凭证"; this.FileImport.PostedFile.SaveAs(path + fileName); _InventoryFacade.AddInvDoc(invDoc); WebInfoPublish.PublishInfo(this, "$Success_UpLoadFile", this.languageComponent1); } catch (Exception ex) { WebInfoPublish.PublishInfo(this, ex.Message, this.languageComponent1); } } else { WebInfoPublish.PublishInfo(this, "导入文件不能为空", this.languageComponent1); } }
public bool UploadFile(byte[] bytes, string asn, string type, string userName) { if (bytes.Length > 0) { MemoryStream ms = new MemoryStream(bytes); string root = HttpContext.Current.Server.MapPath("~/"); string path = root + @"InvDoc\初检签收\"; string stamp = DateTime.Now.ToString("yyyyMMddmmhhss"); string fileName = "ASN" + asn + "_" + type + "_" + stamp; string fullPath = path + fileName; try { Image img = Image.FromStream(ms); img.Save(fullPath + ".jpg"); } catch (ArgumentException ex) { return(false); } InvDoc doc = new InvDoc(); doc.Dirname = "初检签收"; doc.InvDocNo = asn; doc.InvDocType = type; doc.DocName = fileName; doc.DocType = "jpg"; doc.DocSize = (bytes.Length / 1024); doc.UpUser = userName; doc.UpfileDate = FormatHelper.TODateInt(DateTime.Now); doc.ServerFileName = fileName + ".jpg"; doc.MaintainUser = userName; doc.MaintainTime = FormatHelper.TOTimeInt(DateTime.Now); doc.MaintainDate = FormatHelper.TODateInt(DateTime.Now); InventoryFacade _inventoryFacade = new InventoryFacade(); _inventoryFacade.AddInvDoc(doc); return(true); } return(false); }
protected override void Grid_ClickCell(GridRecord row, string commandName) { try { if (commandName == "Docname") { if (_documentFacade == null) { _documentFacade = new DocumentFacade(this.DataProvider); } if (inventoryFacade == null) { inventoryFacade = new BenQGuru.eMES.Material.InventoryFacade(base.DataProvider); } //bool right = _documentFacade.GetDocDirRight(int.Parse(row.Items.FindItemByKey("Dirserial").Value.ToString()), this.GetUserCode(), "QUERY"); InvDoc doc = inventoryFacade.GetInvDoc(int.Parse(row.Items.FindItemByKey("Docserial").Value.ToString())) as InvDoc; if (doc != null) { //if (doc.Checkedstatus == "Y" && doc.Validstatus == "Y") //{ if (_facade == null) { _facade = new SystemSettingFacade(this.DataProvider); } //object parameter = _facade.GetParameter("DOCDIRPATH", "DOCDIRPATHGROUP"); //if (parameter != null) //{ //服务器目录路径 //string filePath = ((Domain.BaseSetting.Parameter)parameter).ParameterAlias; string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "InvDoc/" + doc.Dirname; //+ "FileUpload"; if (filePath.LastIndexOf('\\') == filePath.Length - 1) { filePath = filePath.Substring(0, filePath.Length - 1); } #region//下载文件 FileInfo currentFile = new FileInfo(filePath + "/" + row.Items.FindItemByKey("ServerFullName").Value.ToString()); if (currentFile.Exists) { this.DownloadFileFull(this.VirtualHostRoot + "InvDoc/" + doc.Dirname + "/" + row.Items.FindItemByKey("ServerFullName").Value); } else { Log.Error(filePath + "/" + row.Items.FindItemByKey("ServerFullName").Value.ToString() + " 不存在!"); WebInfoPublish.PublishInfo(this, row.Items.FindItemByKey("ServerFullName").Value.ToString() + "不存在", this.languageComponent1); } #endregion //} //else //{ // WebInfoPublish.PublishInfo(this, "$Error_DocDirPath_NotExist", this.languageComponent1); //} // } // else // { // WebInfoPublish.PublishInfo(this, "$Error_FileIsNotCheckedOrValid", this.languageComponent1); // } } else { WebInfoPublish.PublishInfo(this, "$Error_HaveNoRightToDownload", this.languageComponent1); } } } catch (Exception ex) { Log.Error(ex.StackTrace); WebInfoPublish.PublishInfo(this, "$Error_QueryFile_Exception", this.languageComponent1); } }