public ActionResult FieldAttachAddView() { var list = DB.T_GM_TypeNo.ToList(); List <T_GM_TypeNo> lis = new List <T_GM_TypeNo>(); foreach (var item in list) { if (item.TypeID.Contains("FD_")) { lis.Add(item); } } foreach (var item in lis) { FileUploadField fdn = new FileUploadField() { ID = item.TypeID.Trim(), LabelWidth = 80, Icon = Icon.Attach, FieldLabel = item.TypeName, ButtonText = "选择文件", }; fdn.AddTo(this.GetCmp <Container>("cc")); } this.GetCmp <Container>("cc").SetActive(true); ViewBag.prono = cw.SetCombox_PNo(); return(View()); }
public ActionResult Save(UserData data) { try { FileUploadField upload = this.GetCmp <FileUploadField>("Userimage"); data.UserImageFile = upload.PostedFile; if (upload.HasFile) { data.UserImage = string.Format("~/Images/{0}/{1}.{2}", data.UserName, Guid.NewGuid().ToString(), Path.GetExtension(data.UserImageFile.FileName)); data.UserImageSavePath = Server.MapPath(data.UserImage); data.UserImageFileType = data.UserImageFile.ContentType; } if (data.SavaData()) { X.MessageBox.Notify("消息", "信息保存成功!").Show(); } else { X.MessageBox.Notify("消息", "信息保存失败!").Show(); } } catch { X.MessageBox.Notify("消息", "信息保存失败!").Show(); } return(this.Direct()); }
public ActionResult Submit(CollectionPlan cplan) { FileUtility attachFile = new FileUtility(); FileUploadField upload = this.GetCmp <FileUploadField>("AnnetPath"); if (upload.HasFile) { attachFile.File = upload.PostedFile; cplan.Attachment = string.Format("~/AttachFile/CollectionPlan/{0}/{1}.{2}", DateTime.Now.Date.ToString("yyyy-MM-dd"), Guid.NewGuid(), Path.GetExtension(attachFile.File.FileName)); attachFile.FilePath = cplan.Attachment; attachFile.SavePath = Server.MapPath(attachFile.FilePath); attachFile.FileType = attachFile.File.ContentType; } bool flag = cplan.Save(this, attachFile); X.Msg.Alert("页面消息", flag ? "提交成功!" : "提交失败!", flag ? "parent.App.win.close();" : null).Show(); if (flag) { X.AddScript("parent.App.storedata.reload();"); } return(this.Direct()); }
public ActionResult Submit(DailyWorkReportModel model) { string chongfu = Chongfu(model.WorkHourses); if (chongfu != "-11111") { var staff = from o in entities.T_HR_Staff where o.StaffID == chongfu select o; chongfu = "工号:" + chongfu + ",姓名:" + staff.First().Name; X.Msg.Alert("警告", "具有重复员工!<\br>" + chongfu).Show(); return(this.Direct()); } string chongfudb = ChongfuComDB(model); if (chongfudb != "-11111") { X.Msg.Alert("警告", chongfudb).Show(); return(this.Direct()); } FileUtility attachFile = new FileUtility(); FileUploadField upload = this.GetCmp <FileUploadField>("AnnetPath"); attachFile.File = upload.PostedFile; if (upload.HasFile) { model.AttachFile = string.Format("~/AttachFile/DailyWorkReport/{0}/{1}.{2}", DateTime.Now.Date.ToString("yyyy-MM-dd"), Guid.NewGuid(), Path.GetExtension(attachFile.File.FileName)); attachFile.FilePath = model.AttachFile; attachFile.SavePath = Server.MapPath(attachFile.FilePath); attachFile.FileType = attachFile.File.ContentType; } bool flag = model.Save(this, attachFile); X.Msg.Alert("页面消息", flag ? "工作日报提交成功!" : "工作日报提交失败!", flag?"parent.App.win.close();":null).Show(); if (flag) { X.AddScript("parent.App.storedata.reload();"); } return(this.Direct()); }
/// <summary> /// upload file from computer to server /// </summary> /// <param name="sender">ID of FileUploadField</param> /// <param name="relativePath">the relative path to place you want to save file</param> /// <returns>The path of file after upload to server</returns> private string UploadFile(object sender, string relativePath) { FileUploadField obj = (FileUploadField)sender; HttpPostedFile file = obj.PostedFile; DirectoryInfo dir = new DirectoryInfo(Server.MapPath(relativePath)); // if directory not exist then create this if (dir.Exists == false) { dir.Create(); } string rdstr = Util.GetInstance().GetRandomString(7); string path = Server.MapPath(relativePath) + "/" + rdstr + "_" + obj.FileName; if (File.Exists(path)) { return(""); } file.SaveAs(path); //return relativePath + "/" + rdstr + "_" + obj.FileName; return(path); }
/// <summary> /// upload file from computer to server /// </summary> /// <param name="sender">ID of FileUploadField</param> /// <param name="directory">directory of folder HoSoNhanSu</param> /// <param name="relativePath">the relative path to place you want to save file</param> /// <returns>The path of file after upload to server</returns> public string UploadFile(object sender, string relativePath) { FileUploadField obj = (FileUploadField)sender; HttpPostedFile file = obj.PostedFile; DirectoryInfo dir = new DirectoryInfo(Server.MapPath(relativePath)); // save file to directory HoSoNhanSu/File // if directory not exist then create this if (dir.Exists == false) { dir.Create(); } string rdstr = SoftCore.Util.GetInstance().GetRandomString(7); string path = Server.MapPath(relativePath) + "/" + rdstr + "_" + obj.FileName; if (File.Exists(path)) { return(""); } FileInfo info = new FileInfo(path); file.SaveAs(path); return(relativePath + "/" + rdstr + "_" + obj.FileName); }
public ActionResult Save() { FileUploadField upload = this.GetCmp <FileUploadField>("Userimage"); BasicModel data = new BasicModel(); data.UserImageFile = upload.PostedFile; if (upload.HasFile) { data.UserImage = string.Format("~/Images/{0}/{1}{2}", "HR", Guid.NewGuid().ToString(), Path.GetExtension(data.UserImageFile.FileName)); data.UserImageSavePath = Server.MapPath(data.UserImage); data.UserImageFileType = data.UserImageFile.ContentType; } if (data.UserImageSavePath != null && Path.GetDirectoryName(data.UserImageSavePath) != null) { if (Directory.Exists(Path.GetDirectoryName(data.UserImageSavePath)) == false) { Directory.CreateDirectory(Path.GetDirectoryName(data.UserImageSavePath)); } data.UserImageFile.SaveAs(data.UserImageSavePath); } var s = X.GetCmp <Image>("UserImage"); s.ImageUrl = data.UserImage; s.ReRender(); var s1 = X.GetCmp <TextField>("p"); s1.Text = data.UserImage; return(this.Direct()); }
// // GET: /finance/PaymentApply/Create public ActionResult Create(PaymentApply pay) { FileUtility attachFile = new FileUtility(); FileUploadField upload = this.GetCmp <FileUploadField>("AnnetPath"); if (upload.HasFile) { attachFile.File = upload.PostedFile; pay.AnnetPath = string.Format("~/AttachFile/PaymentApply/{0}/{1}.{2}", DateTime.Now.Date.ToString("yyyy-MM-dd"), Guid.NewGuid(), Path.GetExtension(attachFile.File.FileName)); attachFile.FilePath = pay.AnnetPath; attachFile.SavePath = Server.MapPath(attachFile.FilePath); attachFile.FileType = attachFile.File.ContentType; } if (pay.CreatePaymentApply(this, attachFile)) { X.Msg.Alert("页面消息", "保存成功!", "parent.App.storedata.reload();parent.App.win.close();").Show(); } else { X.Msg.Alert("页面消息", "保存失败,请确保输入信息正确!").Show(); } return(this.Direct()); }
//Traitement Requete public int SaveFile(HttpRequest _Request, FileUploadField FileUpload1) { int retourSave = -1; for (int i = 0; i < _Request.Form.Count; i++) { if (_Request.Form.GetKey(i) == "pwd") { FormData.Add(_Request.Form.GetKey(i), Hash(_Request.Form.Get(i))); } else { FormData.Add(_Request.Form.GetKey(i), _Request.Form.Get(i)); } } FormData.Add("actif", "1"); //actif=1 FormData.Add("date_modif", DateTime.Now.ToString()); //date-modif= date système if (_TableModule == "client") { FormData.Add("revendeurid", this.getCurrentUser().getRevendeurId().ToString()); } else { if (issetClientid) { FormData.Add("clientid", this.getCurrentUser().getClientId().ToString()); } } Boolean fileOK = false; string filename = null; String path = Server.MapPath("~/Ressources/Images/imagesupload/"); for (int i = 0; i < _Request.Files.Count; i++) { if (FileUpload1.HasFile) { String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" }; for (int ii = 0; ii < allowedExtensions.Length; ii++) { if (fileExtension == allowedExtensions[ii] && FileUpload1.PostedFile.ContentLength < 1048576) { fileOK = true; filename = Guid.NewGuid().ToString() + ((DateTime.Now.ToString().Replace(":", "")).Replace("/", "")).Replace(" ", "") + fileExtension; FormData.Add(_Request.Files.GetKey(i), filename); } } } } string colonnes = ""; string valeurs = ""; string ChaineUpdate = ""; for (int i = 0; i < FormData.Count; i++) { string ligne = FormData.ElementAt(i).Key; for (int j = 0; j < this.ShemaTable.Count; j++) { string lignedb = this.ShemaTable.ElementAt(j).Key; if (lignedb.ToLower().Trim() == ligne.ToLower().Trim()) { if (i != 0) { colonnes += lignedb.ToLower().Trim() + ","; valeurs += "'" + FormData.ElementAt(i).Value + "',"; ChaineUpdate += FormData.ElementAt(i).Key.Trim() + "='" + FormData.ElementAt(i).Value + "',"; } } } } colonnes = colonnes.Substring(0, colonnes.Length - 1); valeurs = valeurs.Substring(0, valeurs.Length - 1); ChaineUpdate = ChaineUpdate.Substring(0, ChaineUpdate.Length - 1); string _ValIdTable = FormData.ElementAt(0).Value; if (_ValIdTable == "" && GeHabilitationAction("ajouter")) { string _req = "insert into " + this._TableModule + " (" + colonnes + ") values (" + valeurs + ") SELECT IDENT_CURRENT('" + this._TableModule + "')"; retourSave = this.InsertRetourId(_req); if (retourSave != -1) { if (fileOK) { try { for (int i = 0; i < _Request.Files.Count; i++) { FileUpload1.PostedFile.SaveAs(path + filename); } } catch (Exception ex) { ex.ToString(); } } } } else if (_ValIdTable != "0" && GeHabilitationAction("modifier")) { string _recupereancienlogo = "SELECT " + _Request.Files.GetKey(0) + " from " + this._TableModule + " where " + _Request.Form.GetKey(0) + "=" + _ValIdTable; SqlDataReader resulat = this.Select(_recupereancienlogo); resulat.Read(); string ancienlogo = resulat[0].ToString(); resulat.Close(); if (_TableModule == "client") { string _req = "update " + this._TableModule + " set " + ChaineUpdate + " where " + FormData.ElementAt(0).Key + "=" + _ValIdTable + " and revendeurid=" + this.getCurrentUser().getRevendeurId().ToString(); retourSave = this.Update(_req); } else { if (issetClientid) { string _req = "update " + this._TableModule + " set " + ChaineUpdate + " where " + FormData.ElementAt(0).Key + "=" + _ValIdTable + " and clientid=" + this.getCurrentUser().getClientId().ToString(); retourSave = this.Update(_req); } else if (!issetClientid) { string _req = "update " + this._TableModule + " set " + ChaineUpdate + " where " + FormData.ElementAt(0).Key + "=" + _ValIdTable; retourSave = this.Update(_req); } else { } } if (retourSave != 0) { retourSave = int.Parse(_ValIdTable); } if (retourSave != -1 && retourSave != 0) { for (int i = 0; i < _Request.Files.Count; i++) { try { FileUpload1.PostedFile.SaveAs(path + filename); System.IO.File.Delete(path + ancienlogo); } catch (Exception ex) { ex.ToString(); } } } } else { } return(retourSave); }
public bool UploadFile(FileUploadField fuTransHand, string sFileName) { fuHand = fuTransHand; return(upFile(sFileName)); }
public static Objeler.Tanimlar.Messages DosyaGonder(FileUploadField FUF, string P) { Objeler.Tanimlar.Messages M = new Objeler.Tanimlar.Messages(); HttpPostedFile GelenDosya = FUF.PostedFile; string GelenUzanti = GelenDosya.FileName.Split(new Char[] { '.' })[GelenDosya.FileName.Split(new Char[] { '.' }).Length - 1]; //string dosya_adi = GelenDosya.FileName.Substring(0, GelenDosya.FileName.Length - GelenUzanti.Length - 1); //string mime_type = GelenDosya.ContentType; int GelenDosyaBoyutu = GelenDosya.ContentLength; string TamDosyaYolu = P + Class.Fonksiyonlar.Genel.StringIslemleri(Class.Sabitler.StringIslemleri.StringIslemTipleri.StringTemizle, GelenDosya.FileName); #region Resim Uzantıları List <string> Uzantilar = new List <string>(); string[] T = Class.Degiskenler.Site.ResimUzantilari.Split(','); foreach (string i in T) { Uzantilar.Add(i.Replace("*.", "")); } #endregion if (GelenDosyaBoyutu > 1) { if (Uzantilar.Contains(GelenUzanti)) { if (GelenDosyaBoyutu < 2201600) { if (!File.Exists(TamDosyaYolu)) { try { byte[] B = new byte[GelenDosyaBoyutu]; GelenDosya.InputStream.Read(B, 0, GelenDosyaBoyutu); Class.Fonksiyonlar.Genel.DosyaKaydet(B, TamDosyaYolu); #region Mesaj Döndür M.Type = Class.Sabitler.MessageTypes.OK; #endregion } catch (Exception ex) { #region Mesaj Döndür M.Type = Class.Sabitler.MessageTypes.ERROR; M.Header = "Bir iç hata Oluştu"; M.Text = ex.Message; #endregion } } else { #region Mesaj Döndür M.Type = Class.Sabitler.MessageTypes.ERROR; M.Header = "Hata Oluştu"; M.Text = "Bu isimde bir dosya zaten var!<br/>Lütfen ilgili dosyanın adını değiştirerek yeniden deneyiniz."; #endregion } } else { #region Mesaj Döndür M.Type = Class.Sabitler.MessageTypes.ERROR; M.Header = "Hata Oluştu"; M.Text = "Dosya GelenDosyaBoyutuu 2 MB den fazla olamaz.<br/>Lütfen yeniden deneyiniz."; #endregion } } else { #region Mesaj Döndür M.Type = Class.Sabitler.MessageTypes.ERROR; M.Header = "Hata Oluştu"; M.Text = "Yalnızca " + Class.Degiskenler.Site.ResimUzantilari.ToString().Replace("*.", " ") + " gibi resim dosyalarını yükleyebilirsiniz.<br/>Lütfen yeniden deneyiniz."; #endregion } } else { #region Mesaj Döndür M.Type = Class.Sabitler.MessageTypes.ERROR; M.Header = "Hata Oluştu"; M.Text = "İlgili dosya yüklenemedi!<br/>Lütfen yeniden deneyiniz."; #endregion } return(M); }
public ActionResult AddOrEditCertificate(V_HR_Certificate re) { FileUploadField upload = this.GetCmp <FileUploadField>("Userimage"); HttpPostedFile UserImageFile; string UserImage = "", UserImageSavePath = "", UserImageFileType, path = ""; UserImageFile = upload.PostedFile; if (UserImageFile.ContentLength <= 20971520) { DirectResult r = new DirectResult(); T_HR_Certificate reupdate = entities.T_HR_Certificate.Find(re.ID); if (upload.HasFile) { UserImage = string.Format("~/AttachFile/HR/Certificate/{0}/{1}{2}", re.StaffID, Guid.NewGuid().ToString(), Path.GetExtension(UserImageFile.FileName)); UserImageSavePath = Server.MapPath(UserImage); UserImageFileType = UserImageFile.ContentType; } if (UserImageSavePath != "" && Path.GetDirectoryName(UserImageSavePath) != null) { if (Directory.Exists(Path.GetDirectoryName(UserImageSavePath)) == false) { Directory.CreateDirectory(Path.GetDirectoryName(UserImageSavePath)); } UserImageFile.SaveAs(UserImageSavePath); } if (reupdate == null)//为空为添加 { T_HR_Certificate readd = new T_HR_Certificate(); readd.ID = Guid.NewGuid().ToString(); readd.StaffID = re.StaffID; readd.CertificateName = re.CertificateName; readd.CertificateNum = re.CertificateNum; readd.Startdate = re.Startdate; readd.Deadline = re.Deadline; readd.State = re.State; if (UserImage != "") { readd.CerImage = UserImage; } readd.Remark = re.Remark; readd.Valid = true; readd.CreaterName = new LoginUser().EmployeeId; readd.CreateTime = DateTime.Now; entities.T_HR_Certificate.Add(readd); try { entities.SaveChanges(); r.Success = true; X.Msg.Alert("提示", "保存成功!", new JFunction { Fn = "closewindow" }).Show(); } catch (Exception e) { X.Msg.Alert("警告", "数据保存失败!<br /> note:" + e.Message, new JFunction { Fn = "closewindow" }).Show(); r.Success = false; } } else//否则为修改 { reupdate.StaffID = re.StaffID; reupdate.CertificateName = re.CertificateName; reupdate.CertificateNum = re.CertificateNum; reupdate.Startdate = re.Startdate; reupdate.Deadline = re.Deadline; reupdate.State = re.State; if (UserImage != "") { if (reupdate.CerImage != null) { path = Server.MapPath(reupdate.CerImage); } if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } reupdate.CerImage = UserImage; } reupdate.Remark = re.Remark; reupdate.Valid = true; reupdate.EditorName = new LoginUser().EmployeeId; reupdate.EditeTime = DateTime.Now; try { entities.SaveChanges(); r.Success = true; X.Msg.Alert("提示", "保存成功!", new JFunction { Fn = "closewindow" }).Show(); } catch (Exception e) { X.Msg.Alert("警告", "数据保存失败!<br /> note:" + e.Message, new JFunction { Fn = "closewindow" }).Show(); r.Success = false; } } return(r); } else { X.Msg.Alert("警告", "图片需要小于20M!").Show(); return(this.Direct()); } }