void BindForm(int id) { WR_Rule model = bll.GetModel(id); if (model == null) { Response.Redirect("RuleList.aspx", false); } lblID.Text = model.ID.ToString(); txtPublishDate.Value = model.Publish_Date.HasValue ? model.Publish_Date.Value.ToString("yyyy-MM-dd") : ""; ddlCategory.SelectedValue = model.Category_ID.ToString(); txtTitle.Text = model.Title; txtSummary.Text = model.Summary; //获取附件 List <WR_Attachment> items = new Attachement().GetListByRuleId(model.ID); List <AttachmentItem> attachmentItems = (from p in items select new AttachmentItem { Attachment_ID = p.Attachment_GUID, Created_On = p.Created_On, FileName = p.FileName, FileSize = p.FileSize, FilePath = p.FilePath }).ToList(); ViewState["Attachments"] = attachmentItems; rptAttachment.DataSource = attachmentItems; rptAttachment.DataBind(); }
public void Insert(WR_Rule model) { using (WorkFlowRuleDataContext db = new WorkFlowRuleDataContext()) { db.WR_Rule.InsertOnSubmit(model); db.SubmitChanges(); } }
protected void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(lblID.Text)) { try { WR_Rule model = GetModel(); model.Rule_GUID = Guid.NewGuid(); model.Created_By = CurrentEmployee.EmployeeCode; model.Created_By_Name = CurrentEmployee.EmployeeName; model.Created_On = DateTime.Now; model.Record_Status = 0; bll.Insert(model); List <WR_Attachment> attachements = GetAttachementModel(model.ID); new Attachement().Insert(attachements); JsHelper.AlertOperationSuccessAndRedirect(Page, "RuleList.aspx"); } catch (Exception ex) { JsHelper.AlertOperationFailure(Page, ex); } } else { try { WR_Rule model = GetModel(); model.ID = Convert.ToInt16(lblID.Text); bll.Update(model); new Attachement().DeleteByRuleId(model.ID); List <WR_Attachment> attachements = GetAttachementModel(model.ID); new Attachement().Insert(attachements); JsHelper.AlertOperationSuccessAndRedirect(Page, "RuleList.aspx"); } catch (Exception ex) { JsHelper.AlertOperationFailure(Page, ex); } } }
WR_Rule GetModel() { WR_Rule model = new WR_Rule(); if (!string.IsNullOrEmpty(txtPublishDate.Value.Trim())) { model.Publish_Date = Convert.ToDateTime(txtPublishDate.Value.Trim()).Date; } model.Category_ID = Convert.ToInt32(ddlCategory.SelectedValue); model.Title = txtTitle.Text.Trim(); model.Summary = txtSummary.Text.Trim(); model.Record_Status = 0; model.Modified_By = CurrentEmployee.EmployeeCode; model.Modified_By_Name = CurrentEmployee.EmployeeName; model.Modified_On = DateTime.Now; return(model); }
public void Update(WR_Rule model) { using (WorkFlowRuleDataContext db = new WorkFlowRuleDataContext()) { WR_Rule obj = db.WR_Rule.Where(p => p.ID == model.ID && p.Record_Status == 0).FirstOrDefault(); if (obj != null) { obj.Modified_By = model.Modified_By; obj.Modified_By_Name = model.Modified_By_Name; obj.Modified_On = model.Modified_On; obj.Publish_Date = model.Publish_Date; obj.Category_ID = model.Category_ID; obj.Title = model.Title; obj.Summary = model.Summary; db.SubmitChanges(); } } }
protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e) { try { if (e.CommandName == "Delete") { WR_Rule model = new WR_Rule(); model.ID = Convert.ToInt16(e.CommandArgument); model.Record_Status = 2; model.Modified_By = CurrentEmployee.EmployeeCode; model.Modified_By_Name = CurrentEmployee.EmployeeName; model.Modified_On = DateTime.Now; bll.UpdateRecordStatus(model); Label lblCategoryName = (Label)e.Item.FindControl("lblCategoryName"); //删除附件 List <WR_Attachment> items = new Attachement().GetListByRuleId(model.ID); foreach (var item in items) { new Attachement().Delete(item.ID); //删除服务器文件 string path = "/WorkFlowRule/Upload/" + lblCategoryName.Text + "/" + item.FileName; if (File.Exists(Server.MapPath("~" + path))) { File.Delete(Server.MapPath("~" + path)); } } BindDataList(); } if (e.CommandName == "Edit") { Response.Redirect("RuleEdit.aspx?ID=" + e.CommandArgument, false); } } catch (Exception ex) { JsHelper.AlertOperationFailure(Page, ex); } }
private void BindInfo(int id) { WR_Rule model = bll.GetModel(id); if (model != null) { if (model.Rule_GUID.ToString() != Request.QueryString["GUID"]) { Response.Redirect("Institution.aspx", false); return; } if (model.Publish_Date.HasValue) { lblPublishDate.Visible = true; lblPublishDate.Text = "自 " + model.Publish_Date.Value.ToString("yyyy-MM-dd") + " 施行"; } lblTitle.Text = model.Title; lblSummary.Text = model.Summary.Replace("\n", "<br/>"); lblCreatedByName.Text = model.Created_By_Name; lblCreatedOn.Text = model.Created_On.ToString(); //Hidden hdId.Value = model.ID.ToString(); hdcreatedBy.Value = CurrentEmployee.EmployeeCode; hdcreatedByName.Value = CurrentEmployee.EmployeeName; //附件 List <WR_Attachment> items = new Attachement().GetListByRuleId(model.ID); rptAttachements.DataSource = items; rptAttachements.DataBind(); if (items.Count == 0) { lblAttachements.Visible = true; } } }
public void UpdateRecordStatus(WR_Rule model) { using (WorkFlowRuleDataContext db = new WorkFlowRuleDataContext()) { WR_Rule obj = db.WR_Rule.Where(p => p.ID == model.ID && p.Record_Status == 0).FirstOrDefault(); if (obj != null) { obj.Modified_By = model.Modified_By; obj.Modified_By_Name = model.Modified_By_Name; obj.Modified_On = model.Modified_On; obj.Record_Status = model.Record_Status; //删除收藏记录 var items = db.WR_Focus.Where(p => p.Record_Status == 0 && p.Rule_ID == model.ID); foreach (var item in items) { db.WR_Focus.DeleteOnSubmit(item); } db.SubmitChanges(); } } }