//新增 public void CreateData(BbsViewModel model) { //model 不得為 null if (model == null) { throw new Exception("請檢查輸入的資料!"); } //判斷有無此部門代碼 if (IsExistBbsID(model.bbs_id.ToString())) { throw new Exception("新增失敗,已經存在相同代碼!"); } var mainpulationConditions = new Conditions() { { "@bbs_title", model.txt_Title }, { "@bbs_content", model.txt_Content }, { "@startdatetime", model.DefaultStartDateTime }, { "@enddatetime", model.DefaultEndDateTime }, { "@bbs_http", model.txt_Http }, { "@bbs_photo", model.PhotoName }, { "@bbs_file", model.UpName }, { "@Creator", model.Creator }, { "@CreateDate", model.CreateDate }, }; try { _dc.ExecuteAndCheck( @"INSERT INTO BbsContent (bbs_title, bbs_content, startdatetime, enddatetime, bbs_http, bbs_photo, bbs_file, creator, createdate) VALUES (@bbs_title, @bbs_content, @startdatetime, @enddatetime, @bbs_http, @bbs_photo, @bbs_file, @Creator, @CreateDate) " , mainpulationConditions); } catch (Exception ex) { throw ex; } }
protected void Button_DelFILE2_Command(object sender, CommandEventArgs e) { _bbsRepo = RepositoryFactory.CreateBbsRepo(); //取得頁面資料 model = WebUtils.ViewModelMapping <BbsViewModel>(this.Page); String filepath2 = _bbsRepo.Find_Url(model.bbs_id.ToString()); del_file(filepath2); File_Up1.Visible = true; Button_DelFILE2.Visible = false; HyperLink_FILENAME2.Visible = false; }
protected void Page_Load(object sender, EventArgs e) { if (!Authentication.HasResource(User.Identity.Name, "bbs_contentList")) { Response.Redirect(@"/account/logon.aspx?ReturnUrl=%2f"); } if (!IsPostBack) { _bbsRepo = RepositoryFactory.CreateBbsRepo(); _rootRepo = RepositoryFactory.CreateRootRepo(); //從QueryString取得 公佈欄代碼 string bbsID = String.IsNullOrEmpty(Request["BbsID"]) ? String.Empty : Request["BbsID"].ToString(); PageTitle.Value = "公佈欄 > 新增"; if (!String.IsNullOrWhiteSpace(bbsID)) { model = _bbsRepo.GetBbs(bbsID); PageTitle.Value = "公佈欄 > 編輯"; if (model.PhotoName != "") { HyperLink_FILENAME1.Visible = true; HyperLink_FILENAME1.NavigateUrl = @"..\..\Upload\" + model.PhotoName; Button_DelFILE1.Visible = true; File_Photo.Visible = false; } else { HyperLink_FILENAME1.Visible = false; Button_DelFILE1.Visible = false; File_Photo.Visible = true; } if (model.UpName != "") { HyperLink_FILENAME2.Visible = true; HyperLink_FILENAME2.NavigateUrl = @"..\..\Upload\" + model.UpName; Button_DelFILE2.Visible = true; File_Up1.Visible = false; } else { HyperLink_FILENAME2.Visible = false; Button_DelFILE2.Visible = false; File_Up1.Visible = true; } WebUtils.PageDataBind(_bbsRepo.GetBbsData(bbsID), this.Page); } } }
//編輯 public void EditData(BbsViewModel model) { var orgModel = GetBbsData(model.bbs_id.ToString()); //model 不得為 null if (model == null || orgModel == null) { throw new Exception("請檢查輸入的資料!"); } if (!model.TimeStamp.Equals(orgModel.ModifyDate.FormatDatetimeNullable())) { throw new Exception("此筆資料已被他人更新!請重新確認!"); } var mainpulationConditions = new Conditions() { { "@bbs_id", model.bbs_id }, { "@bbs_title", model.txt_Title }, { "@bbs_content", model.txt_Content }, { "@startdatetime", model.DefaultStartDateTime }, { "@enddatetime", model.DefaultEndDateTime }, { "@bbs_http", model.txt_Http }, { "@bbs_photo", model.PhotoName }, { "@bbs_file", model.UpName }, { "@Modifier", model.Modifier } }; try { //bbs_photo = @bbs_photo, //bbs_file = @bbs_file, _dc.ExecuteAndCheck( @"Update BbsContent Set bbs_title = @bbs_title, bbs_content = @bbs_content, startdatetime = @startdatetime, enddatetime = @enddatetime, bbs_http = @bbs_http, bbs_photo = @bbs_photo, bbs_file = @bbs_file, Modifier = @Modifier, ModifyDate = getDate() Where bbs_id = @bbs_id", mainpulationConditions); } catch (Exception ex) { throw ex; } }
//簽核作業頁面 > 取得表單資料 public BbsViewModel GetBbs(string bbs_id) { BbsViewModel model = null; string strSQL = @"Select * from BbsContent Where bbs_id = @bbs_id"; var strCondition = new Conditions() { { "@bbs_id", bbs_id } }; var result = _dc.QueryForDataRow(strSQL, strCondition); if (result == null) { return(null); } model = new BbsViewModel() { bbs_id = Int32.Parse(result["bbs_id"].ToString()), txt_Title = result["bbs_title"].ToString(), txt_Content = result["bbs_content"].ToString(), DefaultStartDateTime = !result["StartDateTime"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["StartDateTime"].ToString()) : (DateTime?)null, DefaultEndDateTime = !result["EndDateTime"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["EndDateTime"].ToString()) : (DateTime?)null, txt_Http = result["bbs_http"].ToString(), PhotoName = result["bbs_photo"].ToString(), UpName = result["bbs_file"].ToString(), Modifier = result["Modifier"].ToString(), Creator = result["Creator"].ToString() //FormID_FK = Int32.Parse(result["FormID_FK"].ToString()), //SignDocID_FK = result["SignDocID_FK"].ToString(), //ApplyID_FK = result["ApplyID_FK"].ToString(), //ApplyName = result["ApplayName"].ToString(), //ApplyDateTime = DateTime.Parse(result["ApplyDateTime"].ToString()), //EmployeeID_FK = result["EmployeeID_FK"].ToString(), //EmployeeName = result["EmployeeName"].ToString(), //DepartmentID_FK = result["DepartmentID_FK"].ToString(), //DepartmentName = result["DepartmentName"].ToString(), //PeriodType = Int32.Parse(result["PeriodType"].ToString()), //PunchName = result["PunchName"].ToString(), //ForgotPunchInDateTime = !result["ForgotPunchInDateTime"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["ForgotPunchInDateTime"].ToString()) : (DateTime?)null, //ForgotPunchOutDateTime = !result["ForgotPunchOutDateTime"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["ForgotPunchOutDateTime"].ToString()) : (DateTime?)null, //Note = result["Note"].ToString() }; return(model); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PageTitle.Value = "公佈欄資料 > 公佈的內容"; _bbsRepo = RepositoryFactory.CreateBbsRepo(); //從QueryString取得 簽核代碼 string bbsID = String.IsNullOrEmpty(Request["bbs_id"]) ? String.Empty : Request["bbs_id"].ToString(); //根據查詢的SN 搜尋公告 model = _bbsRepo.GetBbs(bbsID); if (model.PhotoName.ToString() != "") { img_Photo.Visible = true; img_Photo.ImageUrl = @"..\..\Upload\" + model.PhotoName; } else { img_Photo.Visible = false; } if (model.txt_Http.ToString() != "http://" && model.txt_Http.ToString() != "") { hyl_Http.Visible = true; hyl_Http.Text = model.txt_Http; hyl_Http.NavigateUrl = model.txt_Http; } else { hyl_Http.Visible = false; } if (model.UpName.ToString() != "") { hyl_Url.Visible = true; hyl_Url.Text = model.UpName; hyl_Url.NavigateUrl = @"..\..\Upload\" + model.UpName; } else { hyl_Url.Visible = false; } lbl_Creator.Text = model.Creator; WebUtils.PageDataBind(model, this.Page); } }
//編輯頁面 > 取得部門資料 public BbsViewModel GetBbsData(string bbsID) { BbsViewModel model = null; string strSQL = @"Select * from BbsContent where bbs_id = @bbs_id"; var strCondition = new Conditions() { { "@bbs_id", bbsID } }; var result = _dc.QueryForDataRow(strSQL, strCondition); if (result == null) { return(null); } model = new BbsViewModel() { bbs_id = int.Parse(result["bbs_id"].ToString()), txt_Title = result["bbs_title"].ToString(), txt_Content = result["bbs_content"].ToString(), DefaultStartDateTime = !result["StartDateTime"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["StartDateTime"].ToString()) : (DateTime?)null, DefaultEndDateTime = !result["EndDateTime"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["EndDateTime"].ToString()) : (DateTime?)null, txt_Http = result["bbs_http"].ToString(), PhotoName = result["bbs_photo"].ToString(), UpName = result["bbs_file"].ToString(), //DepartmentLevel = Int32.Parse(result["DepartmentLevel"].ToString()), //FilingEmployeeID_FK = result["FilingEmployeeID_FK"].ToString(), //Disabled = "True".Equals(result["Disabled"].ToString()), //DisabledDate = !result["DisabledDate"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["DisabledDate"].ToString()) : (DateTime?)null, Modifier = result["Modifier"].ToString(), ModifyDate = !result["ModifyDate"].IsDBNullOrWhiteSpace() ? DateTime.Parse(result["ModifyDate"].ToString()) : DateTime.Parse(result["CreateDate"].ToString()), TimeStamp = (result["ModifyDate"].IsDBNullOrWhiteSpace() ? result["CreateDate"].ToString() : result["ModifyDate"].ToString()).ToDateFormateString(), EmployeeDic = _rootRepo.GetEmployee(), DepartmentDic = _rootRepo.GetDepartment(), }; return(model); }
protected void SaveBtn_Click(object sender, EventArgs e) { _bbsRepo = RepositoryFactory.CreateBbsRepo(); //取得頁面資料 model = WebUtils.ViewModelMapping <BbsViewModel>(this.Page); var validator = new Validator(); var validResult = validator.ValidateModel(model); if (!validResult.IsValid) { Response.Write(validResult.ErrorMessage.ToString().ToAlertFormat()); return; } //btn處理 ViewUtils.ButtonOff(SaveBtn, CoverBtn); //存檔 var responseMessage = ""; var successRdUrl = String.Empty; //if (!Check_Null()) //{ // return; //} try { if (String.IsNullOrWhiteSpace(Request["BbsID"])) { BatchFileUpload1(File_Photo); BatchFileUpload2(File_Up1); _bbsRepo.CreateData(model); successRdUrl = @"bbs_contentList.aspx?orderField=CreateDate&descending=True"; responseMessage = "新增成功!"; } else { string filepath1 = string.Empty; if (File_Photo.Visible == false && Button_DelFILE1.Visible == true) { filepath1 = _bbsRepo.Find_Photo(model.bbs_id.ToString()); } else if (!string.IsNullOrEmpty(File_Photo.PostedFile.FileName)) { BatchFileUpload1(File_Photo); filepath1 = File_Photo.FileName; } model.PhotoName = filepath1; string filepath2 = string.Empty; if (File_Up1.Visible == false && Button_DelFILE2.Visible == true) { filepath2 = _bbsRepo.Find_Url(model.bbs_id.ToString()); } else if (!string.IsNullOrEmpty(File_Up1.PostedFile.FileName)) { BatchFileUpload2(File_Up1); filepath2 = File_Up1.FileName; } model.UpName = filepath2; _bbsRepo.EditData(model); successRdUrl = @"bbs_contentList.aspx?orderField=ModifyDate&descending=True"; responseMessage = "編輯成功!"; } //btn處理 ViewUtils.ButtonOn(SaveBtn, CoverBtn); responseMessage = responseMessage.ToAlertAndRedirect(successRdUrl); } catch (Exception ex) { responseMessage = String.Concat("存檔失敗!\r\n錯誤訊息: ", ex.Message).ToAlertFormat(); ViewUtils.ShowRefreshBtn(CoverBtn, RefreshBtn); } finally { Response.Write(responseMessage); } }