protected void Button1_Click(object sender, EventArgs e) { if (hiplanid.Value != "") { WX.Model.Plan.MODEL plan = this.GetRequestedPlan(); try { plan.Total.value = txtTotal.Text.Trim() == "" ? 0 : Convert.ToInt32(txtTotal.Text); } catch { plan.Total.value = 0; } try { plan.Current.value = txtCurrent.Text.Trim() == "" ? 0 : Convert.ToInt32(txtCurrent.Text); } catch { plan.Current.value = 0; } plan.Title.value = txtTitle.Text.Trim(); plan.Content.value = txtContent.Text.Trim(); plan.Summary.value = txtSummary.Text.Trim(); plan.Update(); WX.Main.AddLog(WX.LogType.Default, "修改计划!", String.Format("{0}", plan.Title.ToString())); } else { WX.Model.Plan.MODEL plan = WX.Model.Plan.NewDataModel(); try { plan.Total.value = txtTotal.Text.Trim() == "" ? 0 : Convert.ToInt32(txtTotal.Text); } catch { plan.Total.value = 0; } try { plan.Current.value = txtCurrent.Text.Trim() == "" ? 0 : Convert.ToInt32(txtCurrent.Text); } catch { plan.Current.value = 0; } plan.Title.value = txtTitle.Text.Trim(); plan.Content.value = txtContent.Text.Trim(); plan.Summary.value = txtSummary.Text.Trim(); if (Request["UserID"] != null && Request["UserID"] != "") { WX.Model.User.MODEL user = WX.Request.rUser; plan.UserID.value = user.UserID.value; plan.DepartmentID.value = user.DepartmentID.value; } else { plan.UserID.value = WX.Main.CurUser.UserID; plan.DepartmentID.value = Request["DeptId"]; } plan.Type.value = Request["type"]; plan.RangeType.value = Request["rtype"] != null && Request["rtype"] != "" ? Request["rtype"] : "1"; switch (Request["type"]) { //case "6": plan.Starttime.value = rDate.AddMonths(1).ToString("yyyy-MM-01"); plan.Stoptime.value = DateTime.Parse(plan.Starttime.ToString()).AddDays(DateTime.DaysInMonth(rDate.AddMonths(1).Year, rDate.AddMonths(1).Month) - 1); break; //case "5": DateTime now = rDate.AddDays(7); now = now.AddDays(-(Convert.ToInt32(now.DayOfWeek) > 0 ? Convert.ToInt32(now.DayOfWeek) : 7)); plan.Starttime.value = now.ToString("yyyy-MM-dd"); plan.Stoptime.value = now.AddDays(6).ToString("yyyy-MM-dd"); break; //case "4": plan.Starttime.value = rDate.AddDays(1).ToString("yyyy-MM-dd"); plan.Stoptime.value = plan.Starttime.value; break; case "3": plan.Starttime.value = rDate.ToString("yyyy-MM-01"); plan.Stoptime.value = DateTime.Parse(plan.Starttime.ToString()).AddDays(DateTime.DaysInMonth(rDate.Year, rDate.Month) - 1); break; case "2": DateTime now1 = rDate; now1 = now1.AddDays(-(Convert.ToInt32(now1.DayOfWeek) > 0 ? Convert.ToInt32(now1.DayOfWeek) : 7)); plan.Starttime.value = now1.ToString("yyyy-MM-dd"); plan.Stoptime.value = now1.AddDays(6).ToString("yyyy-MM-dd"); break; case "1": plan.Starttime.value = rDate.ToString("yyyy-MM-dd"); plan.Stoptime.value = plan.Starttime.value; break; default: break; } if (plan.Type.ToInt32() > 3) { plan.Type.set(plan.Type.ToInt32() - 3); } int id = plan.Insert(true); hiplanid.Value = id.ToString();; WX.Main.AddLog(WX.LogType.Default, "创建计划!", String.Format("{0}", plan.Title.ToString())); } ULCode.Debug.Alert(this, "保存成功!"); }
protected void Button1_Click(object sender, EventArgs e) { //获取用户变量 string title = this.plantitle.Text; string total = this.planTotle.Text; string current = this.planCurrent.Text; string content = this.planContent.Text; //验证 if (String.IsNullOrEmpty(title) || String.IsNullOrEmpty(content)) { ULCode.Debug.Alert(this, "标题与内容不能为空!"); return; } if (!ULCode.Validation.IsNumber(total) || !ULCode.Validation.IsNumber(current)) { ULCode.Debug.Alert(this, "预期数量与完成数量必须为数字"); return; } //操作 WX.Model.Plan.MODEL plan = null; if (Request["PlanId"] != null && Request["PlanId"] != "") { plan = WX.Request.rPlan; } else { plan = WX.Model.Plan.NewDataModel(); } plan.Title.value = plantitle.Text; plan.Total.value = planTotle.Text; plan.Current.value = planCurrent.Text; plan.Content.value = planContent.Text; plan.PlanState.value = 0; if (Request["PlanId"] != null && Request["PlanId"] != "") { plan.Update(); ULCode.Debug.Alert(this, "提交成功!", (plan.RangeType.ToInt32() == 1 ? "Plan_MyPlan.aspx" : "Plan_DeptPlan.aspx?type=" + plan.Type.ToString())); } else { WX.Main.CurUser.LoadUserModel(false); plan.UserID.value = WX.Main.CurUser.UserModel.UserID.ToString(); plan.DepartmentID.value = WX.Main.CurUser.UserModel.DepartmentID.ToString(); switch (this.rbPlanType.SelectedValue) { case "6": plan.Starttime.value = rDate.AddMonths(1).ToString("yyyy-MM-01"); plan.Stoptime.value = DateTime.Parse(plan.Starttime.ToString()).AddDays(DateTime.DaysInMonth(rDate.AddMonths(1).Year, rDate.AddMonths(1).Month) - 1); break; case "5": DateTime now = rDate.AddDays(7); now = now.AddDays(-(Convert.ToInt32(now.DayOfWeek) > 0 ? Convert.ToInt32(now.DayOfWeek) : 7)); plan.Starttime.value = now.ToString("yyyy-MM-dd"); plan.Stoptime.value = now.AddDays(6).ToString("yyyy-MM-dd"); break; case "4": plan.Starttime.value = rDate.AddDays(1).ToString("yyyy-MM-dd"); plan.Stoptime.value = plan.Starttime.value; break; case "3": plan.Starttime.value = rDate.ToString("yyyy-MM-01"); plan.Stoptime.value = DateTime.Parse(plan.Starttime.ToString()).AddDays(DateTime.DaysInMonth(rDate.Year, rDate.Month) - 1); break; case "2": DateTime now1 = rDate; now1 = now1.AddDays(-(Convert.ToInt32(now1.DayOfWeek) > 0 ? Convert.ToInt32(now1.DayOfWeek) : 7)); plan.Starttime.value = now1.ToString("yyyy-MM-dd"); plan.Stoptime.value = now1.AddDays(6).ToString("yyyy-MM-dd"); break; case "1": plan.Starttime.value = rDate.ToString("yyyy-MM-dd"); plan.Stoptime.value = plan.Starttime.value; break; default: break; } plan.Type.value = this.rbPlanType.SelectedValue; if (plan.Type.ToInt32() > 3) { plan.Type.set(plan.Type.ToInt32() - 3); } if (Request["rtype"] != null && Request["rtype"] != "") { plan.RangeType.value = planrtype.SelectedValue; } else { plan.RangeType.value = 1; } int id = plan.Insert(true); ULCode.Debug.Alert(this, "计划提交成功!请添加计划任务,完成后在[我的计划]默认页提交审核!", "Plan_EditPlan.aspx?PlanId=" + id); } }