/// <summary> /// 编辑情况下组装sql的方法 /// </summary> /// <param name="listSql"></param> /// <param name="purchase_billing_id"></param> /// <param name="model"></param> private void EditModifyBillSql(List<SysSQLString> listSql, tb_parts_stock_modifyprice ModyPricEntity, string ModyPricId, 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, ModifyPriceBillEntity); ModyPricEntity.handle = GlobalStaticObj.UserID; ModyPricEntity.operators = GlobalStaticObj.UserID; ModyPricEntity.enable_flag = NoDelFlag; if (HandleType == Save) { ModyPricEntity.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.DRAFT).ToString(); ModyPricEntity.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.DRAFT, true); } else if (HandleType == Submit) { ModyPricEntity.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.SUBMIT).ToString(); ModyPricEntity.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.SUBMIT, true); } if (ModifyPriceBillEntity != null) { StringBuilder sb = new StringBuilder(); sb.Append(" Update tb_parts_stock_modifyprice Set "); bool isFirstValue = true; foreach (PropertyInfo info in ModyPricEntity.GetType().GetProperties()) { string name = info.Name; object value = info.GetValue(ModyPricEntity, 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 stock_modifyprice_id='" + ModyPricId + "';"); 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 AddModifyBillSql(List<SysSQLString> listSql, tb_parts_stock_modifyprice ModyPricEntity, string ModyPricId, 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, ModyPricEntity); ModyPricEntity.stock_modifyprice_id = ModyPricId; ModyPricEntity.update_by = GlobalStaticObj.UserID; ModyPricEntity.operators = GlobalStaticObj.UserID; ModyPricEntity.enable_flag = NoDelFlag; if (HandleType == Save) { ModyPricEntity.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.DRAFT).ToString(); ModyPricEntity.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.DRAFT, true); } else if (HandleType == Submit) { ModyPricEntity.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.SUBMIT).ToString(); ModyPricEntity.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.SUBMIT, true); } if (ModyPricEntity != null) { StringBuilder sb = new StringBuilder(); sb.Append(" Insert Into tb_parts_stock_modifyprice( "); StringBuilder sb_PrValue = new StringBuilder(); StringBuilder sb_PrName = new StringBuilder(); foreach (PropertyInfo info in ModyPricEntity.GetType().GetProperties()) { string name = info.Name; object value = info.GetValue(ModyPricEntity, 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); } }