private void ProfilePhotoUpdate() { try { if (photoUpload.HasFile) { urUserRegBLLObj.usrProfilePhoto = photoUpload.FileName; imageOk = cc.CheckImageExtension(urUserRegBLLObj.usrProfilePhoto); } if (imageOk == true) { string thisDir = Server.MapPath("~"); //if (File.Exists(thisDir + "\\User_Resource\\" + urUserRegBLLObj.usrUserId + "\\Profile_Photo\\"+*+".jpg")) //{ // File.Delete(thisDir + "\\User_Resource\\" + urUserRegBLLObj.usrUserId + "\\Profile_Photo\\"); //} urUserRegBLLObj.usrUserId = Convert.ToString(Session["userid"]); string ePath = thisDir + "\\User_Resource\\" + urUserRegBLLObj.usrUserId + "\\Profile_Photo"; string[] filename = Directory.GetFiles(ePath, "*"); foreach (string str in filename) { File.Delete(str); } string currentUserId = Convert.ToString(Session["userid"]); photoUpload.PostedFile.SaveAs(path + currentUserId + "\\Profile_Photo\\" + urUserRegBLLObj.usrProfilePhoto); urUserRegBLLObj.usrUserId = currentUserId; int j = urUserRegBLLObj.BLLUserProfilePhotoUpdate(urUserRegBLLObj); if (j > 0) { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Photo Uploaded')", true); } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Photo Not Uploaded')", true); } } } catch (Exception ex) { //throw ex; } }
public void GetImagePath() { fileSaved = false; advBLLObj.AdvId = Convert.ToString(ViewState["advId"]); if (advBLLObj.AdvId == null) { advBLLObj.AdvId = System.Guid.NewGuid().ToString(); } thisDir = Server.MapPath("~"); if (!System.IO.Directory.Exists(thisDir + "\\Political_Resource\\" + advBLLObj.AdvId)) { System.IO.Directory.CreateDirectory(thisDir + "\\Political_Resource\\" + advBLLObj.AdvId); } System.Random round = new Random(); string rndImage = Convert.ToString(round.Next(1, 9999)); if (FileUpload.HasFile) { advBLLObj.ImageURL = FileUpload.FileName; imageOk = cc.CheckImageExtension(advBLLObj.ImageURL); //check for correct image extension } if (imageOk == true) { try { FileUpload.PostedFile.SaveAs(path + "\\" + advBLLObj.AdvId + "\\" + rndImage + advBLLObj.ImageURL); advBLLObj.ImageURL = rndImage + advBLLObj.ImageURL; fileSaved = true; } catch (Exception ex) { throw ex; } } }
public void ItemImageUpload() { iciBLLObj.itemId = Convert.ToString(ddlSelectItem.SelectedValue); iciBLLObj.categoryId = Convert.ToInt32(Convert.ToString(ddlSelectCategory.SelectedValue)); iciBLLObj.imageSetType = Convert.ToInt32(ddlImageType.SelectedValue); status = iciBLLObj.BLLIsExistsMainItemCategoryImage(iciBLLObj); if (status > 0) { iciBLLObj.BLLIsExistsItemCategoryImage(iciBLLObj, out status, out imgId); iciBLLObj.imageId = imgId; if (status > 0) { if (Convert.ToString(ViewState["updateImage"]) == "1") { iciBLLObj.imageId = Convert.ToInt32(Convert.ToString(ViewState["updateImageId"])); string thisDir = Server.MapPath("~"); if (!System.IO.Directory.Exists(thisDir + "\\Item_Resource\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId)) { System.IO.Directory.CreateDirectory(thisDir + "\\Item_Resource\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId); } System.Random round = new Random(); rndImage = Convert.ToString(round.Next(1, 9999)); if (iciBLLObj.imageSetType == 2) { iciBLLObj.image1 = uplImage7.FileName; image1Ok = cc.CheckImageExtension(iciBLLObj.image1); iciBLLObj.imageName = txtImageName3.Text; iciBLLObj.imageDescription = txtImageDescription3.Text; if (image1Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; fileSaved = true; } } else if (iciBLLObj.imageSetType == 1) { iciBLLObj.image1 = uplImage4.FileName; iciBLLObj.image2 = uplImage5.FileName; iciBLLObj.image3 = uplImage6.FileName; image1Ok = cc.CheckImageExtension(iciBLLObj.image1); image2Ok = cc.CheckImageExtension(iciBLLObj.image2); image3Ok = cc.CheckImageExtension(iciBLLObj.image3); iciBLLObj.imageName = txtImageName2.Text; iciBLLObj.imageDescription = txImageDescription2.Text; if (image1Ok == true && image2Ok == true && image3Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; uplImage2.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image2); iciBLLObj.image2 = rndImage + iciBLLObj.image2; uplImage3.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image3); iciBLLObj.image3 = rndImage + iciBLLObj.image3; fileSaved = true; } } else { iciBLLObj.image1 = uplImage1.FileName; iciBLLObj.image2 = uplImage2.FileName; iciBLLObj.image3 = uplImage3.FileName; image1Ok = cc.CheckImageExtension(iciBLLObj.image1); image2Ok = cc.CheckImageExtension(iciBLLObj.image2); image3Ok = cc.CheckImageExtension(iciBLLObj.image3); iciBLLObj.imageName = txtImageName.Text; iciBLLObj.imageDescription = txtImageDesc.Text; if (image1Ok == true && image2Ok == true && image3Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; uplImage2.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image2); iciBLLObj.image2 = rndImage + iciBLLObj.image2; uplImage3.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image3); iciBLLObj.image3 = rndImage + iciBLLObj.image3; fileSaved = true; } } if (fileSaved == true) { int k = iciBLLObj.BLLItemCategoryImageUpdate(iciBLLObj); if (k > 0) { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert(' updated')", true); } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Not updated')", true); } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Check File Exist Or not')", true); } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Already Photo Uploaded Please update it')", true); } } else { //TODO : Implement The Feature of Alreaady Inserted ==>Data to Updated string thisDir = Server.MapPath("~"); if (!System.IO.Directory.Exists(thisDir + "\\Item_Resource\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId)) { System.IO.Directory.CreateDirectory(thisDir + "\\Item_Resource\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId); } System.Random round = new Random(); rndImage = Convert.ToString(round.Next(1, 9999)); if (iciBLLObj.imageSetType == 2) { iciBLLObj.image1 = uplImage7.FileName; image1Ok = cc.CheckImageExtension(iciBLLObj.image1); iciBLLObj.imageName = txtImageName3.Text; iciBLLObj.imageDescription = txtImageDescription3.Text; if (image1Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; fileSaved = true; } } else if (iciBLLObj.imageSetType == 1) { iciBLLObj.image1 = uplImage4.FileName; iciBLLObj.image2 = uplImage5.FileName; iciBLLObj.image3 = uplImage6.FileName; image1Ok = cc.CheckImageExtension(iciBLLObj.image1); image2Ok = cc.CheckImageExtension(iciBLLObj.image2); image3Ok = cc.CheckImageExtension(iciBLLObj.image3); iciBLLObj.imageName = txtImageName2.Text; iciBLLObj.imageDescription = txImageDescription2.Text; if (image1Ok == true && image2Ok == true && image3Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; uplImage2.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image2); iciBLLObj.image2 = rndImage + iciBLLObj.image2; uplImage3.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image3); iciBLLObj.image3 = rndImage + iciBLLObj.image3; fileSaved = true; } } else { iciBLLObj.image1 = uplImage1.FileName; iciBLLObj.image2 = uplImage2.FileName; iciBLLObj.image3 = uplImage3.FileName; iciBLLObj.imageName = txtImageName.Text; iciBLLObj.imageDescription = txtImageDesc.Text; if (image1Ok == true && image2Ok == true && image3Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; uplImage2.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image2); iciBLLObj.image2 = rndImage + iciBLLObj.image2; uplImage3.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image3); iciBLLObj.image3 = rndImage + iciBLLObj.image3; fileSaved = true; } } if (fileSaved == true) { int kx = iciBLLObj.BLLItemCategoryImageUpdate(iciBLLObj); if (kx > 0) { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert(' updated')", true); } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Not updated')", true); } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Check File Exist Or not')", true); } } } else //For total New Insert Image { iciBLLObj.imageSetType = mvwMain.ActiveViewIndex; string thisDir = Server.MapPath("~"); if (!System.IO.Directory.Exists(thisDir + "\\Item_Resource\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId)) { System.IO.Directory.CreateDirectory(thisDir + "\\Item_Resource\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId); } System.Random round = new Random(); rndImage = Convert.ToString(round.Next(1, 9999)); if (iciBLLObj.imageSetType == 2) { iciBLLObj.image1 = uplImage7.FileName; image1Ok = cc.CheckImageExtension(iciBLLObj.image1); iciBLLObj.imageName = txtImageName3.Text; iciBLLObj.imageDescription = txtImageDescription3.Text; if (image1Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; fileSaved = true; } } else if (iciBLLObj.imageSetType == 1) { iciBLLObj.image1 = uplImage4.FileName; iciBLLObj.image2 = uplImage5.FileName; iciBLLObj.image3 = uplImage6.FileName; image1Ok = cc.CheckImageExtension(iciBLLObj.image1); image2Ok = cc.CheckImageExtension(iciBLLObj.image2); image3Ok = cc.CheckImageExtension(iciBLLObj.image3); iciBLLObj.imageName = txtImageName2.Text; iciBLLObj.imageDescription = txImageDescription2.Text; if (image1Ok == true && image2Ok == true && image3Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; uplImage2.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image2); iciBLLObj.image2 = rndImage + iciBLLObj.image2; uplImage3.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image3); iciBLLObj.image3 = rndImage + iciBLLObj.image3; fileSaved = true; } } else { iciBLLObj.image1 = uplImage1.FileName; iciBLLObj.image2 = uplImage2.FileName; iciBLLObj.image3 = uplImage3.FileName; image1Ok = cc.CheckImageExtension(iciBLLObj.image1); image2Ok = cc.CheckImageExtension(iciBLLObj.image2); image3Ok = cc.CheckImageExtension(iciBLLObj.image3); iciBLLObj.imageName = txtImageName.Text; iciBLLObj.imageDescription = txtImageDesc.Text; if (image1Ok == true && image2Ok == true && image3Ok == true) { uplImage1.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image1); iciBLLObj.image1 = rndImage + iciBLLObj.image1; uplImage2.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image2); iciBLLObj.image2 = rndImage + iciBLLObj.image2; uplImage3.PostedFile.SaveAs(path + "\\" + iciBLLObj.itemId + "\\" + iciBLLObj.categoryId + "\\" + rndImage + iciBLLObj.image3); iciBLLObj.image3 = rndImage + iciBLLObj.image3; fileSaved = true; } } if (fileSaved == true) { int j = iciBLLObj.BLLItemCategoryImageInsert(iciBLLObj); if (j > 0) { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Photo Uploaded')", true); } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Photo Not Uploaded')", true); } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Check File Exist Or not')", true); } } }
//Add & Update the Item public void InsertItem() { bool fileSaved = false; string getCategory = ""; for (int k = 0; k < chkLstCategory.Items.Count; k++) //Get all the category to which item will be inserted { if (chkLstCategory.Items[k].Selected == true) { getCategory += Convert.ToString(chkLstCategory.Items[k].Value) + ","; } } if (cmbCity.SelectedValue == "") { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Select City')", true); } else if (getCategory == "") { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Select Category')", true); } else { try { itemBLLObj.itemName = txtItemName.Text; itemBLLObj.itemDescription = txtItemDescription.Text; itemBLLObj.cityId = Convert.ToInt32(Convert.ToString(cmbCity.SelectedValue)); itemBLLObj.itemActive = 1; //for (int k = 0; k < chkLstCategory.Items.Count; k++) //Get all the category to which item will be inserted //{ // if (chkLstCategory.Items[k].Selected == true) // { // getCategory += Convert.ToString(chkLstCategory.Items[k].Value) + ","; // } //} int id = getCategory.Length; string categotyId = getCategory.Substring(0, id - 1); if (Convert.ToString(ViewState["EditImage"]) != "1") { itemBLLObj.itemId = System.Guid.NewGuid().ToString(); //Creates a GUID as new Item Id itemBLLObj.categoryId = categotyId; string thisDir = Server.MapPath("~"); if (!System.IO.Directory.Exists(thisDir + "\\Item_Resource\\" + itemBLLObj.itemId)) //Creates a folder named that of GIUD(itemId) { System.IO.Directory.CreateDirectory(thisDir + "\\Item_Resource\\" + itemBLLObj.itemId); } System.Random round = new Random(); string rndImage = Convert.ToString(round.Next(1, 9999)); if (uplSelectImage.HasFile) { itemBLLObj.itemImage = uplSelectImage.FileName; imageOk = cc.CheckImageExtension(itemBLLObj.itemImage); //check for correct image extension } if (imageOk == true) { try { uplSelectImage.PostedFile.SaveAs(path + "\\" + itemBLLObj.itemId + "\\" + rndImage + itemBLLObj.itemImage); itemBLLObj.itemImage = rndImage + itemBLLObj.itemImage; fileSaved = true; } catch (Exception ex) { throw ex; } } status = itemBLLObj.BLLInsertItem(itemBLLObj); if (status > 0) { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Item Inserted Successfully.')", true); } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Item Not Inserted.')", true); } } else //Update the Item { itemBLLObj.itemId = Convert.ToString(ViewState["itemId"]); itemBLLObj.itemDescription = txtItemDescription.Text; itemBLLObj.itemName = txtItemName.Text; itemBLLObj.categoryId = categotyId; itemBLLObj.cityId = Convert.ToInt32(cmbCity.SelectedValue); System.Random round = new Random(); string rndImage = Convert.ToString(round.Next(1, 9999)); if (uplSelectImage.HasFile) { itemBLLObj.itemImage = uplSelectImage.FileName; imageOk = cc.CheckImageExtension(itemBLLObj.itemImage); //check for correct image extension } if (imageOk == true) { try { uplSelectImage.PostedFile.SaveAs(path + "\\" + itemBLLObj.itemId + "\\" + rndImage + itemBLLObj.itemImage); itemBLLObj.itemImage = rndImage + itemBLLObj.itemImage; fileSaved = true; } catch (Exception ex) { throw ex; } } status = itemBLLObj.BLLUpdateItem(itemBLLObj); if (status > 0) { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Item Updated Successfully.')", true); } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('Item Not Updated.')", true); } } } catch (Exception ex) { throw ex; } } }