protected void ButtonSubmit_Click(object sender, EventArgs e) { if (Validation()) { string id = Session["ArtID"].ToString(); Article art = new Article(); art = art.GetArticleById(id); String title = TextboxTitle.Text.ToString(); String description = TextboxDescription.Text.ToString(); var dateAndTime = DateTime.Now; String lastupdated = dateAndTime.ToShortDateString(); String link = TextboxLink.Text.ToString(); String image = ""; if (UploadImage.HasFile) { string filename = Path.GetFileName(UploadImage.FileName); UploadImage.SaveAs(Server.MapPath("img/articleImages/") + filename); image = ("img/articleImages/" + filename); } else { image = art.Image; } //Get Article art = art.GetArticleById(id); int insCnt = art.UpdateArticle(id, title, description, image, link, lastupdated); Response.Redirect("LearnAdmin.aspx"); } }
protected void btn_Click(object sender, EventArgs e) { if (!Directory.Exists(Server.MapPath("Images"))) { Directory.CreateDirectory(Server.MapPath("Images")); } string imageurl = (Server.MapPath("Images") + "\\" + UploadImage.FileName); UploadImage.SaveAs(imageurl); }
protected void ButtonSubmit_Click(object sender, EventArgs e) { string imagePath = "~/images/" + UploadImage.FileName; UploadImage.SaveAs(Server.MapPath(imagePath).ToString()); SqlCommand cmd = new SqlCommand("insert into restaurantProfile(restaurantName,restaurantContactNo,restaurantEmail,restaurantAddress,restaurantOpeningTime,restaurantClosingTime,restaurantCapacity,restaurantDescription,restaurantAdminAccountID,restaurantDP)values('" + TextBoxName.Text + "','" + TextBoxContact.Text + "','" + TextBoxEmail.Text + "','" + TextBoxAddress.Text + "','" + TextBoxOpeningTime.Text + "','" + TextBoxClosingTime.Text + "','" + TextBoxCapacity.Text + "','" + TextBoxBio.Text + "','" + Session["restaurantAdminID"] + "','" + imagePath + "')", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); }
protected void ButtonUpdate_Click(object sender, EventArgs e) { if (UploadImage.HasFile) { string imagePath = "~/images/" + UploadImage.FileName; UploadImage.SaveAs(Server.MapPath(imagePath).ToString()); SqlCommand cmd = new SqlCommand("UPDATE restaurantProfile SET restaurantName = '" + TextBoxName.Text + "',restaurantContactNo = '" + TextBoxContact.Text + "', restaurantEmail = '" + TextBoxEmail.Text + "' ,restaurantAddress = '" + TextBoxAddress.Text + "',restaurantOpeningTime = '" + TextBoxOpeningTime.Text + "',restaurantClosingTime = '" + TextBoxClosingTime.Text + "',restaurantCapacity = '" + TextBoxCapacity.Text + "',restaurantDescription = '" + TextBoxBio.Text + "',restaurantDP = '" + imagePath + "' WHERE restaurantAdminAccountID = " + Session["restaurantAdminID"], con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); BindData(); } }
protected void Btn_Click(object sender, EventArgs e) { if (!Directory.Exists(Server.MapPath("Images"))) { Directory.CreateDirectory(Server.MapPath("Images")); } string imageurl = (Server.MapPath("Images") + "\\" + UploadImage.FileName); string dppathimg = "~/Images/" + UploadImage.FileName; UploadImage.SaveAs(imageurl); SqlCommand command = new SqlCommand("insert ImageMaster (UserImage) values (@UserImage)", conn); command.Parameters.AddWithValue("@UserImage", dppathimg); conn.Open(); command.ExecuteNonQuery(); conn.Close(); }
protected void ButtonUpdate_Click(object sender, EventArgs e) { if (UploadImage.HasFile) { string imagePath = "~/images/" + UploadImage.FileName; UploadImage.SaveAs(Server.MapPath(imagePath).ToString()); SqlCommand cmd = new SqlCommand("UPDATE menuCategories SET categoryName = '" + TextBoxName.Text + "', categoryImage = '" + imagePath + "' WHERE menuCategoryID = " + Request.QueryString["ID"], con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); TextBoxName.Text = ""; imagePath = ""; } else { } }
protected void ButtonInsert_Click(object sender, EventArgs e) { if (UploadImage.HasFile) { string imagePath = "~/images/" + UploadImage.FileName; UploadImage.SaveAs(Server.MapPath(imagePath).ToString()); SqlCommand cmd = new SqlCommand("insert into menuCategories(categoryName,categoryImage,restaurantID) values('" + TextBoxCategoryName.Text + "','" + imagePath + "', '" + Session["restaurantID"] + "') ", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); TextBoxCategoryName.Text = ""; imagePath = ""; } else { } Response.Redirect("Menu_Categories.aspx"); }
protected void ButtonSaveBook_Click(object sender, EventArgs e) { if (UploadImage.HasFile) { if (UploadImage.PostedFile.ContentType.StartsWith("image/")) { UploadImage.SaveAs(Request.PhysicalApplicationPath + "Resimler\\" + UploadImage.FileName); SqlConnection Baglanti; SqlCommand Komut; string ConnectionString = ConfigurationManager.ConnectionStrings["ConfigurationStringApplication"].ConnectionString; Baglanti = new SqlConnection(ConnectionString); Komut = new SqlCommand("INSERT INTO Book (Name,Writer,ImgUrl,Status) VALUES (@Name,@Writer,@ImgUrl,@Status)", Baglanti); Komut.Parameters.Add("@Name", System.Data.SqlDbType.NVarChar); Komut.Parameters["@Name"].Value = txtBookName.Text; Komut.Parameters.Add("@Writer", System.Data.SqlDbType.NVarChar); Komut.Parameters["@Writer"].Value = txtBookAuthor.Text; Komut.Parameters.Add("@ImgUrl", System.Data.SqlDbType.NVarChar); Komut.Parameters["@ImgUrl"].Value = "Resimler\\" + UploadImage.FileName; Komut.Parameters.Add("@Status", System.Data.SqlDbType.Bit); Komut.Parameters["@Status"].Value = false; try { Baglanti.Open(); Komut.ExecuteNonQuery(); } catch (Exception ex) { LabelCatch.Visible = true; LabelCatch.Text += ex.Message.ToString(); } finally { Baglanti.Close(); LabelAdding.Visible = true; } } else { divAdding.Visible = false; divWrongWithThis.Visible = true; } } }
protected void btnUpload_Click(object sender, EventArgs e) { string qryInsert = string.Empty; Page.Validate("VC"); if (!Page.IsValid) { return; } if (!FileUploadEng.HasFile) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Failure", "alert('Please Select File !!!!')", true); return; } try { if (isValidFile() && isValidImageAttachmentFile(UploadImage)) { string Filepath = Server.MapPath("../../Site/Upload/Pdf/"); FileUploadEng.SaveAs(Filepath + FileUploadEng.FileName); if (FileUploadMar.HasFile) { FileUploadMar.SaveAs(Filepath + FileUploadMar.FileName); } if (FileUploadUr.HasFile) { FileUploadUr.SaveAs(Filepath + FileUploadUr.FileName); } string imagefilepath = Server.MapPath("../../Site/Upload/Images/"); UploadImage.SaveAs(imagefilepath + UploadImage.FileName); SaveTODB(); } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Failure", "alert('Please Select Valid PDF/Image File For Upload !!!!')", true); } return; } catch (Exception ex) { throw ex; } finally { ClearControls(); } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { if (Validation()) { String title = TextboxTitle.Text.ToString(); int views = 0; int likes = 0; int comments = 0; String description = TextboxDescription.Text.ToString(); String image = ""; var dateAndTime = DateTime.Now; String lastupdated = dateAndTime.ToShortDateString(); String dateposted = dateAndTime.ToShortDateString(); String email = Session["email"].ToString(); Profiles prof = new Profiles(); prof = prof.GetProfileById(email); String author = prof.Fname.ToString(); String link = TextboxLink.Text.ToString(); Boolean deleted = false; if (UploadImage.HasFile) { string filename = Path.GetFileName(UploadImage.FileName); UploadImage.SaveAs(Server.MapPath("img/articleImages/") + filename); image = ("img/articleImages/" + filename); } else { image = "img/articleImages/DefaultImage.jpg"; } //Instantiate object Article art = new Article(title, views, likes, comments, description, image, dateposted, author, link, lastupdated, deleted); int insCnt = art.AddArticle(); Response.Redirect("LearnAdmin.aspx"); } }
protected void btnCreateSubCategory_Click(object sender, EventArgs e) { if (ddCategory.SelectedIndex > 0) { if (txtSubCategory.Text.Length > 0) { if (string.IsNullOrEmpty(Convert.ToString(ViewState["ID"]))) { try { string ImageFile = ""; if (UploadImage.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; thumbPath = thumbPath + ImageFile; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 250); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); imgPath = imgPath + ImageFile; UploadImage.SaveAs(MapPath(imgPath)); } string categoryid = Convert.ToString(ddCategory.SelectedValue); int success = 0; success = local_subcategory.AddSubCategory(categoryid, txtSubCategory.Text, txtDescription.Text, ImageFile, ImageFile); if (success != 0) { clear(); lblMessage.ForeColor = Color.Green; lblMessage.Text = "Sub Category Created Successfully"; BindSubCategory(); } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Sub Category Creation Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } else //Update subcategory { //string ImageFile; //if (UploadImage.HasFile) //{ // string imgPath = "~/Upload/images/"; // string thumbPath = "~/Upload/thumbnails/"; // ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); // ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; // thumbPath = thumbPath + ImageFile; // System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); // System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 250); // objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); // imgPath = imgPath + ImageFile; // UploadImage.SaveAs(MapPath(imgPath)); //} //else //{ // ImageFile = lblImage.Text; //} try { Int32 categoryid = Convert.ToInt32(ddCategory.SelectedValue); Int32 subcategoryid = Convert.ToInt32(ViewState["ID"]); int success = 0; success = local_subcategory.UpdateSubCategory(subcategoryid, txtSubCategory.Text, txtDescription.Text, categoryid); if (success != 0) { clear(); lblMessage.ForeColor = Color.Green; lblMessage.Text = "Sub Category Updated Successfully"; BindSubCategory(); ViewState["ID"] = null; lblImage.Text = ""; btnCreateSubCategory.Text = "Create Sub Category"; } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Sub Category Update Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Enter Sub Category Name"; } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Select Category Name"; } }
//private void BindFlavour() //{ // try // { // DataTable dt = new DataTable(); // dt = local_product.getFlavourname(); // if (dt.Rows.Count > 0) // { // ddFlavour.DataSource = dt; // ddFlavour.DataTextField = "FlavourName"; // ddFlavour.DataValueField = "FlavourID"; // ddFlavour.DataBind(); // ddFlavour.Items.Insert(0, "Select Flavour"); // } // } // catch // { } //} protected void btnAddProduct_Click(object sender, EventArgs e) { if (txtProductName.Text.Length > 0) { if (string.IsNullOrEmpty(Convert.ToString(ViewState["ID"]))) { try { if (UploadImage.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; string smallPath = "~/Upload/small/"; string ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; thumbPath = thumbPath + ImageFile; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); //System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 170); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); smallPath = smallPath + ImageFile; System.Drawing.Image objImage2 = ScaleImage2(bmpUploadedImage); objImage2.Save(Server.MapPath(smallPath), ImageFormat.Png); imgPath = imgPath + ImageFile; UploadImage.SaveAs(MapPath(imgPath)); string categoryid = Convert.ToString(ddCategory.SelectedValue); Int32 subcategoryid = 0; if (ddSubCategory.SelectedIndex > 0) { subcategoryid = Convert.ToInt32(ddSubCategory.SelectedValue); } string producturl = txtProducturl.Text; string producttitle = txtProductTitle.Text; string productkeywords = txtProductKeywords.Text; string productshortDes = txtProductShortDes.Text; string name = txtProductName.Text.Trim(); string variantnames = txtVariant.Text; string variantquantity = txtVariantquantity.Text; decimal price = Convert.ToDecimal(txtPrice.Text.Trim()); bool active; if (CheckBox1.Checked == true) { active = true; } else { active = false; } txtProductCode.Text = ""; if (txtProductName.Text != "")//SKU code { txtProductCode.Text = txtProductName.Text + " " + txtPrice.Text; } Int32 discount = 0; if (txtDiscount.Text.Length > 0) { discount = Convert.ToInt32(txtDiscount.Text.Trim()); } // Int32 quantity = Convert.ToInt32(txtQuantity.Text.Trim()); Int32 quantity = 0; string date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string brand = txtBrand.Text.Trim(); string shippingcharges = "0"; //Shipping Charges if (txtshippingcharges.Text.Length > 0) { shippingcharges = txtshippingcharges.Text.Trim(); } string weightlbl = "0"; //Weight if (txtProductCapacity.Text != "") { weightlbl = txtProductCapacity.Text.Trim(); } string flavour = ""; //Flavour int selectproduct = 1; if (rdOfferProduct.Checked == true) { selectproduct = 1; } else if (rdNewproduct.Checked == true) { selectproduct = 2; } else if (rdBestSeller.Checked == true) { selectproduct = 3; } else if (rdFeature.Checked == true) { selectproduct = 4; } string description = CKEditor1.Text; int success = 0; success = local_product.AddNewProduct(producturl, producttitle, productkeywords, productshortDes, name, variantnames, variantquantity, price, ImageFile, ImageFile, active, txtProductCode.Text, discount, date, subcategoryid, quantity, brand, shippingcharges, weightlbl, flavour, categoryid, selectproduct, description); if (success != 0) { clear(); lblMessage.ForeColor = Color.Green; lblMessage.Text = "Product Added Successfully"; ViewState["ID"] = null; } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Product Addition Failed"; } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Select Product Photo"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } else //Update Product { string ImageFile; if (UploadImage.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; string smsllPath = "~/Upload/small/"; ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; thumbPath = thumbPath + ImageFile; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); //System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 170); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); smsllPath = smsllPath + ImageFile; System.Drawing.Image objImage2 = ScaleImage2(bmpUploadedImage); objImage2.Save(Server.MapPath(smsllPath), ImageFormat.Png); imgPath = imgPath + ImageFile; UploadImage.SaveAs(MapPath(imgPath)); } else { ImageFile = lblImage.Text; } try { string productid = Request.QueryString["id"]; string producturl = txtProducturl.Text.Trim(); string producttitle = txtProductTitle.Text.Trim(); string productkeywords = txtProductKeywords.Text.Trim(); string productshortDes = txtProductShortDes.Text.Trim(); string name = txtProductName.Text.Trim(); string description = CKEditor1.Text; decimal price = Convert.ToDecimal(txtPrice.Text.Trim()); string variantnames = txtVariant.Text.Trim(); string variantquantity = txtVariantquantity.Text.Trim(); bool active; if (CheckBox1.Checked == true) { active = true; } else { active = false; } string productcode = ""; if (txtProductCode.Text != "")//SKU code { productcode = txtProductCode.Text.Trim(); } Int32 discount = 0; if (txtDiscount.Text.Length > 0) { discount = Convert.ToInt32(txtDiscount.Text.Trim()); } //Int32 quantity = Convert.ToInt32(txtQuantity.Text.Trim()); Int32 quantity = 0; string date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string categoryid = Convert.ToString(ddCategory.SelectedValue); Int32 subcategoryid = 0; if (ddSubCategory.SelectedIndex > 0) { subcategoryid = Convert.ToInt32(ddSubCategory.SelectedValue); } string brand = txtBrand.Text.Trim(); string shippingcharges = txtshippingcharges.Text.Trim(); string weightlbl = txtProductCapacity.Text.Trim(); //string flavour = ddFlavour.SelectedValue; string flavour = ""; int selectproduct = 1; if (rdOfferProduct.Checked == true) { selectproduct = 1; } else if (rdNewproduct.Checked == true) { selectproduct = 2; } else if (rdBestSeller.Checked == true) { selectproduct = 3; } else if (rdFeature.Checked == true) { selectproduct = 4; } int success = 0; success = local_product.UpdateNewProduct(productid, producturl, producttitle, productkeywords, productshortDes, name, description, price, variantnames, variantquantity, ImageFile, ImageFile, active, productcode, discount, date, quantity, brand, shippingcharges, weightlbl, flavour, subcategoryid, categoryid, selectproduct); if (success != 0) { clear(); ViewState["ID"] = null; btnAddProduct.Text = "Add Product"; lblMessage.ForeColor = Color.Green; lblMessage.Text = "Product Updated Successfully"; Response.Redirect("~/admin/EditProduct.aspx", false); } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Product Update Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Enter Product Name"; } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { ClassLibrary_PropertyManager.Model.mTenantContract contract = new ClassLibrary_PropertyManager.Model.mTenantContract(); int landlordId = Convert.ToInt32(Session["LandLordID"]); try { int success = 0; contract.TenantID = Convert.ToInt32(ddlTenant.SelectedValue); contract.UnitID = Convert.ToInt32(ddlUnit.SelectedValue); contract.LandLordID = landlordId; contract.TenantDeposit = Convert.ToDouble(txtDeposit.Value.Trim()); contract.TenantMonthlyRent = Convert.ToDouble(txtRent.Value.Trim()); contract.ContractStartDate = Convert.ToDateTime(txtStart.Value); contract.ContractEndDate = Convert.ToDateTime(txtEnd.Value); contract.ContractStatusID = txtStatus.Checked; if (UploadImage.HasFile) { fileName = contract.TenantID.ToString() + "-" + contract.UnitID + "-" + UploadImage.FileName.Trim(); if (File.Exists(Server.MapPath("/ContractImages" + fileName))) { File.Delete(Server.MapPath("/ContractImages" + fileName)); Console.WriteLine("File deleted."); } UploadImage.SaveAs(Server.MapPath("/ContractImages" + fileName)); //DispalyMenuPicture.ImageUrl = Global.gShowMenuPicturesFiles + fileName; } contract.AgreementDocoument = fileName; if (btnSubmit.Text != "Update") { success = ClassLibrary_PropertyManager.Controller.cTenantContract.AddNewContract(contract); ClassLibrary_PropertyManager.Controller.cUnit.UpdateUnitAvailability(Convert.ToInt32(ddlUnit.SelectedValue), false); divMsgSuccess.Visible = true; } else { contract.TenantContractID = Convert.ToInt32(Request.QueryString["id"]); success = ClassLibrary_PropertyManager.Controller.cTenantContract.UpdateTenantContract(contract); divMsgSuccess.Visible = true; } ddlTenant.SelectedIndex = 0; ddlUnit.SelectedIndex = 0; txtDeposit.Value = ""; txtRent.Value = ""; txtStart.Value = ""; txtEnd.Value = ""; txtStatus.Checked = false; } catch (Exception ioExp) { using (StreamWriter sw = new StreamWriter(Global.ErrorFilePath, true)) { // If file exists, text will be appended ; otherwise a new file will be created sw.Write(string.Format("Message: {0}<br />{1}StackTrace :{2}{1}Date :{3}{1}-----------------------------------------------------------------------------{1}", ioExp.Message, Environment.NewLine, ioExp.StackTrace, DateTime.Now.ToString())); } divMsgError.Visible = true; } finally { contract = null; } } }
protected void btnAddProduct_Click(object sender, EventArgs e) { if (txtProductName.Text.Length > 0) { if (string.IsNullOrEmpty(Convert.ToString(ViewState["ID"]))) { try { string categoryid = Convert.ToString(ddCategory.SelectedValue); Int32 subcategoryid = 0; Int32 subsubcategoryid = 0; if (ddSubCategory.SelectedIndex > 0) { subcategoryid = Convert.ToInt32(ddSubCategory.SelectedValue); if (ddSubSubCategory.SelectedIndex > 0) { subsubcategoryid = Convert.ToInt32(ddSubSubCategory.SelectedValue); } } string name = txtProductName.Text.Trim(); string price = txtprice.Text.Trim(); string ImageFile = ""; if (UploadImage.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); ImageFile = ImageFile.Replace(" ", "-"); ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; thumbPath = thumbPath + ImageFile; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); //System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 170); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); imgPath = imgPath + ImageFile; UploadImage.SaveAs(MapPath(imgPath)); } else { ImageFile = ""; ImageFile = ""; } string description = CKEditor1.Text; //string date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // string date = System.DateTime.Now.ToString("dd/mm/yyyy"); int success = 0; success = local_product.AddNewProduct(name, price, ImageFile, ImageFile, description, subcategoryid, subcategoryid, categoryid); if (success != 0) { clear(); lblMessage.ForeColor = Color.Green; lblMessage.Text = "Product Added Successfully"; ViewState["ID"] = null; } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Product Addition Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } else //Update Product { try { string productid = Request.QueryString["id"]; string name = txtProductName.Text.Trim(); string price = txtprice.Text.Trim(); string ImageFile; if (UploadImage.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); ImageFile = ImageFile.Replace(" ", "-"); ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; thumbPath = thumbPath + ImageFile; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); //System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 170); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); imgPath = imgPath + ImageFile; UploadImage.SaveAs(MapPath(imgPath)); } else { ImageFile = lblImage.Text; } string description = CKEditor1.Text; //string date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string categoryid = Convert.ToString(ddCategory.SelectedValue); Int32 subcategoryid = 0; if (ddSubCategory.SelectedIndex > 0) { subcategoryid = Convert.ToInt32(ddSubCategory.SelectedValue); } int success = 0; success = local_product.UpdateNewProduct(productid, name, price, ImageFile, ImageFile, description, subcategoryid, categoryid); if (success != 0) { clear(); ViewState["ID"] = null; btnAddProduct.Text = "Add Product"; lblMessage.ForeColor = Color.Green; lblMessage.Text = "Product Updated Successfully"; Response.Redirect("~/admin/EditProduct.aspx", false); } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Product Update Failed"; } } catch (Exception ex) { lblMessage.Text = ex.Message; } } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Enter Product Name"; } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { ClassLibrary_PropertyManager.Model.mUnit unit = new ClassLibrary_PropertyManager.Model.mUnit(); int landlordId = Convert.ToInt32(Session["LandLordID"]); try { int success = 0; unit.BuildingID = Convert.ToInt32(ddlBuildings.SelectedValue); unit.UnitType = ddlUnitTypes.SelectedItem.ToString(); unit.LandLordID = landlordId; unit.UnitPrice = Convert.ToDouble(txtPrice.Value.Trim()); unit.UnitNumber = txtUnitNumber.Value.Trim(); unit.FloorLevel = Convert.ToInt32(txtFloorLevel.Value.Trim()); unit.UnitSize = txtUnitSize.Value.Trim(); unit.UnitAddress = txtUnitAddress.Value.Trim(); unit.UnitCity = txtCity.Value.Trim(); unit.Description = txtDescription.Value; unit.Bedrooms = Convert.ToInt32(txtBedrooms.Value); unit.Kitchen = Convert.ToInt32(txtKitchen.Value); unit.Bathrooms = Convert.ToInt32(txtBathrooms.Value); unit.Available = txtAvailable.Checked; unit.Garage = txtGarage.Checked; unit.Furnishing = txtFurnsihing.Checked; if (UploadImage.HasFile) { fileName = unit.UnitNumber.ToString() + "-" + unit.UnitType + "-" + UploadImage.FileName.Trim(); if (File.Exists(Server.MapPath("/UnitImages/" + fileName))) { File.Delete(Server.MapPath("/UnitImages/" + fileName)); Console.WriteLine("File deleted."); } UploadImage.SaveAs(Server.MapPath("/UnitImages/" + fileName)); } unit.UnitPictures = fileName; Session["dtunits"] = unit; if (btnSubmit.Text != "Update") { success = ClassLibrary_PropertyManager.Controller.cUnit.AddUnit(unit); divMsgSuccess.Visible = true; } else { unit.UnitID = Convert.ToInt32(Request.QueryString["id"]); success = ClassLibrary_PropertyManager.Controller.cUnit.UpdateUnit(unit); divMsgSuccess.Visible = true; } ddlBuildings.SelectedIndex = 0; ddlUnitTypes.SelectedIndex = 0; txtPrice.Value = ""; txtUnitNumber.Value = ""; txtUnitAddress.Value = ""; txtFloorLevel.Value = ""; txtUnitSize.Value = ""; txtCity.Value = ""; txtDescription.Value = ""; txtDescription.Value = ""; txtBedrooms.Value = ""; txtBathrooms.Value = ""; txtKitchen.Value = ""; txtGarage.Checked = false; txtFurnsihing.Checked = false; txtAvailable.Checked = false; } catch (Exception ioExp) { using (StreamWriter sw = new StreamWriter(Global.ErrorFilePath, true)) { // If file exists, text will be appended ; otherwise a new file will be created sw.Write(string.Format("Message: {0}<br />{1}StackTrace :{2}{1}Date :{3}{1}-----------------------------------------------------------------------------{1}", ioExp.Message, Environment.NewLine, ioExp.StackTrace, DateTime.Now.ToString())); } divMsgError.Visible = true; } finally { unit = null; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { ClassLibrary_PropertyManager.Model.mEmployee employee = new ClassLibrary_PropertyManager.Model.mEmployee(); int landlordId = Convert.ToInt32(Session["LandLordID"]); try { int success = 0; employee.EmployeeName = txtName.Value.Trim(); employee.EmployeeType = ddlOccupation.SelectedItem.ToString(); employee.EmployeeEmail = txtEmail.Value.Trim(); employee.EmployeePassword = txtPassword.Value.Trim(); employee.LandLordID = landlordId; employee.BuildingID = Convert.ToInt32(ddlBuilding.SelectedValue); employee.EmployeePhone = txtPhone.Value.Trim(); employee.EmployeeStatus = txtStatus.Checked; if (UploadImage.HasFile) { fileName = employee.EmployeeName.ToString() + "-" + employee.EmployeeType + "-" + UploadImage.FileName.Trim(); if (File.Exists(Server.MapPath("/EmployeeImages/") + fileName)) { File.Delete(Server.MapPath("/EmployeeImages/") + fileName); Console.WriteLine("File deleted."); } UploadImage.SaveAs(Server.MapPath("/EmployeeImages/") + fileName); imgDisplayPicture.ImageUrl = "/EmployeeImages/" + fileName; } employee.EmployeePicture = fileName; if (btnSubmit.Text != "Update") { success = ClassLibrary_PropertyManager.Controller.cEmployee.AddNewEmployee(employee); divMsgSuccess.Visible = true; } else { employee.EmployeeID = Convert.ToInt32(Request.QueryString["id"]); success = ClassLibrary_PropertyManager.Controller.cEmployee.UpdateEmployee(employee); divMsgSuccess.Visible = true; } txtName.Value = ""; ddlOccupation.SelectedIndex = 0; ddlBuilding.SelectedIndex = 0; txtEmail.Value = ""; txtPassword.Value = ""; txtPhone.Value = ""; txtStatus.Checked = false; imgDisplayPicture.Visible = false; } catch (Exception ioExp) { using (StreamWriter sw = new StreamWriter(Global.ErrorFilePath, true)) { // If file exists, text will be appended ; otherwise a new file will be created sw.Write(string.Format("Message: {0}<br />{1}StackTrace :{2}{1}Date :{3}{1}-----------------------------------------------------------------------------{1}", ioExp.Message, Environment.NewLine, ioExp.StackTrace, DateTime.Now.ToString())); } divMsgError.Visible = true; } finally { employee = null; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { ClassLibrary_PropertyManager.Model.mBill Bill = new ClassLibrary_PropertyManager.Model.mBill(); int landlordId = Convert.ToInt32(Session["LandLordID"]); try { int success = 0; Bill.TenantID = Convert.ToInt32(ddlTenant.SelectedValue); Bill.LandLordID = landlordId; Bill.BillType = ddlBillType.SelectedValue; Bill.BillAmount = Convert.ToDouble(txtAmountDue.Value.Trim()); Bill.BillDueDate = Convert.ToDateTime(txtDueDate.Value); Bill.BillNotes = txtNotes.Text.Trim(); Bill.BillStatus = 0; // 0 - not paid , 1 - Paid if (ddlRecurrency.SelectedIndex == 0) { Bill.BillRecurrency = 30; } else if (ddlRecurrency.SelectedIndex == 1) { Bill.BillRecurrency = 90; } else if (ddlRecurrency.SelectedIndex == 2) { Bill.BillRecurrency = 180; } else if (ddlRecurrency.SelectedIndex == 3) { Bill.BillRecurrency = 360; } else { Bill.BillRecurrency = 0; } if (UploadImage.HasFile) { fileName = Bill.TenantID.ToString() + "-" + Bill.BillType + "-" + UploadImage.FileName.Trim(); if (File.Exists(Server.MapPath("/BillImages" + fileName))) { File.Delete(Server.MapPath("/BillImages" + fileName)); Console.WriteLine("File deleted."); } UploadImage.SaveAs(Server.MapPath("/BillImages" + fileName)); //DispalyMenuPicture.ImageUrl = Global.gShowMenuPicturesFiles + fileName; } Bill.BillAttatchment = fileName; if (btnSubmit.Text != "Update") { success = ClassLibrary_PropertyManager.Controller.cBill.AddNewBill(Bill); //ClassLibrary_PropertyManager.Controller.cUnit.UpdateUnitAvailability(Convert.ToInt32(ddlUnit.SelectedValue), false); divMsgSuccess.Visible = true; } else { Bill.BillID = Convert.ToInt32(Request.QueryString["id"]); //success = ClassLibrary_PropertyManager.Controller.cTenantContract.UpdateTenantContract(contract); divMsgSuccess.Visible = true; } ddlTenant.SelectedIndex = 0; ddlBillType.SelectedIndex = 0; ddlRecurrency.SelectedIndex = 0; txtAmountDue.Value = ""; txtDueDate.Value = ""; txtNotes.Text = ""; } catch (Exception ioExp) { using (StreamWriter sw = new StreamWriter(Global.ErrorFilePath, true)) { // If file exists, text will be appended ; otherwise a new file will be created sw.Write(string.Format("Message: {0}<br />{1}StackTrace :{2}{1}Date :{3}{1}-----------------------------------------------------------------------------{1}", ioExp.Message, Environment.NewLine, ioExp.StackTrace, DateTime.Now.ToString())); } divMsgError.Visible = true; } finally { Bill = null; } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { ClassLibrary_PropertyManager.Model.mInvoice invoice = new ClassLibrary_PropertyManager.Model.mInvoice(); int landlordId = Convert.ToInt32(Session["LandLordID"]); try { int success = 0; invoice.TenantID = Convert.ToInt32(lstTenant.SelectedValue); invoice.LandLordID = landlordId; invoice.InvoiceType = ddlBillType.SelectedValue.Trim(); invoice.InvoiceAmount = Convert.ToDouble(txtAmount.Value.Trim()); invoice.AmountPaid = 0; invoice.InvoiceNotes = txtNotes.Text.Trim(); invoice.InvoiceDueDate = Convert.ToDateTime(txtDueDate.Value); invoice.InvoiceReminder = txtStatus.Checked; invoice.InvoiceStatus = 0; if (UploadImage.HasFile) { fileName = invoice.InvoiceID.ToString() + "-" + invoice.InvoiceType + "-" + UploadImage.FileName.Trim(); if (File.Exists(Server.MapPath("/InvoiceImages/") + fileName)) { File.Delete(Server.MapPath("/InvoiceImages/") + fileName); Console.WriteLine("File deleted."); } UploadImage.SaveAs(Server.MapPath("/InvoiceImages/") + fileName); } invoice.InvoiceAttatchments = fileName; if (btnSubmit.Text != "Update") { success = ClassLibrary_PropertyManager.Controller.cInvoice.AddNewInvoice(invoice); if (success > 0 & txtStatus.Checked == true) { string[] strTenant = lstTenant.SelectedItem.Text.Split('-'); string TenantName = strTenant[0]; string strEmailMessage = clEmailTemplates.SendTenantInvoice(TenantName, ddlBillType.SelectedValue.Trim(), txtAmount.Value, UploadImage.PostedFile.FileName, txtDueDate.Value, txtNotes.Text); DataTable dtTenant = ClassLibrary_PropertyManager.Controller.cTenant.GetTenantByTenantID(Convert.ToInt32(lstTenant.SelectedValue)); ClassLibrary_PropertyManager.UtilityClasses.ucEmailManagement.SendTenantInvoice(dtTenant.Rows[0]["TenantEmail"].ToString(), strEmailMessage); divMsgSuccess.Visible = true; //email.InnerHtml = txtEmail.Text.Trim(); } } else { invoice.InvoiceID = Convert.ToInt32(Request.QueryString["id"]); //success = ClassLibrary_PropertyManager.Controller.cTenantContract.UpdateTenantContract(contract); //divMsgSuccess.Visible = true; } lstTenant.SelectedIndex = 0; ddlBillType.SelectedIndex = 0; txtAmount.Value = ""; txtDueDate.Value = ""; txtNotes.Text = ""; txtStatus.Checked = false; } catch (Exception ioExp) { using (StreamWriter sw = new StreamWriter(Global.ErrorFilePath, true)) { // If file exists, text will be appended ; otherwise a new file will be created sw.Write(string.Format("Message: {0}<br />{1}StackTrace :{2}{1}Date :{3}{1}-----------------------------------------------------------------------------{1}", ioExp.Message, Environment.NewLine, ioExp.StackTrace, DateTime.Now.ToString())); } divMsgError.Visible = true; } finally { invoice = null; } } }
protected void btnBackImage_Click(object sender, EventArgs e) { try { string productid = Request.QueryString["product"]; if (productid != null) { string ImageFile = ""; if (UploadImage.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; string smallPath = "~/Upload/small/"; ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); ImageFile = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-back-" + ImageFile; thumbPath = thumbPath + ImageFile; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); smallPath = smallPath + ImageFile; System.Drawing.Image objImage2 = ScaleImage2(bmpUploadedImage); objImage2.Save(Server.MapPath(smallPath), ImageFormat.Png); imgPath = imgPath + ImageFile; UploadImage.SaveAs(MapPath(imgPath)); } else { ImageFile = lblImage.Text; } string ImageFile2 = ""; if (UploadImage2.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; string smallPath = "~/Upload/small/"; ImageFile2 = Path.GetFileName(Server.MapPath(UploadImage2.PostedFile.FileName)); ImageFile2 = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-back-" + ImageFile2; thumbPath = thumbPath + ImageFile2; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage2.PostedFile.InputStream); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); smallPath = smallPath + ImageFile2; System.Drawing.Image objImage2 = ScaleImage2(bmpUploadedImage); objImage2.Save(Server.MapPath(smallPath), ImageFormat.Png); imgPath = imgPath + ImageFile2; UploadImage2.SaveAs(MapPath(imgPath)); } else { ImageFile2 = lblImage2.Text; } string ImageFile3 = ""; if (UploadImage3.HasFile) { string imgPath = "~/Upload/images/"; string thumbPath = "~/Upload/thumbnails/"; string smallPath = "~/Upload/small/"; ImageFile3 = Path.GetFileName(Server.MapPath(UploadImage3.PostedFile.FileName)); ImageFile3 = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-back-" + ImageFile3; thumbPath = thumbPath + ImageFile3; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage3.PostedFile.InputStream); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); smallPath = smallPath + ImageFile3; System.Drawing.Image objImage2 = ScaleImage2(bmpUploadedImage); objImage2.Save(Server.MapPath(smallPath), ImageFormat.Png); imgPath = imgPath + ImageFile3; UploadImage3.SaveAs(MapPath(imgPath)); } else { ImageFile3 = lblImage3.Text; } int result = 0; result = obj_product.AddOtherProductImage(productid, ImageFile, ImageFile2, ImageFile3); if (result != 0) { lblMessage.ForeColor = Color.Green; lblMessage.Text = "Product Other Image Added!"; BindBackImg(productid); } } else { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Go View Product & select Product!"; } } catch (Exception ex) { lblMessage.ForeColor = Color.Red; lblMessage.Text = ex.Message; } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { ClassLibrary_PropertyManager.Model.mBuilding building = new ClassLibrary_PropertyManager.Model.mBuilding(); int landlordId = Convert.ToInt32(Session["LandLordID"]); try { int success = 0; building.BuildingType = txtbuildingtype.Items[txtbuildingtype.SelectedIndex].Text; building.LandLordID = landlordId; building.BuildingName = txtname.Value.Trim(); building.BuildingCity = txtcity.Value.Trim(); building.BuildingAddress = txtaddress.Value.Trim(); building.TotalUnits = Convert.ToInt32(txttotals.Value); building.Contractor = txtcontractor.Value.Trim(); building.CompletionDate = Convert.ToDateTime(txtdate.Value).Date; building.Parking = txtparking.Checked; building.Security = txtsecurity.Checked; building.KidFriendly = txtkid.Checked; building.IsActive = true; if (UploadImage.HasFile) { fileName = building.BuildingID.ToString() + "-" + building.BuildingName + "-" + UploadImage.FileName.Trim(); if (File.Exists(Server.MapPath("/BuildingImages" + fileName))) { File.Delete(Server.MapPath("/BuildingImages" + fileName)); Console.WriteLine("File deleted."); } UploadImage.SaveAs(Server.MapPath("/BuildingImages" + fileName)); //DispalyMenuPicture.ImageUrl = Global.gShowMenuPicturesFiles + fileName; } building.BuildingImage = fileName; //Session["dtBuildings"] = building; if (btnSubmit.Text != "Update") { success = ClassLibrary_PropertyManager.Controller.cBuilding.AddBuilding(building); divMsgSuccess.Visible = true; } else { building.BuildingID = Convert.ToInt32(Request.QueryString["id"]); success = ClassLibrary_PropertyManager.Controller.cBuilding.UpdateBuildig(building); divMsgSuccess.Visible = true; } txtbuildingtype.SelectedIndex = 0; txtname.Value = ""; txtcity.Value = ""; txtaddress.Value = ""; txttotals.Value = ""; txtdate.Value = ""; txtcontractor.Value = ""; txtparking.Checked = false; txtsecurity.Checked = false; txtkid.Checked = false; } catch (Exception ioExp) { using (StreamWriter sw = new StreamWriter(Global.ErrorFilePath, true)) { // If file exists, text will be appended ; otherwise a new file will be created sw.Write(string.Format("Message: {0}<br />{1}StackTrace :{2}{1}Date :{3}{1}-----------------------------------------------------------------------------{1}", ioExp.Message, Environment.NewLine, ioExp.StackTrace, DateTime.Now.ToString())); } divMsgError.Visible = true; } finally { building = null; } } }
protected void btnAddEvent_Click(object sender, EventArgs e) { string title = txtEventtitle.Text; string description = CKEditor1.Text.Trim(); //int categoryid = Convert.ToInt32(ddCategory.SelectedValue); string date = DateTime.Now.ToString("dd/MM/yyyy"); int result = 0; try { //if (string.IsNullOrEmpty(Convert.ToString(Session["blogid"]))) if (string.IsNullOrEmpty(Convert.ToString(ViewState["ID"]))) { string blogimage = ""; if (UploadImage.HasFile) { //string imgPath = "~/Upload/images/"; //string thumbPath = "~/Upload/thumbnails/"; string imgPath = "~/Upload/event/"; string ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); blogimage = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; //thumbPath = thumbPath + blogimage; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 300); //System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); //objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); imgPath = imgPath + blogimage; UploadImage.SaveAs(MapPath(imgPath)); } result = local_product.AddNewEvent(title, description, date, blogimage); if (result != 0) { lblMessage.Text = "New Event Added Successfully"; lblMessage.ForeColor = Color.Green; BindBlog(); txtEventtitle.Text = ""; CKEditor1.Text = ""; } else { lblMessage.Text = "Event Not Added?"; lblMessage.ForeColor = Color.Red; } } else //edit { string blogimage = ""; if (UploadImage.HasFile) { string imgPath = "~/Upload/event/"; //string thumbPath = "~/Upload/thumbnails/"; string ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName)); blogimage = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile; //thumbPath = thumbPath + blogimage; System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream); System.Drawing.Image objImage = ScaleImage(bmpUploadedImage, 300); //System.Drawing.Image objImage = ScaleImage(bmpUploadedImage); //objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png); imgPath = imgPath + blogimage; UploadImage.SaveAs(MapPath(imgPath)); } else { blogimage = lblImage.Text; } string eventid = Request.QueryString["Eventid"]; result = local_product.UpdateEvent(title, description, eventid, blogimage); if (result != 0) { lblMessage.Text = "Event Updated Successfully"; lblMessage.ForeColor = Color.Green; BindBlog(); txtEventtitle.Text = ""; CKEditor1.Text = ""; Session["Eventid"] = null; Session["ID"] = null; btnAddEvent.Text = "Add Event"; lblImage.Text = ""; } else { lblMessage.Text = "Event Not Updated?"; lblMessage.ForeColor = Color.Red; } } } catch (Exception ex) { throw new Exception(ex.Message); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { ClassLibrary_PropertyManager.Model.mAnnouncment announcment = new ClassLibrary_PropertyManager.Model.mAnnouncment(); int landlordId = Convert.ToInt32(Session["LandLordID"]); try { int success = 0; announcment.AnnouncmentHeader = txtTitle.Text.Trim(); announcment.AnnouncmentBody = txtAnnouncment.Text.Trim(); announcment.BuildingID = Convert.ToInt32(ddlBuilding.SelectedValue); announcment.LandLordId = landlordId; announcment.AnnouncmentStatus = true; if (UploadImage.HasFile) { fileName = announcment.AnnouncmentID.ToString() + "-" + announcment.LandLordId + "-" + UploadImage.FileName.Trim(); if (File.Exists(Server.MapPath("/AnnouncmentImages/" + fileName))) { File.Delete(Server.MapPath("/AnnouncmentImages/" + fileName)); Console.WriteLine("File deleted."); } UploadImage.SaveAs(Server.MapPath("/AnnouncmentImages/" + fileName)); } announcment.AnnouncmentPicture = fileName; Session["dtAnnouncments"] = announcment; if (btnSubmit.Text != "Update") { success = ClassLibrary_PropertyManager.Controller.cAnnouncment.AddNewAnnouncment(announcment); divMsgSuccess.Visible = true; } else { //unit.UnitID = Convert.ToInt32(Request.QueryString["id"]); //success = ClassLibrary_PropertyManager.Controller.cUnit.UpdateUnit(unit); //divMsgSuccess.Visible = true; } ddlBuilding.SelectedIndex = 0; txtAnnouncment.Text = ""; } catch (Exception ioExp) { using (StreamWriter sw = new StreamWriter(Global.ErrorFilePath, true)) { // If file exists, text will be appended ; otherwise a new file will be created sw.Write(string.Format("Message: {0}<br />{1}StackTrace :{2}{1}Date :{3}{1}-----------------------------------------------------------------------------{1}", ioExp.Message, Environment.NewLine, ioExp.StackTrace, DateTime.Now.ToString())); } divMsgError.Visible = true; } finally { announcment = null; } } }