/// <summary> /// 编辑情况下组装sql的方法 /// </summary> /// <param name="listSql"></param> /// <param name="purchase_billing_id"></param> /// <param name="model"></param> private void EditAllotBillSql(List<SysSQLString> listSql, tb_parts_stock_allot AllotEntity, string AllotBillIdValue, string HandleType) { try { const string NoDelFlag = "1";//默认删除标记,1表示未删除,0表示删除 string Save = DataSources.GetDescription(DataSources.EnumOperateType.save, true);//保存操作 string Submit = DataSources.GetDescription(DataSources.EnumOperateType.submit, true);//提交操作 SysSQLString sysStrSql = new SysSQLString(); sysStrSql.cmdType = CommandType.Text;//sql字符串语句执行函数 Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数 CommonFuncCall.FillEntityByControls(this, AllotBillEntity); AllotEntity.handle = GlobalStaticObj.UserID; AllotEntity.operators = GlobalStaticObj.UserID; AllotEntity.enable_flag = NoDelFlag; if (HandleType == Save) { AllotEntity.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.DRAFT).ToString(); AllotEntity.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.DRAFT, true); } else if (HandleType == Submit) { AllotEntity.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.SUBMIT).ToString(); AllotEntity.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.SUBMIT, true); } if (AllotBillEntity != null) { StringBuilder sb = new StringBuilder(); sb.Append(" Update " + AllotBillTable + " Set "); bool isFirstValue = true; foreach (PropertyInfo info in AllotEntity.GetType().GetProperties()) { string name = info.Name; object value = info.GetValue(AllotEntity, null); if (isFirstValue) { isFirstValue = false; sb.Append(name); sb.Append("="); sb.Append("@" + name); } else { sb.Append("," + name); sb.Append("="); sb.Append("@" + name); } dicParam.Add(name, value == null ? "" : value.ToString()); } sb.Append(" where " + AllotBillId + "='" + AllotBillIdValue + "';"); sysStrSql.sqlString = sb.ToString(); sysStrSql.Param = dicParam; listSql.Add(sysStrSql);//完成SQL语句的拼装 } } catch (Exception ex) { MessageBoxEx.Show(ex.Message,"异常提示",MessageBoxButtons.OK,MessageBoxIcon.Question); } }
/// <summary> /// 添加情况下组装sql的方法 /// </summary> /// <param name="listSql"></param> /// <param name="purchase_billing_id"></param> private void AddAllotBillSql(List<SysSQLString> listSql, tb_parts_stock_allot AllotEntity, string StockAllotId, string HandleType) { try { const string NoDelFlag = "1";//默认删除标记1表示未删除,0表示删除 string Save = DataSources.GetDescription(DataSources.EnumOperateType.save, true);//保存操作 string Submit = DataSources.GetDescription(DataSources.EnumOperateType.submit, true);//提交操作 //SQL语句拼装操作 SysSQLString sysStringSql = new SysSQLString(); sysStringSql.cmdType = CommandType.Text; Dictionary<string, string> dicParam = new Dictionary<string, string>();//保存SQL语句参数值 CommonFuncCall.FillEntityByControls(this, AllotEntity); AllotEntity.stock_allot_id = StockAllotId; AllotEntity.update_by = GlobalStaticObj.UserID; AllotEntity.operators = GlobalStaticObj.UserID; AllotEntity.enable_flag = NoDelFlag; if (HandleType == Save) { AllotEntity.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.DRAFT).ToString(); AllotEntity.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.DRAFT, true); } else if (HandleType == Submit) { AllotEntity.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.SUBMIT).ToString(); AllotEntity.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.SUBMIT, true); } if (AllotEntity != null) { StringBuilder sb = new StringBuilder(); sb.Append(" Insert Into " + AllotBillTable + "( "); StringBuilder sb_PrValue = new StringBuilder(); StringBuilder sb_PrName = new StringBuilder(); foreach (PropertyInfo info in AllotEntity.GetType().GetProperties()) { string name = info.Name; object value = info.GetValue(AllotEntity, null); sb_PrName.Append("," + name);//数据表字段名 sb_PrValue.Append(",@" + name);//数据表字段值 dicParam.Add(name, value == null ? "" : value.ToString()); } sb.Append(sb_PrName.ToString().Substring(1, sb_PrName.ToString().Length - 1) + ") Values (");//追加字段名 sb.Append(sb_PrValue.ToString().Substring(1, sb_PrValue.ToString().Length - 1) + ");");//追加字段值 //完成SQL语句的拼装 sysStringSql.sqlString = sb.ToString(); sysStringSql.Param = dicParam; listSql.Add(sysStringSql); } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question); } }