protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { string un = AspNetSecurityHelper.GetCurrentUserName; ServiceDetailsManager _ServiceDetailsManager = new ServiceDetailsManager(); if (e.CommandName == "DeleteUpdate") { string Id = e.CommandArgument.ToString(); int id = 0; if (int.TryParse(Id, out id)) { string operation = (String)GetGlobalResourceObject("HCMResource", "Delete"); int i = 0;//_ServiceDetailsManager.DeleteServiceDetails(id); DAL.Entity.ServiceDetail obj = _ServiceDetailsManager.GetServiceDetails(id); if (obj != null) { obj.DeletedFlag = true; obj.LastUpdatedBy = un; obj.LastUpdatedDate = DateTime.Now; i = _ServiceDetailsManager.UpdateServiceDetails(obj); } if (i != 0) { ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationSuccess"), operation), "", Common.msgType.alertMessageSuccess); } else { ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationError"), operation), "", Common.msgType.alertMessageDanger); } FillData(); } } }
protected void btnSave_Click(object sender, EventArgs e) { var user = AspNetSecurityHelper.currentAppUser; if (user != null && sessionId != 0) { ServiceDetailsManager _ServiceDetailsManager = new ServiceDetailsManager(); SSAManager _SSAManager = new SSAManager(); DAL.Entity.ServiceDetail obj = _ServiceDetailsManager.GetServiceDetails(queryStringId); if (obj == null) { obj = new DAL.Entity.ServiceDetail(); } obj.InformationContent = txtInformationContent.Text; obj.ServiceInformationId = sessionId; int typ = 0; if (int.TryParse(ddlInfoType.SelectedValue, out typ) && typ != 0) { obj.InfoTypeId = typ; } int i = 0; if (obj.Id == 0) { obj.CreatedBy = user.UserName; obj.CreatedDate = DateTime.Now; obj.DeletedFlag = false; i = _ServiceDetailsManager.AddServiceDetails(obj); Operation = (String)GetGlobalResourceObject("HCMResource", "Add"); btnSave.Visible = false; } else { obj.LastUpdatedBy = user.UserName; obj.LastUpdatedDate = DateTime.Now; i = _ServiceDetailsManager.UpdateServiceDetails(obj); Operation = (String)GetGlobalResourceObject("HCMResource", "Update"); } if (i != 0) { if (obj.Id != 0 && obj.ServiceInformationId.HasValue) { UploadImage(obj.Id, obj.ServiceInformationId.ToString(), obj.InfoTypeId.ToString()); } ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationSuccess"), Operation), "", Common.msgType.alertMessageSuccess); FillData(); } else { ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationError"), Operation), "", Common.msgType.alertMessageDanger); } } else { Response.Redirect("/"); } }
private void UploadImage(int id, string svcInfoId, string folder) { try { if (FileUpload.HasFile == true) { //if (FileUploadImages.PostedFile.ContentLength > ImageMaxSize) //{ // string s = "يجب أن لا يتجاوز حجم الملف عن " + (ImageMaxSize / 1024).ToString() + " MB"; // ucMsg.statusMsg(s, msgtyp.error); //} //else //{ string appPath = HttpContext.Current.Request.ApplicationPath; string physicalPath = HttpContext.Current.Request.MapPath(appPath); string folderName = (folder == "3" ? "DetailsImages" : "DetailsFiles"); string ImagesFolderPath = physicalPath + "\\" + folderName; if (!Directory.Exists(ImagesFolderPath)) { Directory.CreateDirectory(ImagesFolderPath); } //ImagesFolderPath = ImagesFolderPath + "\\" + svcInfoId; //if (!Directory.Exists(ImagesFolderPath)) Directory.CreateDirectory(ImagesFolderPath); //Directory.Delete(ImagesFolderPath, true); if (!String.IsNullOrEmpty(FileUpload.PostedFile.ToString())) { string ext = Path.GetExtension(FileUpload.PostedFile.FileName); string imgName = FileUpload.FileName; string fileName = svcInfoId + "_" + id + ext; //FileUpload.FileName.Split('.')[1]; string imgPath = ImagesFolderPath + "\\" + fileName; if (!String.IsNullOrEmpty(imgPath)) { string chkimgPath = imgPath; FileInfo FInfo = new FileInfo(chkimgPath); if (FInfo.Exists) { FInfo.Delete(); } } FileUpload.SaveAs(imgPath); ServiceDetailsManager _ServiceDetailsManager = new ServiceDetailsManager(); DAL.Entity.ServiceDetail obj = _ServiceDetailsManager.GetServiceDetails(id); if (obj != null) { obj.FileExt = ext.Replace(".", ""); int i = _ServiceDetailsManager.UpdateServiceDetails(obj); } } //} } } catch (Exception exception) { exception.Log(); } }