/// <summary> /// 执行业务过程处理 /// </summary> /// <returns></returns> private bool ExecBusinessProcess() { InitMasterParams();//初始主表参数 //SetParameter("LastUpdateTime", "datetime", GetServerDateTime());//重取一次LastUpdateTime if (NeedTranscation) { Bss_Helper.BeginTrans();//开始事务 } foreach (BusinessObject bis in ProcessObjects) { try { if (!bis.Repeated) //不是循环执行,直接提交 { bis.DoValidate(paras, this); //执行语句提交 continue; //直接进入下一个业务语句 } DataTable dtDetail = null; //当前处理循环的从表 int rowItem = 0; //当前从表循环的记录 do //进入循环执行从表数据提交 { string[] sqlParams = DBHelper.GetSqlTextParams(bis.Sql); //取出当前语句的参数 if (sqlParams != null && sqlParams.Count() > 0) //语句有参数,需要参数赋值 { foreach (string ParamName in sqlParams) { if (SysParams2.Contains <string>(ParamName)) { continue;//系统参数不处理 } if (dtDetail == null) { dtDetail = GetDataObjectTable(ParamName, dsDataObject);//按第一个参数从表 } if (dtDetail == null || dtDetail.TableName == "Master") { dtDetail = null; continue; //没有到参数赋值,直接进入下一个参数;主表参数无需重新赋值 } if (dtDetail.Rows.Count == 0) //当前从表没有数据,跳出执行,返回到下一个业务处理 { break; //foreach } if (dtDetail.Columns.Contains(ParamName)) //表存在参数值 { if (ParamName.IndexOf("UpdateFlag") != -1) { string val = string.Empty; if (dtDetail.Rows[rowItem].RowState == DataRowState.Added) { val = "I"; } else if (dtDetail.Rows[rowItem].RowState == DataRowState.Modified) { val = "U"; } else if (dtDetail.Rows[rowItem].RowState == DataRowState.Deleted) { val = "D"; } SetParameter(ParamName, "string", val); } else { //SetParameter(ParamName, dtDetail.Rows[rowItem][ParamName]); if (dtDetail.Rows[rowItem].RowState == DataRowState.Deleted) { SetParameter(ParamName, dtDetail.Rows[rowItem][ParamName, DataRowVersion.Original]); } else { SetParameter(ParamName, dtDetail.Rows[rowItem][ParamName]); } } } } } if (dtDetail != null && dtDetail.Rows.Count > 0) //当前从表有数据才处理 { bis.DoValidate(paras, this); //执行语句提交 } rowItem++; //doWhile:; } while (dtDetail != null && rowItem < dtDetail.Rows.Count);//循环完毕后继续下一个业务语句处理 } catch (Exception ex) { if (NeedTranscation) { Bss_Helper.RollBack(); } throw new RFException("执行【" + FormatSummary(bis.Summary) + "】错误:" + ex.Message); } } if (NeedTranscation) { Bss_Helper.Commit();//事务提交 } //主表LastUpdateTime更新 if (dsDataObject.Tables.IndexOf("Master") != -1) { DataTable dtMaster = dsDataObject.Tables["Master"]; if (dtMaster != null && dtMaster.Columns.Contains("LastUpdateTime")) { dtMaster.Rows[dtMaster.Rows.Count - 1].BeginEdit(); dtMaster.Rows[dtMaster.Rows.Count - 1]["LastUpdateTime"] = GetParameter("LastUpdateTime"); dtMaster.Rows[dtMaster.Rows.Count - 1].EndEdit(); } } //提交内存表所有数据 for (int n = 0; n < dsDataObject.Tables.Count; n++) { dsDataObject.Tables[n].AcceptChanges(); } return(true); }
/// <summary> /// 执行业务检查处理 /// </summary> /// <returns></returns> private bool ExecBusinessCheck() { InitMasterParams();//初始主表参数 foreach (CheckObject obj in CheckObjects) { if (obj.Index <= CheckIndex) { continue; //2018-05-29继续执行的控制,少于当前项的不执行,因为是继续执行,从下个起点开始前面无需重复执行 } if (!obj.Repeated) //不是从表参数,即主表参数,直接执行 { CurrentValidateParam = obj.ValidateParamName; //返回检查失败的参数 obj.DoValidate(paras /*, DataDic*/); //执行业务检查 CurrentValidateParam = string.Empty; } else//执行从表参数检查 { DataTable dtDetail = null;//记录当前参数循环的从表 string[] sqlParams = DBHelper.GetSqlTextParams(obj.Sql); //取出当前语句的参数 dtDetail = GetDataObjectTable(obj.ValidateParamName, dsDataObject); //取当前参数的表 if (dtDetail != null && dtDetail.TableName.IndexOf("Detail") != -1 && dtDetail.Rows.Count > 0) { //找到从表并有记录 switch (obj.ValidateType) { case "Query": case "SQL": case "QueryGrid": foreach (DataRow dr in dtDetail.Rows) { foreach (string ParamName in sqlParams) { if (dtDetail.Columns.Contains(ParamName)) { if (ParamName.IndexOf("UpdateFlag") != -1) { string val = string.Empty; if (dr.RowState == DataRowState.Added) { val = "I"; } else if (dr.RowState == DataRowState.Modified) { val = "U"; } else if (dr.RowState == DataRowState.Deleted) { val = "D"; } SetParameter(ParamName, "string", val); } else { SetParameter(ParamName, dr[ParamName]); } } } CurrentValidateParam = obj.ValidateParamName; //返回检查失败的参数 obj.DoValidate(paras /*, DataDic*/); //执行业务检查 CurrentValidateParam = string.Empty; } break; default: foreach (DataRow dr in dtDetail.Rows) { if (dtDetail.Columns.Contains(obj.ValidateParamName)) { SetParameter(obj.ValidateParamName, dr[obj.ValidateParamName]); } CurrentValidateParam = obj.ValidateParamName; //返回检查失败的参数 obj.DoValidate(paras /*, DataDic*/); //执行业务检查 CurrentValidateParam = string.Empty; } break; } } else { throw new RFException(AlertMessage.Business_RepeatedParamsError); } } } //foreach (CheckObject obj in CheckObjects) //{ // if (obj.Index <= CheckIndex) continue;//2018-05-29继续执行的控制,少于当前项的不执行,因为是继续执行,从下个起点开始前面无需重复执行 // switch (obj.ValidateType) // { // case "Required": // case "Query": // case "SQL": // case "QueryGrid": // DataTable dtDetail = null;//记录当前参数循环的从表 // string[] sqlParams = DBHelper.GetSqlTextParams(obj.Sql);//取出当前语句的参数 // dtDetail = GetDataObjectTable(obj.ValidateParamName, dsDataObject);//取当前参数的表 // if (dtDetail != null && dtDetail.TableName.IndexOf("Detail") != -1 && dtDetail.Rows.Count > 0) // { // foreach (DataRow dr in dtDetail.Rows) // { // foreach (string ParamName in sqlParams) // { // if (dtDetail.Columns.Contains(ParamName)) // { // if (ParamName.IndexOf("UpdateFlag") != -1) // { // string val = string.Empty; // if (dr.RowState == DataRowState.Added) // val = "I"; // else if (dr.RowState == DataRowState.Modified) // val = "U"; // else if (dr.RowState == DataRowState.Deleted) // val = "D"; // SetParameter(ParamName, "string", val); // } // else // { // SetParameter(ParamName, dr[ParamName]); // } // } // } // CurrentValidateParam = obj.ValidateParamName;//返回检查失败的参数 // obj.DoValidate(paras, DataDic);//执行业务检查 // CurrentValidateParam = string.Empty; // } // } // else // { // if (dtDetail == null || (dtDetail != null && dtDetail.TableName == "Master")) // { // CurrentValidateParam = obj.ValidateParamName;//返回检查失败的参数 // obj.DoValidate(paras, DataDic);//执行业务检查 // CurrentValidateParam = string.Empty; // } // } // break; // default: // CurrentValidateParam = obj.ValidateParamName;//返回检查失败的参数 // obj.DoValidate(paras, DataDic);//执行业务检查 // CurrentValidateParam = string.Empty; // break; // } //} return(true); }