private bool tryPost(ref Model.Instancenew model, out string errMsg) { errMsg = ""; bool re = false; model.Creater = this.auth.UserId; model.CreatedDate = DateTime.Now; if (InstanceManager.AddInstance(ref model, out errMsg)) { re = true; } return(re); }
private bool tryValidate(Model.Instancenew model, out string errMsg) { errMsg = ""; bool re = true; if (model.Car == 0 || model.Project == 0 || model.Department == 0 || model.UserName == null || model.UserName.Length == 0 || model.UserName.Length > 20 || model.Oils == null || model.Oils.Count == 0 || model.Goal.Length > 200 || model.StartDate == null || model.EndDate == null || model.StartInfo.Length > 200 || model.Creater == 0) { errMsg = "输入数据不合法"; re = false; } if (re && model.Creater != auth.UserId) { errMsg = "登录信息异常,请刷新浏览器以重启应用(APP请退出应用后重新打开)"; re = false; } return(re); }
/// <summary> /// 新建申请单 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool AddInstance(ref Model.Instancenew model, out string errMsg) { return(InstanceService.AddInstance(ref model, out errMsg)); }
/// <summary> /// 新建申请单 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool AddInstance(ref Model.Instancenew model, out string errMsg) { errMsg = ""; try { model.UserName = model.UserName.Trim(); int[] oils = model.Oils.ToArray(); string[] arrayOils = Array.ConvertAll(oils, delegate(int s) { return(s.ToString()); }); SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Car", model.Car), new SqlParameter("@Project", model.Project), new SqlParameter("@Department", model.Department), new SqlParameter("@UserName", model.UserName), new SqlParameter("@Oils", string.Join(",", arrayOils)), new SqlParameter("@Goal", model.Goal.Trim()), new SqlParameter("@StartDate", model.StartDate), new SqlParameter("@EndDate", model.EndDate), new SqlParameter("@StartInfo", model.StartInfo.Trim()), new SqlParameter("@Creater", model.Creater), new SqlParameter("@CreatedDate", model.CreatedDate), new SqlParameter("@OutState", SqlDbType.Int), new SqlParameter("@return", SqlDbType.Int) }; para[11].Direction = ParameterDirection.Output; para[12].Direction = ParameterDirection.ReturnValue; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, "proc_InstanceInsert", para); int outState = int.Parse(para[11].Value.ToString()); int returnValue = int.Parse(para[12].Value.ToString()); if (returnValue > 0) { EventLog e = new EventLog(); e.TargetIds = returnValue.ToString(); e.CodeTag = "AddInstance"; e.LogName = "新建申请单"; EventLogService.AddEventLog <Model.Instancenew>(e, model); return(true); } else { switch (outState) { case -100: errMsg = "起止时间设置有误"; break; case -1: errMsg = "添加申请单失败"; break; case -2: errMsg = "添加申请单履历失败"; break; case -3: errMsg = "更新车辆信息失败"; break; default: errMsg = "异常错误"; break; } ErrorLog e = new ErrorLog(); e.TargetIds = model.Car.ToString(); e.CodeTag = "AddInstance"; e.LogName = "新建申请单"; e.ErrorMsg = errMsg; ErrorLogService.AddErrorLog <Model.Instancenew>(e, model); return(false); } } catch (Exception ex) { errMsg = ex.Message; ErrorLog e = new ErrorLog(); e.TargetIds = "0"; e.CodeTag = "AddInstance"; e.LogName = "新建申请单"; e.ErrorMsg = ex.Message.ToString(); ErrorLogService.AddErrorLog <Model.Instancenew>(e, model); return(false); } }