/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.unBusinessMoneyLog model) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); List <SqlParameter> paras = new List <SqlParameter>(); strSql.Append("update MS_unBusinessMoneyLog set "); foreach (PropertyInfo pi in pros) { //如果不是主键则追加sql字符串 if (!pi.Name.Equals("ubml_id")) { //判断属性值是否为空 //if (pi.GetValue(model, null) != null) //{ //} str1.Append(pi.Name + "=@" + pi.Name + ","); //声明参数 paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值 } } strSql.Append(str1.ToString().Trim(',')); strSql.Append(" where ubml_id=@id "); paras.Add(new SqlParameter("@id", model.ubml_id)); return(DbHelperSQL.ExecuteSql(strSql.ToString(), paras.ToArray()) > 0); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.unBusinessMoneyLog GetModel(int id) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); Model.unBusinessMoneyLog model = new Model.unBusinessMoneyLog(); //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); foreach (PropertyInfo p in pros) { str1.Append(p.Name + ",");//拼接字段 } strSql.Append("select top 1 " + str1.ToString().Trim(',')); strSql.Append(" from MS_unBusinessMoneyLog"); strSql.Append(" where ubml_id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; DataTable dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0]; if (dt.Rows.Count > 0) { return(DataRowToModel(dt.Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public string Update(Model.unBusinessMoneyLog model, string content, Model.manager manager) { if (dal.Update(model)) { return(""); } return("更新失败"); }
/// <summary> /// 增加一条数据 /// </summary> public string Add(Model.unBusinessMoneyLog model) { if (dal.Add(model) > 0) { return(""); } return("添加失败"); }
/// <summary> /// 删除一条数据 /// </summary> public string Delete(int id) { Model.unBusinessMoneyLog model = GetModel(id); if (model == null) { return("数据不存在"); } if (dal.Delete(id)) { return(""); } return("删除失败"); }
/// <summary> /// 将对象转换实体 /// </summary> public Model.unBusinessMoneyLog DataRowToModel(DataRow row) { Model.unBusinessMoneyLog model = new Model.unBusinessMoneyLog(); if (row != null) { //利用反射获得属性的所有公共属性 Type modelType = model.GetType(); for (int i = 0; i < row.Table.Columns.Count; i++) { //查找实体是否存在列表相同的公共属性 PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName); if (proInfo != null && row[i] != DBNull.Value) { proInfo.SetValue(model, row[i], null);//用索引值设置属性值 } } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.unBusinessMoneyLog model) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); //数据字段 StringBuilder str2 = new StringBuilder(); //数据参数 //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); List <SqlParameter> paras = new List <SqlParameter>(); strSql.Append("insert into MS_unBusinessMoneyLog("); foreach (PropertyInfo pi in pros) { //如果不是主键则追加sql字符串 if (!pi.Name.Equals("ubml_id")) { //判断属性值是否为空 if (pi.GetValue(model, null) != null) { str1.Append(pi.Name + ","); //拼接字段 str2.Append("@" + pi.Name + ","); //声明参数 paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值 } } } strSql.Append(str1.ToString().Trim(',')); strSql.Append(") values ("); strSql.Append(str2.ToString().Trim(',')); strSql.Append(") "); strSql.Append(";select @@IDENTITY;"); object obj = DbHelperSQL.GetSingle(strSql.ToString(), paras.ToArray()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 审批非业务支付申请状态 /// </summary> /// <param name="id">记录ID</param> /// <param name="type">1部门审批,2财务审批,3总经理审批</param> /// <param name="status">0待审批,1审批未通过,2审批通过</param> /// <param name="remark">备注</param> /// <param name="username">操作人工号</param> /// <param name="realname">操作人姓名</param> /// <returns></returns> public string checkStatus(int id, byte?type, byte?status, string checkMoney, string remark, Model.manager adminModel) { Model.unBusinessApply model = GetModel(id); if (model == null) { return("记录不存在"); } //如果是员工往来,要验证对应的订单是否已经锁单,锁单的不能再审批 if (model.uba_type == 0 && !string.IsNullOrEmpty(model.uba_oid)) { Model.Order order = new BLL.Order().GetModel(model.uba_oid); if (order != null && order.o_lockStatus == 1) { return("订单已锁单,不能再审批"); } } //批复金额 decimal _checkmoney = 0, _oldmoney = model.uba_money.Value; string addremark = string.Empty, ubmlRemark = string.Empty; Model.unBusinessMoneyLog mlog = null; int ubmlID = 0; if (model.uba_function == "业务活动执行备用金借款" && !string.IsNullOrEmpty(checkMoney) && status == 2) { if (!decimal.TryParse(checkMoney, out _checkmoney)) { return("请正确填写批复金额"); } else { if (_checkmoney <= 0 || _checkmoney >= model.uba_money) { return("批复金额需大于0且小于申请金额(" + model.uba_money + ")"); } else { mlog = new Model.unBusinessMoneyLog(); mlog.ubml_ubaid = model.uba_id; mlog.ubml_newMoney = _checkmoney; mlog.ubml_oldMoney = model.uba_money; mlog.ubml_date = DateTime.Now; mlog.ubml_username = adminModel.user_name; mlog.ubml_realname = adminModel.real_name; addremark = "批复借款金额由原" + model.uba_money + "元改为" + _checkmoney + "元;"; model.uba_money = _checkmoney; } } } string content = ""; //3.如果是财务审批,要先验证部门审批是否已经审批通过,不通过不能审批;如果是总经理审批,要先验证财务审批是否已经审批通过,不通过不能审批 //4.反审批时:a.总经理要先验证是否已经确认支付。b.财务要先验证总经理是否已经审批通过。c.部门要先验证财务是否已经审批通过 switch (type) { case 1: //部门审批 if (model.uba_flag1 == status) { return("状态未改变"); } //判断有没有部门审批权限 if (model.uba_area != adminModel.area || !new permission().checkHasPermission(adminModel, "0603")) { return("无权限审批"); } content = "记录id:" + id + ",部门审批状态:" + Common.BusinessDict.checkStatus()[model.uba_flag1] + "→<font color='red'>" + Common.BusinessDict.checkStatus()[status] + "</font>"; model.uba_flag1 = status; model.uba_checkNum1 = adminModel.user_name; model.uba_checkName1 = adminModel.real_name; model.uba_checkRemark1 = remark; model.uba_checkTime1 = DateTime.Now; if (status == 2) { //由待审批、审批未通过→审批通过 //存在批复金额 if (model.uba_function == "业务活动执行备用金借款" && mlog != null) { mlog.ubml_type = 1; mlog.ubml_remark = "部门审批" + addremark; model.uba_checkRemark1 += "部门审批" + addremark; } } else { //由审批通过→待审批、审批未通过:验证财务审批是否通过,审批通过的不能再做部门反审批 if (model.uba_flag2 == 2) { return("财务已经审批通过,不能做部门审批"); } if (model.uba_function == "业务活动执行备用金借款") { //检查部门审批是否存在批复记录,存在则退回原来的金额 ubmlID = getOldMoney(model, 1, out ubmlRemark); if (!string.IsNullOrEmpty(ubmlRemark)) { model.uba_checkRemark1 = model.uba_checkRemark1.Replace(ubmlRemark, ""); } } } break; case 2: //财务审批 if (model.uba_flag2 == status) { return("状态未改变"); } if (new BLL.department().getGroupArea() != adminModel.area || !new permission().checkHasPermission(adminModel, "0402")) { return("无权限审批"); } content = "记录id:" + id + ",财务审批状态:" + Common.BusinessDict.checkStatus()[model.uba_flag2] + "→<font color='red'>" + Common.BusinessDict.checkStatus()[status] + "</font>"; model.uba_flag2 = status; model.uba_checkNum2 = adminModel.user_name; model.uba_checkName2 = adminModel.real_name; model.uba_checkRemark2 = remark; model.uba_checkTime2 = DateTime.Now; if (status == 2) { //由待审批、审批未通过→审批通过:验证部门审批是否存在待审批或审批未通过的记录,存在则不能做财务审批 if (model.uba_flag1 != 2) { return("部门审批是待审批或审批未通过的,不能做财务审批"); } //存在批复金额 if (model.uba_function == "业务活动执行备用金借款" && mlog != null) { mlog.ubml_type = 2; mlog.ubml_remark = "财务审批" + addremark; model.uba_checkRemark2 += "财务审批" + addremark; } } else { //由审批通过→待审批、审批未通过:验证总经理审批是否通过,审批通过的不能再做财务反审批 if (model.uba_flag3 == 2) { return("总经理已经审批通过,不能做财务审批"); } if (model.uba_function == "业务活动执行备用金借款") { //检查部门审批是否存在批复记录,存在则退回原来的金额 ubmlID = getOldMoney(model, 2, out ubmlRemark); if (!string.IsNullOrEmpty(ubmlRemark)) { model.uba_checkRemark2 = model.uba_checkRemark2.Replace(ubmlRemark, ""); } } } break; case 3: //总经理审批 if (model.uba_flag3 == status) { return("状态未改变"); } if (new BLL.department().getGroupArea() != adminModel.area || !new permission().checkHasPermission(adminModel, "0601")) { return("无权限审批"); } content = "记录id:" + id + ",总经理审批状态:" + Common.BusinessDict.checkStatus()[model.uba_flag3] + "→<font color='red'>" + Common.BusinessDict.checkStatus()[status] + "</font>"; model.uba_flag3 = status; model.uba_checkNum3 = adminModel.user_name; model.uba_checkName3 = adminModel.real_name; model.uba_checkRemark3 = remark; model.uba_checkTime3 = DateTime.Now; if (status == 2) { //由待审批、审批未通过→审批通过:验证财务审批是否存在待审批或审批未通过的记录,存在则不能做总经理审批 if (model.uba_flag2 != 2) { return("财务审批是待审批或审批未通过的,不能做总经理审批"); } //存在批复金额 if (model.uba_function == "业务活动执行备用金借款" && mlog != null) { mlog.ubml_type = 3; mlog.ubml_remark = "总经理审批" + addremark; model.uba_checkRemark3 += "总经理审批" + addremark; } } else { //由审批通过→待审批、审批未通过:验证是否已经确认支付,已经确认支付的不能做总经理审批 if (model.uba_isConfirm.Value) { return("已经确认支付,不能做总经理审批"); } if (model.uba_function == "业务活动执行备用金借款") { //检查部门审批是否存在批复记录,存在则退回原来的金额 ubmlID = getOldMoney(model, 3, out ubmlRemark); if (!string.IsNullOrEmpty(ubmlRemark)) { model.uba_checkRemark3 = model.uba_checkRemark3.Replace(ubmlRemark, ""); } } } break; } if (dal.Update(model)) { //写日志 Model.business_log log = new Model.business_log(); log.ol_title = "审批非业务支付申请状态"; log.ol_content = content; new business_log().Add(DTEnums.ActionEnum.Audit.ToString(), log, adminModel.user_name, adminModel.real_name); //插入批复金额记录 if (mlog != null) { new unBusinessMoneyLog().Add(mlog); } //删除已经批复的记录 if (ubmlID > 0) { new unBusinessMoneyLog().Delete(ubmlID); } #region 审批未通过、审批通过时通知 if (status == 1 || status == 2) { string replaceUser1 = ""; string nodeName = string.Empty; DataTable dt = null; string replaceContent = model.uba_money + "," + model.uba_function; string replaceUser = adminModel.user_name + "," + adminModel.real_name; if (status == 1) { nodeName = "非业务付款通知部门审批、财务审批、总经理未通过"; } else { if (type == 3)//总经理审批完成 { nodeName = "非业务付款通知总经理审批通过"; } else { nodeName = "非业务付款通知部门审批、财务审批通过"; if (type == 1) { dt = new manager().getUserByPermission("0402").Tables[0]; } else { dt = new manager().getUserByPermission("0601").Tables[0]; } if (dt != null) { foreach (DataRow dr in dt.Rows) { replaceUser1 += dr["user_name"] + "(" + dr["real_name"] + "),"; } } replaceUser1 = replaceUser1.TrimEnd(','); } } //钉钉通知申请人 Model.manager_oauth oauthModel = new BLL.manager_oauth().GetModel(model.uba_PersonNum); if (oauthModel != null && oauthModel.is_lock == 1 && !string.IsNullOrEmpty(oauthModel.oauth_userid)) { new BLL.selfMessage().sentDingMessage(nodeName, oauthModel.oauth_userid, replaceContent, replaceUser); } //通知下付款通知人 new BLL.selfMessage().AddMessage(nodeName, model.uba_PersonNum, model.uba_personName, replaceContent, replaceUser, replaceUser1); //通知下一级审批人 if (!string.IsNullOrEmpty(replaceUser1)) { foreach (DataRow dr in dt.Rows) { new BLL.selfMessage().AddMessage(nodeName, dr["user_name"].ToString(), dr["real_name"].ToString(), replaceContent, replaceUser, replaceUser1); //钉钉推送通知 if (!string.IsNullOrEmpty(Utils.ObjectToStr(dr["oauth_userid"]))) { new BLL.selfMessage().sentDingMessage(nodeName, dr["oauth_userid"].ToString(), replaceContent, replaceUser, replaceUser1); } } } } #endregion return(""); } return("操作失败"); }