public void ProcessRequest(HttpContext context) { if (context.Request.Files.Count > 0) { HttpFileCollection files = context.Request.Files; try { HttpPostedFile file = files[0]; if (file.ContentLength > 1000 * 1024 * 1024) { context.Response.Write(" سایز فایل باید کمتر از 50 مگابایت باشد !"); } else { string FilePath = context.Request.QueryString["FilePath"].ToString(); string Title = context.Request.QueryString["Title"].ToString(); string Description = context.Request.QueryString["Description"].ToString(); string UploadFileName = context.Request.QueryString["UploadFileName"].ToString(); string Order = context.Request.QueryString["Order"].ToString(); string IDRet = context.Request.QueryString["IDRet"].ToString(); string IdUser = context.Request.QueryString["IdUser"].ToString(); string IDAttachInterfaceCategory = context.Request.QueryString["IDAttachInterfaceCategory"].ToString(); string IDAttachSite = context.Request.QueryString["IDAttachSite"].ToString(); string FileType = Path.GetExtension(file.FileName).ToLower(); string FileName = IDAttachSite.ToString() + FileType; ViewModel.tblAttachSite AddAttachSite = new ViewModel.tblAttachSite(); AddAttachSite.IDAttachSite = IDAttachSite.StringToGuid(); AddAttachSite.IDRet = IDRet.StringToGuid(); AddAttachSite.IDUser = IdUser.StringToGuid(); AddAttachSite.Name_Fa = Title; AddAttachSite.Description_Fa = Description; AddAttachSite.Url = FilePath + FileName; AddAttachSite.FileType = FileType; AddAttachSite.FileName = UploadFileName.Replace(FileType, ""); AddAttachSite.Order = Order.StringToInt(); AddAttachSite.IDAttachInterfaceCategory = IDAttachInterfaceCategory.StringToGuid(); AddAttachSite.Status = 1; bool ret = BisAttachSiteMethod.AddAttachSite(AddAttachSite); if (ret) { FilePath = context.Server.MapPath(@"\" + FilePath); file.SaveAs(FilePath + FileName); context.Response.Write("فایل مورد نظر آپلود شد!"); } else { context.Response.Write("خطا در آپلود!"); } } } catch { context.Response.Write("خطا!فایل مورد نظر آپلود نشد"); } } }
public bool UpdateAttachSite(ViewModel.tblAttachSite AttachSite) { return(sqlHelper.RunProcedure("sp_tblAttachSite_Update", AttachSite, true) > 0); }
public bool AddAttachSite(ViewModel.tblAttachSite AttachSite) { return(sqlHelper.RunProcedure("sp_tblAttachSite_Insert", AttachSite, true) > 0); }
protected void btnAddAttachSite_Click(object sender, EventArgs e) { if (txtTitle.Text == "") { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "er1", " bootbox.alert({message: \"<p dir='rtl' style='color:#004179;font-size:17px;'>لطفا نام فایل را وارد کنید!</p>\",title: \"<p style='text-align:right;direction:rtl'>خطا</p>\"});", true); return; } switch (hfModeAttachSite.Value) { case "New": try { bool check = checkAccess(EventName.ListofEvents.AddAttchForProduct.ToString()); if (!check) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "ErrorMessage", "alert('شما به این رویداد اجازه دسترسی ندارید!');", true); return; } if (hfFilelName.Value == "") { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "er1", " bootbox.alert({message: \"<p dir='rtl' style='color:#004179;font-size:17px;'>لطفا فایل مورد نظر را انتخاب کنید!</p>\",title: \"<p style='text-align:right;direction:rtl'>خطا</p>\"});", true); return; } string Prefix = hfFilelName.Value.Substring(hfFilelName.Value.IndexOf('.'), hfFilelName.Value.Length - hfFilelName.Value.IndexOf('.')); if (Prefix == ".doc" || Prefix == ".docx" || Prefix == ".txt" || Prefix == ".pdf" || Prefix == ".rar" || Prefix == ".zip" || Prefix == ".jpg" || Prefix == ".png" || Prefix == ".gif" || Prefix == ".mp4") { hfNewIDAttachSite.Value = Guid.NewGuid().ToString(); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "UploadFiles1", hfControlIDAttachSite.Value + "UploadFiles('" + fileUploadAttachSite.ClientID + "','File/AttachSite/','" + ((DataSet)Session["User"]).ReturnDataSetField("IDUser") + "');", true); // jahate file grid event btnJustCallForEvent_Click seda zade mishavad fillgrdAttachSite(); ///agar hfSituation = single bashad 1 file uplaod mikonad va modal ra mibandad if (hfSituation.Value.ToLower() == "single") { this.Page.GetType().InvokeMember("ChangeAfterUpload", System.Reflection.BindingFlags.InvokeMethod, null, this.Page, new object[] { hfNewIDAttachSite.Value.StringToGuid(), "File/AttachSite/" + hfNewIDAttachSite.Value.StringToGuid() + Prefix, Prefix, txtTitle.Text, }); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "HideModalAttachSite", "$('#" + ModalAttachSite.ClientID + "').modal('hide');", true); } } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "er2", " bootbox.alert({message: \"<p dir='rtl' style='color:#004179;font-size:17px;'>فایل انتخابی در فرمت مجاز نمی باشد!</p>\",title: \"<p style='text-align:right;direction:rtl'>خطا</p>\"});", true); } } catch { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "er3", " bootbox.alert({message: \"<p dir='rtl' style='color:#004179;font-size:17px;'>اشکال در برقراری ارتباط با دیتابیس!</p>\",title: \"<p style='text-align:right;direction:rtl'>خطا</p>\"});", true); } break; case "Edit": try { bool check = checkAccess(EventName.ListofEvents.EditAttchForProduct.ToString()); if (!check) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "ErrorMessage", "alert('شما به این رویداد اجازه دسترسی ندارید!');", true); return; } ViewModel.tblAttachSite update = new ViewModel.tblAttachSite(); update.IDAttachCrmInterface = hfIDAttachCrmInterface.Value.StringToGuid(); update.Name_Fa = txtTitle.Text.FixFarsi(); update.Description_Fa = txtDescription.Text.FixFarsi(); update.Order = txtOrder.Text.StringToInt(); update.CreateDate = DateTime.Now; update.IDAttachInterfaceCategory = drpAttachInterfaceCategory.SelectedValue.StringToGuid(); bool ret = bisAttachSiteMethod.UpdateAttachSite(update); if (ret) { fillGrdAttachCrmInterface(hfIDRet.Value, hfPartName.Value); fillgrdAttachSite(); NewFiledsAttachSite(); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "er3", " bootbox.alert({message: \"<p dir='rtl' style='color:#004179;font-size:17px;'>ویرایش با موفقیت انجام شد!</p>\",title: \"<p style='text-align:right;direction:rtl'>ویرایش اطلاعات</p>\"});", true); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "er3", " bootbox.alert({message: \"<p dir='rtl' style='color:#004179;font-size:17px;'>اشکال در ویرایش!</p>\",title: \"<p style='text-align:right;direction:rtl'>خطا</p>\"});", true); } } catch { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "er3", " bootbox.alert({message: \"<p dir='rtl' style='color:#004179;font-size:17px;'>اشکال در برقراری ارتباط با دیتابیس!</p>\",title: \"<p style='text-align:right;direction:rtl'>خطا</p>\"});", true); } break; } }