/// <summary> 创建出入库单
        /// </summary>
        /// <param name="ordertype">单据类型</param>
        /// <param name="bill_model">采购开单信息</param>
        bool CreateIntoStock(string ordertype, tb_parts_purchase_billing bill_model, ref string stock_inout_id)
        {
            tb_parts_stock_inout stoct_inout_model = new tb_parts_stock_inout();
            Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数

            stoct_inout_model.stock_inout_id = Guid.NewGuid().ToString();
            stock_inout_id = stoct_inout_model.stock_inout_id;
            
            stoct_inout_model.order_date = Common.LocalDateTimeToUtcLong(Convert.ToDateTime(DateTime.Now.ToShortDateString()));
            stoct_inout_model.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.DRAFT).ToString();
            stoct_inout_model.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.DRAFT, true);
            if (ordertype == "入库单")
            {
                //stoct_inout_model.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.InBill);//获取入库单编号
                stoct_inout_model.order_type = Convert.ToInt32(DataSources.EnumAllocationBillType.Storage).ToString();//入库单类型编号
                stoct_inout_model.order_type_name = DataSources.GetDescription(DataSources.EnumAllocationBillType.Storage, true);//入库单类型名称
            }
            else if (ordertype == "出库单")
            {
                //stoct_inout_model.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.OutBill);//获取出库单编号
                stoct_inout_model.order_type = Convert.ToInt32(DataSources.EnumAllocationBillType.OutboundOrder).ToString();//出库单类型编号
                stoct_inout_model.order_type_name = DataSources.GetDescription(DataSources.EnumAllocationBillType.OutboundOrder, true);//出库单类型名称
            }
            stoct_inout_model.billing_type = Convert.ToInt32(DataSources.EnumAllocationBillingType.PurchaseBilling).ToString();//开单类型编号
            stoct_inout_model.billing_type_name = DataSources.GetDescription(DataSources.EnumAllocationBillingType.PurchaseBilling, true);//开单类型名称
            stoct_inout_model.arrival_place = bill_model.delivery_address;
            stoct_inout_model.bussiness_units = "";
            stoct_inout_model.com_id = GlobalStaticObj.CurrUserCom_Id;
            stoct_inout_model.com_name = GlobalStaticObj.CurrUserCom_Name;
            stoct_inout_model.org_id = bill_model.org_id;
            stoct_inout_model.org_name = bill_model.org_name;
            stoct_inout_model.handle = bill_model.handle;
            stoct_inout_model.handle_name = bill_model.handle_name;
            stoct_inout_model.operators = bill_model.operators;
            stoct_inout_model.operator_name = bill_model.operator_name;
            stoct_inout_model.create_by = GlobalStaticObj.UserID;
            stoct_inout_model.create_name = GlobalStaticObj.UserName;
            stoct_inout_model.create_time = Common.LocalDateTimeToUtcLong(DateTime.Now);
            stoct_inout_model.remark = "由单号为【" + bill_model.order_num + "】的采购开单生成";
            stoct_inout_model.enable_flag = "1";

            foreach (PropertyInfo info in stoct_inout_model.GetType().GetProperties())
            {
                string name = info.Name;
                object value = info.GetValue(stoct_inout_model, null);
                dicParam.Add(name, value == null ? "" : value.ToString());
            }
            return DBHelper.Submit_AddOrEdit("出入库单表添加信息", "tb_parts_stock_inout", "stock_inout_id", "", dicParam);
        }
        /// <summary>
        /// 审核通过后需要自动生成的单子的方法
        /// </summary>
        void CreateBill(List<string> listField)
        {
            try
            {
                if (listField.Count > 0)
                {
                    string bill_ids = string.Empty;
                    List<SysSQLString> listSql = new List<SysSQLString>();
                    DataTable TemplateTable = CommonFuncCall.CreatePartStatisticTable();//获取要填充的公用表
                    for (int i = 0; i < listField.Count; i++)
                    {
                        DataTable dt = DBHelper.GetTable("", "tb_parts_purchase_billing", "*", string.Format("purchase_billing_id='{0}'", listField[i]), "", "");
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            DataTable dt_bill_p = new DataTable();
                            tb_parts_purchase_billing model = new tb_parts_purchase_billing();
                            CommonFuncCall.SetModlByDataTable(model, dt);

                            #region 开单审核通过后,更新配件的账面库存
                            string str_time = Common.UtcLongToLocalDateTime(model.order_date).ToShortDateString();
                            long long_time = Common.LocalDateTimeToUtcLong(Convert.ToDateTime(str_time));
                            DataTable IOPartTable = DBHelper.GetTable("", "tb_parts_purchase_billing_p", "*", string.Format("purchase_billing_id='{0}'", listField[i]), "", "");
                            if (IOPartTable != null && IOPartTable.Rows.Count > 0)
                            {
                                for (int a = 0; a < IOPartTable.Rows.Count; a++)
                                {
                                    DataRow dr = TemplateTable.NewRow();//创建模版表行项
                                    dr["OrderDate"] = long_time.ToString();//单据日期
                                    dr["WareHouseID"] = CommonCtrl.IsNullToString(IOPartTable.Rows[a]["wh_id"]);//仓库ID
                                    dr["WareHouseName"] = CommonCtrl.IsNullToString(IOPartTable.Rows[a]["wh_name"]);//仓库名称
                                    dr["PartID"] = CommonCtrl.IsNullToString(IOPartTable.Rows[a]["parts_id"]);//配件ID
                                    dr["PartCode"] = IOPartTable.Rows[a]["parts_code"].ToString();//配件编码
                                    dr["PartName"] = IOPartTable.Rows[a]["parts_name"].ToString();//配件名称
                                    dr["PartSpec"] = IOPartTable.Rows[a]["model"].ToString();//配件规格
                                    dr["PartBarCode"] = IOPartTable.Rows[a]["parts_barcode"].ToString();//配件条码
                                    dr["CarPartsCode"] = IOPartTable.Rows[a]["car_factory_code"].ToString();//车厂编码
                                    dr["DrawNum"] = IOPartTable.Rows[a]["drawing_num"].ToString();//配件图号
                                    dr["UnitName"] = IOPartTable.Rows[a]["unit_name"].ToString();//单位名称
                                    //dr["PartCount"] = IOPartTable.Rows[a]["business_counts"].ToString();//配件业务数量
                                    dr["PartCount"] = Convert.ToDecimal(IOPartTable.Rows[a]["business_counts"].ToString());//配件业务数量
                                    dr["StatisticType"] = (int)DataSources.EnumStatisticType.PaperCount;//统计类型
                                    TemplateTable.Rows.Add(dr);//添加新的数据行项
                                }
                            }
                            #endregion

                            #region 当金额大于0时,自动生成预付款单
                            if (model.this_payment > 0)
                            {
                                tb_bill_receivable a = new tb_bill_receivable();
                                tb_balance_documents b = new tb_balance_documents();
                                tb_payment_detail c = new tb_payment_detail();
                                a.cust_id = model.sup_id;//供应商ID
                                a.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.PAYMENT);//订单号
                                a.order_type = (int)DataSources.EnumOrderType.PAYMENT;
                                a.payment_type = (int)DataSources.EnumPaymentType.PAYMENT;
                                a.org_id = model.org_id;

                                b.billing_money = model.this_payment;//开单金额
                                b.documents_date = model.order_date;//单据日期
                                b.documents_id = model.purchase_billing_id;//单据ID
                                b.documents_name = "采购开单";//单据名称
                                b.documents_num = model.order_num;//单据编码

                                c.money = model.this_payment;//金额
                                c.balance_way = model.balance_way;//结算方式
                                c.check_number = model.check_number;//票号

                                DBOperation.AddBillReceivable(a, b, c);
                            }
                            #endregion

                            #region 自动生产出入库单
                            #region 一:采购收货单(业务数量大于0)-->自动生成入库单
                            if (model.order_type ==  Convert.ToInt32(DataSources.EnumPurchaseOrderType.PurchaseReceive).ToString())
                            {
                                string stock_inout_id = string.Empty;
                                //1.生成入库单
                                if (CreateIntoStock("入库单", model, ref stock_inout_id))
                                {
                                    //2.查询配件信息,生成配件信息入库单
                                    DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", "");
                                    if (dt_parts != null && dt_parts.Rows.Count > 0)
                                    {
                                        dt_bill_p = dt_parts;
                                        for (int a = 0; a < dt_parts.Rows.Count; a++)
                                        {
                                            tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p();
                                            CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                            bool ret = CreateIntoPartsStock(stock_inout_id, bill_p_model, model.purchase_billing_id, model.order_num);
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region 二:采购退货(业务数量小于0)-->自动生成出库单
                            else if (model.order_type ==  Convert.ToInt32(DataSources.EnumPurchaseOrderType.PurchaseBack).ToString())
                            {
                                string stock_inout_id = string.Empty;
                                //1.生成出库单
                                if (CreateIntoStock("出库单", model, ref stock_inout_id))
                                {
                                    //2.查询配件信息,生成配件信息出库单
                                    DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", "");
                                    if (dt_parts != null && dt_parts.Rows.Count > 0)
                                    {
                                        for (int a = 0; a < dt_parts.Rows.Count; a++)
                                        {
                                            tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p();
                                            CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                            bool ret = CreateIntoPartsStock(stock_inout_id, bill_p_model, model.purchase_billing_id, model.order_num);
                                        }
                                    }
                                }
                            }
                            #endregion

                            #region 三:采购换货-->自动生成出、入库单(数量大于0是入库,小于0是出库)
                            else if (model.order_type ==  Convert.ToInt32(DataSources.EnumPurchaseOrderType.PurchaseExchange).ToString())
                            {
                                string stock_in_id = string.Empty;
                                string stock_out_id = string.Empty;
                                //1.生成入库单
                                if (CreateIntoStock("入库单", model, ref stock_in_id))
                                {
                                    //2.查询配件入库数量大于0的,生成配件信息入库单
                                    DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "' and isnull(business_counts,0)>0 ", "", "");
                                    if (dt_parts != null && dt_parts.Rows.Count > 0)
                                    {
                                        for (int a = 0; a < dt_parts.Rows.Count; a++)
                                        {
                                            tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p();
                                            CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                            bool ret = CreateIntoPartsStock(stock_in_id, bill_p_model, model.purchase_billing_id, model.order_num);
                                        }
                                    }
                                }

                                //3.生成出库单
                                if (CreateIntoStock("出库单", model, ref stock_out_id))
                                {
                                    //4.查询配件入库数量小于0的,生成配件信息出库单
                                    DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "' and isnull(business_counts,0)<0 ", "", "");
                                    if (dt_parts != null && dt_parts.Rows.Count > 0)
                                    {
                                        for (int a = 0; a < dt_parts.Rows.Count; a++)
                                        {
                                            tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p();
                                            CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                            CreateIntoPartsStock(stock_out_id, bill_p_model, model.purchase_billing_id, model.order_num);
                                        }
                                    }
                                }
                            }
                            #endregion
                            #endregion

                            #region 向宇通发送配送单号
                            if (!string.IsNullOrEmpty(model.ration_send_code))
                            {
                                //DBHelper.WebServHandler("审核通过入库时发送配送单号到宇通系统", EnumWebServFunName.UpLoadPartPutStore, model.ration_send_code);
                                DBHelper.WebServHandler("", EnumWebServFunName.LoadPartInStore, model.ration_send_code);
                            }
                            #endregion

                            #region 审核通过时,将本次现付更新到已结算金额中
                            if (model.this_payment > 0)
                            {
                                SysSQLString sysStringSql = new SysSQLString();
                                sysStringSql.cmdType = CommandType.Text;
                                Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数
                                dicParam.Add("balance_money", model.this_payment.ToString());
                                dicParam.Add("purchase_billing_id", listField[i]);
                                StringBuilder sb = new StringBuilder();
                                sb.Append(" Update tb_parts_purchase_billing Set balance_money=@balance_money where purchase_billing_id=@purchase_billing_id");
                                sysStringSql.Param = dicParam;
                                sysStringSql.sqlString = sb.ToString();
                                listSql.Add(sysStringSql);
                            }
                            #endregion

                            #region 如果配送单号不为空,需将对应的配送单状态修改为“已收货”
                            if (!string.IsNullOrEmpty(model.ration_send_code))
                            {
                                SysSQLString sysStringSql = new SysSQLString();
                                sysStringSql.cmdType = CommandType.Text;
                                Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数
                                dicParam.Add("distribution_status", "2");//1:配送中,2:已收货
                                dicParam.Add("ration_send_code", model.ration_send_code);
                                StringBuilder sb = new StringBuilder();
                                sb.Append(" Update tb_distribution Set distribution_status=@distribution_status where ration_send_code=@ration_send_code");
                                sysStringSql.Param = dicParam;
                                sysStringSql.sqlString = sb.ToString();
                                listSql.Add(sysStringSql);
                            }
                            #endregion

                            #region 如果配送单号不为空,需通过配送单将对应的宇通采购订单的确认数量修改下
//                            if (!string.IsNullOrEmpty(model.ration_send_code))
//                            {
//                                if (dt_bill_p != null && dt_bill_p.Rows.Count > 0)
//                                {
//                                    dt_bill_p = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", "");
//                                    if (dt_bill_p != null && dt_bill_p.Rows.Count > 0)
//                                    {
//                                        string wherestr = string.Format(@"purchase_order_yt_id in 
//                                                            (
//                                                               select top 1 purchase_order_yt_id from tb_parts_purchase_order_2 where dsn_adjustable_parts in 
//                                                               (
//                                                                  select top 1 dsn_adjustable_parts from tb_distribution where ration_send_code='{0}'
//                                                               )
//                                                            )", model.ration_send_code);
//                                        DataTable dt_yt_p = DBHelper.GetTable("采购开单审核通过时,修改宇通采购订单配件信息量", "tb_parts_purchase_order_p_2", "*", wherestr, "", "");
//                                        if (dt_yt_p != null && dt_yt_p.Rows.Count > 0)
//                                        {
//                                            foreach (DataRow dr in dt_bill_p.Rows)
//                                            {
//                                                DataRow[] dr_yt_p = dt_yt_p.Select("parts_code ='" + dr["parts_code"].ToString() + "'");
//                                                if (dr_yt_p.Length > 0)
//                                                {
//                                                    decimal old_conf_count = Convert.ToDecimal(dr_yt_p[0]["conf_count"].ToString());
//                                                    decimal new_conf_count = Convert.ToDecimal(dr["business_counts"].ToString());

//                                                    SysSQLString sysStringSql = new SysSQLString();
//                                                    sysStringSql.cmdType = CommandType.Text;
//                                                    Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数
//                                                    dicParam.Add("conf_count", (old_conf_count + new_conf_count).ToString());
//                                                    dicParam.Add("purchase_order_yt_id", dr_yt_p[0]["purchase_order_yt_id"].ToString());
//                                                    dicParam.Add("parts_code", dr_yt_p[0]["parts_code"].ToString());
//                                                    StringBuilder sb = new StringBuilder();
//                                                    sb.Append(" Update tb_parts_purchase_order_p_2 Set conf_count=@conf_count where purchase_order_yt_id=@purchase_order_yt_id and parts_code=@parts_code");
//                                                    sysStringSql.Param = dicParam;
//                                                    sysStringSql.sqlString = sb.ToString();
//                                                    listSql.Add(sysStringSql);
//                                                }
//                                            }
//                                        }
//                                    }
//                                }
//                            }
	                        #endregion
                        }
                    }
                    CommonFuncCall.StatisticStock(TemplateTable, "采购开单审核通过后更新配件的账面库存");
                    //审核通过时,将本次现付更新到已结算金额中
                    if (listSql.Count > 0)
                    {
                        DBHelper.BatchExeSQLStringMultiByTrans("采购开单审核通过时,将本次现付更新到已结算金额中或是更新配送单状态", listSql);
                    }
                }
            }
            catch (Exception ex)
            { }
        }
        /// <summary> 添加情况下组装sql的方法
        /// </summary>
        /// <param name="listSql"></param>
        /// <param name="purchase_billing_id"></param>
        private void AddPurchaseOrderSqlString(List<SysSQLString> listSql, string purchase_billing_id, string HandleType)
        {
            decimal allmoney=0;
            SysSQLString sysStringSql = new SysSQLString();
            sysStringSql.cmdType = CommandType.Text;
            Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数

            ddtorder_date.Value = Convert.ToDateTime(ddtorder_date.Value.ToShortDateString() + " 23:59:59");
            ddtpayment_date.Value = Convert.ToDateTime(ddtpayment_date.Value.ToShortDateString() + " 23:59:59");
            tb_parts_purchase_billing model = new tb_parts_purchase_billing();
            CommonFuncCall.SetModelObjectValue(this, model);
            GetAllMoney(ref allmoney);

            model.purchase_billing_id = purchase_billing_id;
            model.sup_id = sup_id;
            model.sup_code = sup_code;
            model.sup_name = txtsup_name.Text;
            //单据类型
            if (!string.IsNullOrEmpty(ddlorder_type.SelectedValue.ToString()))
            {
                model.order_type_name = ddlorder_type.SelectedItem.ToString();
            }
            //发票类型
            if (!string.IsNullOrEmpty(ddlreceipt_type.SelectedValue.ToString()))
            {
                model.receipt_type_name = ddlreceipt_type.SelectedItem.ToString();
            }
            //运输方式
            if (!string.IsNullOrEmpty(ddltrans_way.SelectedValue.ToString()))
            {
                model.trans_way_name = ddltrans_way.SelectedItem.ToString();
            }
            //结算方式
            if (!string.IsNullOrEmpty(ddlbalance_way.SelectedValue.ToString()))
            {
                model.balance_way_name = ddlbalance_way.SelectedItem.ToString();
            }
            //结算账户
            if (!string.IsNullOrEmpty(ddlbalance_account.SelectedValue.ToString()))
            {
                model.balance_account_name = ddlbalance_account.SelectedItem.ToString();
            }
            //部门
            if (!string.IsNullOrEmpty(ddlorg_id.SelectedValue.ToString()))
            {
                model.org_id = ddlorg_id.SelectedValue.ToString();
                model.org_name = ddlorg_id.SelectedItem.ToString();
            }
            //经办人
            if (!string.IsNullOrEmpty(ddlhandle.SelectedValue.ToString()))
            {
                model.handle = ddlhandle.SelectedValue.ToString();
                model.handle_name = ddlhandle.SelectedItem.ToString();
            }
            model.balance_unit = txtbalance_unit.Text.Trim();
            model.create_by = GlobalStaticObj.UserID;
            model.create_name = GlobalStaticObj.UserName;
            model.create_time = Common.LocalDateTimeToUtcLong(DateTime.Now);
            model.operators = GlobalStaticObj.UserID;
            model.operator_name = GlobalStaticObj.UserName;
            model.com_id = GlobalStaticObj.CurrUserCom_Id;//公司ID
            model.com_code = GlobalStaticObj.CurrUserCom_Code;//公司编码
            model.com_name = GlobalStaticObj.CurrUserCom_Name;//公司名称
            model.is_occupy = "0";
            model.is_lock = "0";
            model.enable_flag = "1";
            model.allmoney = allmoney;
            if (HandleType == "保存")
            {
                model.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.DRAFT).ToString();
                model.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.DRAFT, true);
            }
            else if (HandleType == "提交")
            {
                model.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.SUBMIT).ToString();
                model.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.SUBMIT, true);
            }
            if (model != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(" Insert Into tb_parts_purchase_billing( ");
                StringBuilder sp = new StringBuilder();
                StringBuilder sb_prame = new StringBuilder();
                foreach (PropertyInfo info in model.GetType().GetProperties())
                {
                    string name = info.Name;
                    object value = info.GetValue(model, null);
                    sb_prame.Append("," + name);
                    sp.Append(",@" + name);
                    dicParam.Add(name, value == null ? "" : value.ToString());
                }
                sb.Append(sb_prame.ToString().Substring(1, sb_prame.ToString().Length - 1) + ") Values (");
                sb.Append(sp.ToString().Substring(1, sp.ToString().Length - 1) + ")").Append(";");
                sysStringSql.sqlString = sb.ToString();
                sysStringSql.Param = dicParam;
                listSql.Add(sysStringSql);
            }
        }
 /// <summary> 编辑情况下组装sql的方法
 /// </summary>
 /// <param name="listSql"></param>
 /// <param name="purchase_billing_id"></param>
 /// <param name="model"></param>
 private void EditPurchaseOrderSqlString(List<SysSQLString> listSql, string purchase_billing_id, tb_parts_purchase_billing model, string HandleType)
 {
     decimal allmoney = 0;
     SysSQLString sysStringSql = new SysSQLString();
     sysStringSql.cmdType = CommandType.Text;
     Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数
     ddtorder_date.Value = Convert.ToDateTime(ddtorder_date.Value.ToShortDateString() + " 23:59:59");
     ddtpayment_date.Value = Convert.ToDateTime(ddtpayment_date.Value.ToShortDateString() + " 23:59:59");
     CommonFuncCall.SetModelObjectValue(this, model);
     GetAllMoney(ref allmoney);
     model.sup_id = sup_id;
     model.sup_code = sup_code;
     model.sup_name = txtsup_name.Text;
     //单据类型
     if (!string.IsNullOrEmpty(ddlorder_type.SelectedValue.ToString()))
     {
         model.order_type_name = ddlorder_type.SelectedItem.ToString();
     }
     //发票类型
     if (!string.IsNullOrEmpty(ddlreceipt_type.SelectedValue.ToString()))
     {
         model.receipt_type_name = ddlreceipt_type.SelectedItem.ToString();
     }
     //运输方式
     if (!string.IsNullOrEmpty(ddltrans_way.SelectedValue.ToString()))
     {
         model.trans_way_name = ddltrans_way.SelectedItem.ToString();
     }
     //结算方式
     if (!string.IsNullOrEmpty(ddlbalance_way.SelectedValue.ToString()))
     {
         model.balance_way_name = ddlbalance_way.SelectedItem.ToString();
     }
     //结算账户
     if (!string.IsNullOrEmpty(ddlbalance_account.SelectedValue.ToString()))
     {
         model.balance_account_name = ddlbalance_account.SelectedItem.ToString();
     }
     //部门
     if (!string.IsNullOrEmpty(ddlorg_id.SelectedValue.ToString()))
     {
         model.org_id = ddlorg_id.SelectedValue.ToString();
         model.org_name = ddlorg_id.SelectedItem.ToString();
     }
     //经办人
     if (!string.IsNullOrEmpty(ddlhandle.SelectedValue.ToString()))
     {
         model.handle = ddlhandle.SelectedValue.ToString();
         model.handle_name = ddlhandle.SelectedItem.ToString();
     }
     model.balance_unit = txtbalance_unit.Text.Trim();
     model.update_by = GlobalStaticObj.UserID;
     model.update_name = GlobalStaticObj.UserName;
     model.update_time = Common.LocalDateTimeToUtcLong(DateTime.Now);
     model.operators = GlobalStaticObj.UserID;
     model.operator_name = GlobalStaticObj.UserName;
     model.enable_flag = "1";
     model.allmoney = allmoney;
     if (HandleType == "保存")
     {
         model.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.DRAFT).ToString();
         model.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.DRAFT, true);
     }
     else if (HandleType == "提交")
     {
         model.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.SUBMIT).ToString();
         model.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.SUBMIT, true);
     }
     if (model != null)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append(" Update tb_parts_purchase_billing Set ");
         bool isFirstValue = true;
         foreach (PropertyInfo info in model.GetType().GetProperties())
         {
             string name = info.Name;
             object value = info.GetValue(model, 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 purchase_billing_id='" + purchase_billing_id + "';");
         sysStringSql.sqlString = sb.ToString();
         sysStringSql.Param = dicParam;
         listSql.Add(sysStringSql);
     }
 }
        /// <summary>
        /// 审核通过后需要自动生成的单子的方法
        /// </summary>
        void CreateBill(List<string> listField)
        {
            if (listField.Count > 0)
            {
                for (int i = 0; i < listField.Count; i++)
                {
                    DataTable dt = DBHelper.GetTable("", "tb_parts_purchase_billing", "*", string.Format("purchase_billing_id='{0}'", listField[i]), "", "");
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        tb_parts_purchase_billing model = new tb_parts_purchase_billing();
                        CommonFuncCall.SetModlByDataTable(model, dt);

                        #region 当金额大于0时,自动生成预付款单
                        if (model.this_payment > 0)
                        {
                            tb_bill_receivable a = new tb_bill_receivable();
                            tb_balance_documents b = new tb_balance_documents();
                            tb_payment_detail c = new tb_payment_detail();
                            a.cust_id = model.sup_id;//供应商ID
                            a.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.PAYMENT);//订单号
                            a.order_type = (int)DataSources.EnumOrderType.PAYMENT;
                            a.payment_type = (int)DataSources.EnumPaymentType.PAYMENT;
                            a.org_id = model.org_id;

                            b.billing_money = model.this_payment;//开单金额
                            b.documents_date = model.order_date;//单据日期
                            b.documents_id = model.purchase_billing_id;//单据ID
                            b.documents_name = "采购开单";//单据名称
                            b.documents_num = model.order_num;//单据编码

                            c.money = model.this_payment;//金额
                            c.balance_way = model.balance_way;//结算方式
                            c.check_number = model.check_number;//票号

                            DBOperation.AddBillReceivable(a, b, c);
                        }
                        #endregion

                        #region 自动生产出入库单
                        #region 一:采购收货单-->自动生成入库单
                        if (model.order_type == DataSources.EnumPurchaseOrderType.PurchaseReceive.ToString())
                        {
                            string stock_inout_id = string.Empty;
                            //1.生成入库单
                            if (CreateIntoStock("入库单", model, ref stock_inout_id))
                            {
                                //2.查询配件信息,生成配件信息入库单
                                DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                        CreateIntoPartsStock(stock_inout_id, bill_p_model);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region 二:采购退货-->自动生成出库单
                        else if (model.order_type == DataSources.EnumPurchaseOrderType.PurchaseBack.ToString())
                        {
                            string stock_inout_id = string.Empty;
                            //1.生成出库单
                            if (CreateIntoStock("出库单", model, ref stock_inout_id))
                            {
                                //2.查询配件信息,生成配件信息出库单
                                DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "'", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                        CreateIntoPartsStock(stock_inout_id, bill_p_model);
                                    }
                                }
                            }
                        } 
                        #endregion

                        #region 三:采购换货-->自动生成出、入库单(数量大于0是入库,小于0是出库)
                        else if (model.order_type == DataSources.EnumPurchaseOrderType.PurchaseExchange.ToString())
                        {
                            string stock_in_id = string.Empty;
                            string stock_out_id = string.Empty;
                            //1.生成入库单
                            if (CreateIntoStock("入库单", model, ref stock_in_id))
                            {
                                //2.查询配件入库数量大于0的,生成配件信息入库单
                                DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "' and storage_count>0 ", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                        CreateIntoPartsStock(stock_in_id, bill_p_model);
                                    }
                                }
                            }

                            //3.生成出库单
                            if (CreateIntoStock("出库单", model, ref stock_out_id))
                            {
                                //4.查询配件入库数量小于0的,生成配件信息出库单
                                DataTable dt_parts = DBHelper.GetTable("查询采购开单配件信息表", "tb_parts_purchase_billing_p", "*", " purchase_billing_id='" + model.purchase_billing_id + "' and storage_count<0 ", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_purchase_billing_p bill_p_model = new tb_parts_purchase_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                        CreateIntoPartsStock(stock_out_id, bill_p_model);
                                    }
                                }
                            }
                        } 
                        #endregion
                        #endregion

                        #region 向宇通发送配送单号
                        if (!string.IsNullOrEmpty(model.ration_send_code))
                        {
                            //DBHelper.WebServHandler("审核通过入库时发送配送单号到宇通系统", EnumWebServFunName.UpLoadPartPutStore, model.ration_send_code);
                            DBHelper.WebServHandler("", EnumWebServFunName.LoadPartInStore, model.ration_send_code);
                        }
                        #endregion
                    }
                }
            }
        }