protected void btnSave_Click(object sender, EventArgs e) { if (!(String.IsNullOrEmpty(editor1.Text) || String.IsNullOrEmpty(title.Text) || String.IsNullOrEmpty(Abstract.Text) || String.IsNullOrEmpty(Tags.Text) || String.IsNullOrEmpty(KeyWords.Text) || SelectedSubGroups.Items.Count == 0 || Abstract.Text.Count() < 130)) { if (Session["ProjectIDForEdit"] != null) { int id = Session["ProjectIDForEdit"].ToString().ToInt(); //Session.Remove("newProjectIDForEdit"); ProjectsRepository repArt = new ProjectsRepository(); GroupsRepository repo = new GroupsRepository(); Project art = repArt.FindeProjectByID(id); art.Title = title.Text; art.Content = editor1.Text; if (FileUpload1.HasFile) { if (FileUpload1.FileBytes.Length > 1024 * 1024) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حجم فایل بارگذاری شده بیشتر از 1 مگابایت است!')", true); return; } string ext = Path.GetExtension(FileUpload1.FileName).ToLower(); if ((ext != ".jpg") && (ext != ".png")) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('فرمت فایل بارگذاری شده باید .jpg یا .png باشد!')", true); return; } string filename = Path.GetFileName(FileUpload1.FileName); string rand = DBManager.CurrentTimeWithoutColons() + DBManager.CurrentPersianDateWithoutSlash(); filename = rand + filename; string ps = Server.MapPath(@"~\img\") + filename; FileUpload1.SaveAs(ps); FileStream fStream = File.OpenRead(ps); byte[] contents = new byte[fStream.Length]; fStream.Read(contents, 0, (int)fStream.Length); fStream.Close(); FileInfo fi = new FileInfo(Server.MapPath(@"~\img\") + art.Image.Substring(5)); fi.Delete(); FileInfo fil = new FileInfo(Server.MapPath(@"~\img\") + art.ImgFisrtPage.Substring(5)); fil.Delete(); art.Image = "/img/" + filename; System.Drawing.Image img = imgResize.ToImage(contents); System.Drawing.Image image = imgResize.Resize(img, 466, 466); string stream = Server.MapPath(@"~\img\") + "s" + filename; switch (FileUpload1.FileName.Substring(FileUpload1.FileName.IndexOf('.') + 1).ToLower()) { case "jpg": image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); break; case "jpeg": image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); break; case "png": image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); break; } art.ImgFisrtPage = "/img/" + "s" + filename; } art.Abstract = Abstract.Text; art.Tags = Tags.Text; art.KeyWords = KeyWords.Text; ProjectConRepository pcr = new ProjectConRepository(); pcr.deleteByProjectID(Session["ProjectIDForEdit"].ToString().ToInt()); ProjectsRepository ARTRep = new ProjectsRepository(); if (ARTRep.SaveProject(art)) { bool result = true; ProjectConRepository GRConRepo = new ProjectConRepository(); GRConRepo.DeletProjectConnections(id); List <int> SelectedSubGroupsList = new List <int>(); int lastid = id; int count = SelectedSubGroups.Items.Count; if (count > 0) { for (int i = 0; i < count; i++) { ProjectConnection GC = new ProjectConnection(); GC.ProjectID = lastid; GC.GroupID = SelectedSubGroups.Items[i].Value.ToInt(); if (!GRConRepo.SaveProjectCon(GC)) { result = false; } } Session.Add("ProjectLastIDForEmployeeFilterEdit", id); Response.Redirect("AddProject/AddEmployeeToProjectEdit"); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('هیچ زیر گروهی انتخاب نشده است!')", true); } if (!result) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ثبت به وجود آمد،لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید ! ');window.location ='/Admin/ManageProjects'", true); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ثبت با موفقیت انجام شد!');window.location ='/Admin/ManageBlogs'", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ثبت به وجود آمد،لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید ! ');window.location ='/Admin/ManageProjects'", true); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' مشکلی در زمان لود کردن به وجود آمد دوباره سعی کنید ! ');window.location ='/Admin/ManageProjects'", true); } } }
protected void btnSave_Click(object sender, EventArgs e) { if ((String.IsNullOrEmpty(editor1.Text) == false) && (Abstract.Text.Length >= 130) && (FileUpload1.HasFile) && (String.IsNullOrEmpty(title.Text) == false) && (String.IsNullOrEmpty(Abstract.Text) == false) && (String.IsNullOrEmpty(Tags.Text) == false) && (String.IsNullOrEmpty(KeyWords.Text) == false)) { if (FileUpload1.FileBytes.Length > 1024 * 1024) { diverror.InnerHtml = "حجم فایل بارگذاری شده بیشتر از 1 مگابایت است!"; return; } string ext = Path.GetExtension(FileUpload1.FileName).ToLower(); if ((ext != ".jpg") && (ext != ".png")) { diverror.InnerHtml = "فرمت فایل بارگذاری شده باید .jpg یا .png باشد!"; return; } Project ART = new Project(); ART.Title = title.Text; ART.Content = editor1.Text; string filename = Path.GetFileName(FileUpload1.FileName); string rand = DBManager.CurrentTimeWithoutColons() + DBManager.CurrentPersianDateWithoutSlash(); filename = rand + filename; string ps = Server.MapPath(@"~\img\") + filename; FileUpload1.SaveAs(ps); FileStream fStream = File.OpenRead(ps); byte[] contents = new byte[fStream.Length]; fStream.Read(contents, 0, (int)fStream.Length); fStream.Close(); ART.Image = "/img/" + filename; System.Drawing.Image img = imgResize.ToImage(contents); System.Drawing.Image image = imgResize.Resize(img, 466, 466); string stream = Server.MapPath(@"~\img\") + "s" + filename; switch (FileUpload1.FileName.Substring(FileUpload1.FileName.IndexOf('.') + 1).ToLower()) { case "jpg": image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); break; case "jpeg": image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); break; case "png": image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); break; } ART.ImgFisrtPage = "/img/" + "s" + filename; ART.Abstract = Abstract.Text; ART.PostDateTime = OnlineTools.persianFormatedDate(); ART.Tags = Tags.Text; ART.KeyWords = KeyWords.Text; ProjectsRepository ARTRep = new ProjectsRepository(); if (ARTRep.SaveProject(ART)) { bool result = true; ProjectConRepository GRConRepo = new ProjectConRepository(); List <int> SelectedSubGroupsList = new List <int>(); int c = Ids.Count(); int lastid = ARTRep.GetLastProjectID(); Session.Add("ProjectLastIDForEmployeeFilter", lastid); if (c > 0) { for (int i = 0; i < c; i++) { ProjectConnection GC = new ProjectConnection(); GC.ProjectID = lastid; GC.GroupID = Ids[i]; if (!GRConRepo.SaveProjectCon(GC)) { result = false; } } } else { diverror.InnerText = "هیچ زیر گروهی انتخاب نشده است!"; } if (!result) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ثبت به وجود آمد،لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید ! ');window.location ='/Admin/ManageProjects'", true); } else { Response.Redirect("/Admin/AddProject/AddEmployeeToProject"); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ثبت به وجود آمد،لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید ! ');window.location ='/Admin/ManageProjects'", true); } } }
protected void gvPosts_RowCommand(object sender, GridViewCommandEventArgs e) { diverror.InnerHtml = ""; if (e.CommandName == "Edit") { // Retrieve the row index stored in the // CommandArgument property. int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button // from the Rows collection. GridViewRow row = gvPosts.Rows[index]; Session.Add("ProjectIDForEdit", row.Cells[0].Text); Response.Redirect("/Admin/EditProject");//edit } if (e.CommandName == "Show") { // Retrieve the row index stored in the // CommandArgument property. int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button // from the Rows collection. GridViewRow row = gvPosts.Rows[index]; string id = row.Cells[0].Text; Response.Redirect("/Projects/" + id + "/" + row.Cells[1].Text.Replace(' ', '-'));//show } if (e.CommandName == "Delet") { // Retrieve the row index stored in the // CommandArgument property. int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button // from the Rows collection. GridViewRow row = gvPosts.Rows[index]; int id = row.Cells[0].Text.ToInt(); ProjectsRepository repart = new ProjectsRepository(); ProjectConRepository repgpCon = new ProjectConRepository(); string img = ""; string fimg = ""; Project pr = repart.FindeProjectByID(id); if (pr != null) { img = pr.Image; fimg = pr.ImgFisrtPage; } if (repgpCon.DeletProjectConnections(id) && repart.DeletProjectByID(id)) { subgroup(); FileInfo fi = new FileInfo(Server.MapPath(@"~\img\") + img.Substring(5)); fi.Delete(); FileInfo fil = new FileInfo(Server.MapPath(@"~\img\") + fimg.Substring(5)); fil.Delete(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با موفقیت انجام شد ');", true); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با خطا مواجه شد ، بعدا سعی کنید یا با پشتیبانی تماس بگیرید!');", true); } } }