private void InitData() { job = js.GetModel(id); if (job != null) { hidID.Value = job.Id.ToString(); ddlCatalog.SelectedValue = job.NodeCode; txtName.Text = job.Name; txtNumbers.Text = job.Numbers.ToString(); txtAddress.Text = job.Address; txtResponsibilities.Text = job.Responsibilities; txtRequirements.Text = job.Requirements; txtRemark.Text = job.Remark; txtOrder.Text = job.OrderNo.ToString(); chkEnabled.Checked = (job.IsEnabled == 1); txtHits.Text = job.Hits.ToString(); txtEndTime.Text = job.EndTime.HasValue ? job.EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; txtTime.Text = job.AddTime.ToString("yyyy-MM-dd HH:mm:ss"); } }
protected override void btnSave_Click(object sender, EventArgs e) { int num = 0; if (!int.TryParse(txtNumbers.Text.Trim(), out num)) { num = 1; } int order = 0; if (!int.TryParse(txtOrder.Text.Trim(), out order)) { order = 1; } int hits = 0; if (!int.TryParse(txtHits.Text.Trim(), out hits)) { hits = 0; } DateTime dt1, dt2; if (!DateTime.TryParse(txtTime.Text.Trim(), out dt1)) { dt1 = DateTime.Now; } if (!DateTime.TryParse(txtEndTime.Text.Trim(), out dt2)) { dt2 = DateTime.MaxValue; } if (action.Equals("add")) { job = new cmsJob(); job.AddTime = DateTime.Now; } else { job = js.GetModel(id); job.Attach(); } job.NodeCode = ddlCatalog.SelectedValue; job.Name = txtName.Text.Trim(); job.Numbers = num; job.Address = txtAddress.Text; job.Responsibilities = txtResponsibilities.Text; job.Requirements = txtRequirements.Text; job.Remark = txtRemark.Text; job.OrderNo = order; job.IsEnabled = chkEnabled.Checked ? 1 : 0; job.Hits = Convert.ToInt32(txtHits.Text); job.AddTime = dt1; if (dt2 != DateTime.MaxValue) { job.EndTime = dt2; } job.LangId = CurrentLanguageId; try { int r = js.SaveModel(job); if (action.Equals("add")) { ScriptUtil.ConfirmAndRedirect(@"职位添加成功!\n“确定”继续添加,“取消”则跳转到列表页。", "JobAdd.aspx?node=" + NodeCode, "JobList.aspx?node=" + NodeCode); } else { ScriptUtil.ConfirmAndRedirect(@"职位修改成功!\n“确定”留在本页,“取消”则跳转到列表页。", "JobAdd.aspx?node=" + NodeCode + "&id=" + id + "&action=edit", "JobList.aspx?node=" + NodeCode); } } catch (Exception ex) { ScriptUtil.Alert(ex.Message); Logger.Error(ex.Message); } }