public static bool UpdateCommunication(int communicationId, string exchange, int specialWorkTypeId, DateTime workStartDate, DateTime workEndDate, string type, string name, bool sex, DateTime birthday, string company, string address, string phoneNo, double ballot, bool isReelect, string background, string situation) { try { DbEntry.UsingTransaction(delegate { SpecialWork com = SpecialWork.FindById(communicationId); com.Exchange = exchange; com.SpecialWorkTypeId = specialWorkTypeId; if (DateTime.Compare(workStartDate, new DateTime(1900, 1, 1)) == 0) { com.WorkStartDate = null; } else { com.WorkStartDate = workStartDate; } if (DateTime.Compare(workEndDate, new DateTime(1900, 1, 1)) == 0) { com.WorkEndDate = null; } else { com.WorkEndDate = workEndDate; } com.Type = type; com.Name = name; com.Sex = sex; if (DateTime.Compare(birthday, new DateTime(1900, 1, 1)) == 0) { com.Birthday = null; } else { com.Birthday = birthday; } com.Company = company; com.Address = address; com.PhoneNo = phoneNo; com.Ballot = ballot; com.IsReelect = isReelect; com.Background = background; com.Situation = situation; com.Save(); }); } catch { return(false); } return(true); }
public static bool DeleteCommunication(int communicationId) { try { SpecialWork com = SpecialWork.FindById(communicationId); com.IsDelete = true; com.Save(); } catch { return(false); } return(true); }
public static int AddCommunication() { int id = 0; try { DbEntry.UsingTransaction(delegate { SpecialWork com = new SpecialWork(); com.IsDelete = true; com.Save(); id = com.Id; }); } catch { return(0); } return(id); }
//照片上传 protected void btn_upload_Click(object sender, EventArgs e) { if (communicationId == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('数据加载错误,请重新再试!')", true); return; } string fileExtension = null; string file = FileUpload_Photo.FileName; string filename = "ZXGZ-" + communicationId + "-" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss").Replace(" ", "").Replace("/", "").Replace(":", "").Replace("-", ""); bool fileOK = false; string savepath = Server.MapPath("~/upload/photos/"); //判断是否已选择上传文件 if (FileUpload_Photo.HasFile) { //获得文件后缀 fileExtension = System.IO.Path.GetExtension(FileUpload_Photo.FileName).ToLower(); //允许上传文件后缀 String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" }; //判断文件后缀是否被允许上传 for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; filename += fileExtension; } } //文件类型合法 if (fileOK) { try { long strLen = FileUpload_Photo.PostedFile.ContentLength; if (strLen >= 5 * 1024 * 1024) { ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('上传照片不能大于5M!')", true); return; } if (!Directory.Exists(savepath)) { Directory.CreateDirectory(savepath); } FileUpload_Photo.PostedFile.SaveAs(savepath + filename); string photoUrl = "../../upload/photos/" + filename; Photo.ImageUrl = "../../upload/photos/" + filename; //照片 SpecialWork com = SpecialWork.FindById(communicationId); com.PhotoName = filename; com.Save(); ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('上传成功!')", true); } catch (Exception ex) { text(ex.ToString()); ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('无法上传!')", true); } } else { ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('未识别的文件类型!')", true); } } else { ScriptManager.RegisterStartupScript(UpdatePanel_basic, this.GetType(), "alter", "alert('请选择文件!')", true); } }