/// <summary> /// 增加一条计划数据 /// </summary> public int Add(EccmPlanModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into eccm_plan("); strSql.Append("plan_cycle,plan_role,execution_frequency,execution_time,plan_build_time,plan_stime,plan_etime,term_day,uid,plan_creat_time,plan_stats,plan_type,choose_type,is_delete,ext1,ext2,ext3,communityID)"); strSql.Append(" values ("); strSql.Append("@plan_cycle,@plan_role,@execution_frequency,@execution_time,@plan_build_time,@plan_stime,@plan_etime,@term_day,@uid,@plan_creat_time,@plan_stats,@plan_type,@choose_type,@is_delete,@ext1,@ext2,@ext3,@communityID)"); MySqlParameter[] parameters = { new MySqlParameter("@plan_cycle", MySqlDbType.Int32, 11), new MySqlParameter("@plan_role", MySqlDbType.VarChar, 20), new MySqlParameter("@execution_frequency", MySqlDbType.Int32, 11), new MySqlParameter("@execution_time", MySqlDbType.Time), new MySqlParameter("@plan_build_time", MySqlDbType.Time), new MySqlParameter("@plan_stime", MySqlDbType.DateTime), new MySqlParameter("@plan_etime", MySqlDbType.DateTime), new MySqlParameter("@term_day", MySqlDbType.Int32, 11), new MySqlParameter("@uid", MySqlDbType.Int32, 11), new MySqlParameter("@plan_creat_time", MySqlDbType.DateTime), new MySqlParameter("@plan_stats", MySqlDbType.Int32, 11), new MySqlParameter("@plan_type", MySqlDbType.Int32, 11), new MySqlParameter("@choose_type", MySqlDbType.Int32, 11), new MySqlParameter("@is_delete", MySqlDbType.Int32, 11), new MySqlParameter("@ext1", MySqlDbType.VarChar, 50), new MySqlParameter("@ext2", MySqlDbType.VarChar, 50), new MySqlParameter("@ext3", MySqlDbType.VarChar, 50), new MySqlParameter("@communityID", MySqlDbType.Int32, 11) }; parameters[0].Value = model.plan_cycle; parameters[1].Value = model.plan_role; parameters[2].Value = model.execution_frequency; parameters[3].Value = model.execution_time; parameters[4].Value = model.plan_build_time; parameters[5].Value = model.plan_stime; parameters[6].Value = model.plan_etime; parameters[7].Value = model.term_day; parameters[8].Value = model.uid; parameters[9].Value = model.plan_creat_time; parameters[10].Value = model.plan_stats; parameters[11].Value = model.plan_type; parameters[12].Value = model.choose_type; parameters[13].Value = model.is_delete; parameters[14].Value = model.ext1; parameters[15].Value = model.ext2; parameters[16].Value = model.ext3; parameters[17].Value = model.communityID; int rows = MySQLHelper.ExecuteNonQuery(strSql.ToString(), parameters); if (rows > 0) { string sql = "select max(plan_id) from eccm_plan;";//获取计划id int i = Convert.ToInt32(MySQLHelper.ExecuteScalar(sql, null)); return(i); } else { return(0); } }
/// <summary> /// 生成一个维保工单 /// </summary> /// <param name="plan_model">计划对象</param> public static void AddMaintenanceOrder(EccmPlanModel plan_model) { EccmPlanBLL plan_bll = new EccmPlanBLL(); //获取设备 string equCodes = ""; DataTable dt = plan_bll.GetPlanDeviceCode(plan_model.plan_id, Convert.ToInt32(plan_model.choose_type)); for (int i = 0; i < dt.Rows.Count; i++) { equCodes += dt.Rows[i][0].ToString() + ","; } equCodes = equCodes.Substring(0, equCodes.Length - 1); //生成工单 EccmMaintenanceOrderModel model = new EccmMaintenanceOrderModel(); model.order_sn = GetOrderSN("WB"); model.order_stats = 0; model.order_time = DateTime.Now; model.order_type = 0; model.term_order = DateTime.Now.AddDays(Convert.ToInt32(plan_model.term_day)); model.community_id = Convert.ToInt32(plan_model.communityID); model.uid = Convert.ToInt32(plan_model.uid); model.plan_id = plan_model.plan_id; EccmMaintenanceOrderBLL order_bll = new EccmMaintenanceOrderBLL(); PlanLog(plan_model, order_bll.Add(model, equCodes)); }
/// <summary> /// 更改计划状态 /// </summary> public bool UpdataStates(EccmPlanModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update eccm_plan set "); strSql.Append("plan_stats=@plan_stats"); strSql.Append(" where plan_id=@plan_id"); MySqlParameter[] parameters = { new MySqlParameter("@plan_stats", MySqlDbType.Int32, 11), new MySqlParameter("@plan_id", MySqlDbType.Int32, 11) }; parameters[0].Value = model.plan_stats; parameters[1].Value = model.plan_id; int rows = MySQLHelper.ExecuteNonQuery(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更改计划状态 /// </summary> /// <param name="context"></param> /// <returns></returns> private string UpdateStates(HttpContext context) { var jr = new JsonResultModel <int>() { IsSucceed = false, Data = 0, Msg = "更改失败", RedirectUrl = string.Empty }; //获取传递参数 string planID = context.Request.Params["planid"]; string states = context.Request.Params["planstats"]; EccmPlanModel model = new EccmPlanModel(); model.plan_id = int.Parse(planID); model.plan_stats = int.Parse(states); EccmPlanBLL bll = new EccmPlanBLL(); if (bll.UpdataStates(model))//更改计划状态 { jr.IsSucceed = true; jr.Msg = "更改成功"; } return(JsonConvert.SerializeObject(jr)); }
/// <summary> /// 删除计划 /// </summary> /// <param name="context"></param> /// <returns></returns> private string DeletePlan(HttpContext context) { var jr = new JsonResultModel <int>() { IsSucceed = false, Data = 0, Msg = "删除失败", RedirectUrl = string.Empty }; //获取传递参数 string planID = context.Request.Params["planID"]; EccmPlanModel model = new EccmPlanModel(); model.plan_id = int.Parse(planID); model.is_delete = 1; EccmPlanBLL bll = new EccmPlanBLL(); if (bll.Delete(model))//删除该id计划 { jr.IsSucceed = true; jr.Msg = "删除成功"; } return(JsonConvert.SerializeObject(jr)); }
/// <summary> /// 时间逻辑处理:判断是否生成新订单 /// </summary> /// <param name="plan_model">计划对象</param> /// <param name="now_time">当前时间</param> /// <param name="order_time">最后一次订单生成时间</param> /// <returns></returns> public static bool TimeLogic(EccmPlanModel plan_model, DateTime now_time, DateTime order_time) { bool is_order = false; if (plan_model.plan_role == "0")//规则:年 { int year = now_time.Year - order_time.Year; if (year == Convert.ToInt32(plan_model.execution_frequency))//当前时间-最后一次生成工单时间=计划的间隔时间,就需要生成新的工单 { is_order = true; } } else if (plan_model.plan_role == "1")//规则:季 { int Month = (now_time.Year - order_time.Year) * 12 + (now_time.Month - order_time.Month); if (Month == Convert.ToInt32(plan_model.execution_frequency) * 3)//当前时间-最后一次生成工单时间=计划的间隔时间,就需要生成新的工单 { is_order = true; } } else if (plan_model.plan_role == "2")//规则:月 { int Month = (now_time.Year - order_time.Year) * 12 + (now_time.Month - order_time.Month); if (Month == Convert.ToInt32(plan_model.execution_frequency))//当前时间-最后一次生成工单时间=计划的间隔时间,就需要生成新的工单 { is_order = true; } } else if (plan_model.plan_role == "3") //规则:周 { DateTime dt = GetMondayDate(Convert.ToDateTime(order_time).AddDays(Convert.ToInt32(plan_model.execution_frequency) * 7)); //获取下一个周期 星期一的日期 if (DateTime.Now.ToShortDateString() == dt.ToShortDateString()) //如果当前日期=下个周期星期一日期则生成 { is_order = true; } } else if (plan_model.plan_role == "5")//规则:日 { TimeSpan ts = now_time - order_time; if (Convert.ToInt32(ts.TotalDays) == Convert.ToInt32(plan_model.execution_frequency))//当前时间-最后一次生成工单时间=计划的间隔时间,就需要生成新的工单 { is_order = true; } } else { } return(is_order); }
/// <summary> /// 生成工单记录日志 /// </summary> /// <param name="plan_model"></param> /// <param name="b"></param> public static void PlanLog(EccmPlanModel plan_model, bool b) { if (b) { string msg = "计划生成日志:计划id为" + plan_model.plan_id + "生成一个新的"; msg += plan_model.plan_type == 1 ? "巡检" : "维保"; msg += "工单成功"; LogHelper.Dbbug(msg); } else { string msg = "计划生成日志:计划id为" + plan_model.plan_id + "生成一个新的"; msg += plan_model.plan_type == 1 ? "巡检" : "维保"; msg += "工单失败"; LogHelper.Dbbug(msg); } }
/// <summary> /// 获取计划列表 /// </summary>" ", /// <param name="strWhere">筛选条件</param> /// <returns></returns> public List<EccmPlanModel> GetPlanList() { StringBuilder sql = new StringBuilder(); sql.Append(" select * from eccm_plan p"); sql.Append(" WHERE p.plan_stime<='" + DateTime.Now.ToShortDateString() + "' AND p.is_delete=0 AND p.plan_stats=1 AND ( p.plan_etime>='" + DateTime.Now.ToShortDateString() + "' OR p.plan_etime IS NULL)"); DataTable dt = MySQLHelper.ExecuteToDataTable(sql.ToString(), null); List<EccmPlanModel> list = new List<EccmPlanModel>(); foreach (DataRow row in dt.Rows) { EccmPlanModel model = DataRowToModel(row); list.Add(model); } return list; }
/// <summary> /// 更改计划状态 /// </summary> public bool UpdataStates(EccmPlanModel model) { return(dal.UpdataStates(model)); }
/// <summary> /// 删除一条数据 /// </summary> public bool Delete(EccmPlanModel model) { return(dal.Delete(model)); }
/// <summary> /// 增加一条计划数据 /// </summary> public int Add(EccmPlanModel model) { return(dal.Add(model)); }
/// <summary> /// 得到一个对象实体 /// </summary> public EccmPlanModel DataRowToModel(DataRow row) { EccmPlanModel model = new EccmPlanModel(); if (row != null) { if (row["plan_id"] != null && row["plan_id"].ToString() != "") { model.plan_id = int.Parse(row["plan_id"].ToString()); } if (row["plan_cycle"] != null && row["plan_cycle"].ToString() != "") { model.plan_cycle = int.Parse(row["plan_cycle"].ToString()); } if (row["plan_role"] != null) { model.plan_role = row["plan_role"].ToString(); } if (row["execution_frequency"] != null && row["execution_frequency"].ToString() != "") { model.execution_frequency = int.Parse(row["execution_frequency"].ToString()); } if (row["execution_time"] != null && row["execution_time"].ToString() != "") { model.execution_time = DateTime.Parse(row["execution_time"].ToString()); } if (row["plan_build_time"] != null && row["plan_build_time"].ToString() != "") { model.plan_build_time = DateTime.Parse(row["plan_build_time"].ToString()); } if (row["plan_stime"] != null && row["plan_stime"].ToString() != "") { model.plan_stime = DateTime.Parse(row["plan_stime"].ToString()); } if (row["plan_etime"] != null && row["plan_etime"].ToString() != "") { model.plan_etime = DateTime.Parse(row["plan_etime"].ToString()); } if (row["term_day"] != null && row["term_day"].ToString() != "") { model.term_day = int.Parse(row["term_day"].ToString()); } if (row["uid"] != null && row["uid"].ToString() != "") { model.uid = int.Parse(row["uid"].ToString()); } if (row["plan_creat_time"] != null && row["plan_creat_time"].ToString() != "") { model.plan_creat_time = DateTime.Parse(row["plan_creat_time"].ToString()); } if (row["plan_stats"] != null && row["plan_stats"].ToString() != "") { model.plan_stats = int.Parse(row["plan_stats"].ToString()); } if (row["plan_type"] != null && row["plan_type"].ToString() != "") { model.plan_type = int.Parse(row["plan_type"].ToString()); } if (row["choose_type"] != null && row["choose_type"].ToString() != "") { model.choose_type = int.Parse(row["choose_type"].ToString()); } if (row["is_delete"] != null && row["is_delete"].ToString() != "") { model.is_delete = int.Parse(row["is_delete"].ToString()); } if (row["ext1"] != null) { model.ext1 = row["ext1"].ToString(); } if (row["ext2"] != null) { model.ext2 = row["ext2"].ToString(); } if (row["ext3"] != null) { model.ext3 = row["ext3"].ToString(); } if (row["communityID"] != null && row["communityID"].ToString() != "") { model.communityID = int.Parse(row["communityID"].ToString()); } } return model; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(EccmPlanModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update eccm_plan set "); strSql.Append("plan_cycle=@plan_cycle,"); strSql.Append("plan_role=@plan_role,"); strSql.Append("execution_frequency=@execution_frequency,"); strSql.Append("execution_time=@execution_time,"); strSql.Append("plan_build_time=@plan_build_time,"); strSql.Append("plan_stime=@plan_stime,"); strSql.Append("plan_etime=@plan_etime,"); strSql.Append("term_day=@term_day,"); strSql.Append("uid=@uid,"); strSql.Append("plan_stats=@plan_stats,"); strSql.Append("plan_type=@plan_type,"); strSql.Append("choose_type=@choose_type,"); strSql.Append("is_delete=@is_delete,"); strSql.Append("ext1=@ext1,"); strSql.Append("ext2=@ext2,"); strSql.Append("ext3=@ext3,"); strSql.Append("communityID=@communityID"); strSql.Append(" where plan_id=@plan_id"); MySqlParameter[] parameters = { new MySqlParameter("@plan_cycle", MySqlDbType.Int32, 11), new MySqlParameter("@plan_role", MySqlDbType.VarChar, 20), new MySqlParameter("@execution_frequency", MySqlDbType.Int32, 11), new MySqlParameter("@execution_time", MySqlDbType.Time), new MySqlParameter("@plan_build_time", MySqlDbType.Time), new MySqlParameter("@plan_stime", MySqlDbType.DateTime), new MySqlParameter("@plan_etime", MySqlDbType.DateTime), new MySqlParameter("@term_day", MySqlDbType.Int32, 11), new MySqlParameter("@uid", MySqlDbType.Int32, 11), new MySqlParameter("@plan_stats", MySqlDbType.Int32, 11), new MySqlParameter("@plan_type", MySqlDbType.Int32, 11), new MySqlParameter("@choose_type", MySqlDbType.Int32, 11), new MySqlParameter("@is_delete", MySqlDbType.Int32, 11), new MySqlParameter("@ext1", MySqlDbType.VarChar, 50), new MySqlParameter("@ext2", MySqlDbType.VarChar, 50), new MySqlParameter("@ext3", MySqlDbType.VarChar, 50), new MySqlParameter("@communityID", MySqlDbType.Int32, 11), new MySqlParameter("@plan_id", MySqlDbType.Int32, 11) }; parameters[0].Value = model.plan_cycle; parameters[1].Value = model.plan_role; parameters[2].Value = model.execution_frequency; parameters[3].Value = model.execution_time; parameters[4].Value = model.plan_build_time; parameters[5].Value = model.plan_stime; parameters[6].Value = model.plan_etime; parameters[7].Value = model.term_day; parameters[8].Value = model.uid; parameters[9].Value = model.plan_stats; parameters[10].Value = model.plan_type; parameters[11].Value = model.choose_type; parameters[12].Value = model.is_delete; parameters[13].Value = model.ext1; parameters[14].Value = model.ext2; parameters[15].Value = model.ext3; parameters[16].Value = model.communityID; parameters[17].Value = model.plan_id; int rows = MySQLHelper.ExecuteNonQuery(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 添加计划 /// </summary> /// <param name="context"></param> /// <returns></returns> private string AddPlan(HttpContext context) { var jr = new JsonResultModel <int>() { IsSucceed = false, Data = 0, Msg = "添加失败", RedirectUrl = string.Empty }; #region 递参数处理为对象 //获取传递参数 string plancycle = context.Request.Params["plancycle"]; string planrole = context.Request.Params["planrole"]; string executionfrequency = context.Request.Params["executionfrequency"]; string term_day = context.Request.Params["term_day"]; string planstime = context.Request.Params["planstime"]; string planetime = context.Request.Params["planetime"]; string communityID = context.Request.Params["communityID"]; string planstats = context.Request.Params["planstats"]; string choosetype = context.Request.Params["choosetype"]; string plantype = context.Request.Params["plantype"]; string Codes = context.Request.Params["Codes"]; EccmPlanModel model = new EccmPlanModel(); model.plan_cycle = int.Parse(plancycle); model.plan_role = planrole; model.execution_frequency = int.Parse(executionfrequency); model.term_day = int.Parse(term_day); model.plan_stime = DateTime.Parse(planstime); if (planetime != "") { model.plan_etime = DateTime.Parse(planetime); } model.communityID = int.Parse(communityID); model.plan_stats = int.Parse(planstats); model.choose_type = int.Parse(choosetype); model.plan_type = int.Parse(plantype); model.plan_creat_time = DateTime.Now; model.is_delete = 0; #endregion HttpCookie cook = HttpContext.Current.Request.Cookies["EccmUserinfo"]; if (cook != null) { //解密Cookie HttpCookie decodeCookie = HttpSecureCookie.Decode(cook); string uid = decodeCookie.Values["userid"]; //给对象赋值 model.uid = int.Parse(uid); } EccmPlanBLL bll = new EccmPlanBLL(); int id = bll.Add(model); //添加计划并获取id if (id > 0) //添加计划成功 { if (model.choose_type == 0) //设备类型 { EccmPlanDevicetypeModel pdt_model = new EccmPlanDevicetypeModel(); pdt_model.community_id = model.communityID; pdt_model.plan_id = id; pdt_model.system_type_code = Codes; EccmPlanDevicetypeBLL pdt_bll = new EccmPlanDevicetypeBLL(); if (pdt_bll.Add(pdt_model)) { jr.IsSucceed = true; jr.Msg = "添加成功"; } } else if (model.choose_type == 1)//设备 { EccmPlanDeviceModel pd_model = new EccmPlanDeviceModel(); pd_model.community_id = model.communityID; pd_model.plan_id = id; pd_model.equCode = Codes; EccmPlanDeviceBLL pd_bll = new EccmPlanDeviceBLL(); if (pd_bll.Add(pd_model)) { jr.IsSucceed = true; jr.Msg = "添加成功"; } } } return(JsonConvert.SerializeObject(jr)); }