コード例 #1
0
        /// <summary>
        /// 添加情况下组装sql的方法
        /// </summary>
        /// <param name="listSql"></param>
        /// <param name="sale_billing_id"></param>
        private void AddSaleOrderSqlString(List<SysSQLString> listSql, string sale_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");
            ddtreceivables_date.Value = Convert.ToDateTime(ddtreceivables_date.Value.ToShortDateString() + " 23:59:59");
            tb_parts_sale_billing model = new tb_parts_sale_billing();
            CommonFuncCall.SetModelObjectValue(this, model);
            GetAllMoney(ref allmoney);

            model.sale_billing_id = sale_billing_id;
            model.cust_id = cust_id;
            model.cust_code = cust_code;
            model.cust_name = txtcust_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 = balance_unit;
            model.balance_unit_name = 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.allmoney = allmoney;
            model.is_occupy = "0";
            model.is_lock = "0";
            model.enable_flag = "1";
            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_sale_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);
            }
        }
コード例 #2
0
        /// <summary>
        /// 编辑情况下组装sql的方法
        /// </summary>
        /// <param name="listSql"></param>
        /// <param name="sale_billing_id"></param>
        /// <param name="model"></param>
        private void EditSaleOrderSqlString(List<SysSQLString> listSql, string sale_billing_id, tb_parts_sale_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");
            ddtreceivables_date.Value = Convert.ToDateTime(ddtreceivables_date.Value.ToShortDateString() + " 23:59:59");
            CommonFuncCall.SetModelObjectValue(this, model);
            GetAllMoney(ref allmoney);

            model.cust_id = cust_id;
            model.cust_code = cust_code;
            model.cust_name = txtcust_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 = balance_unit;
            model.balance_unit_name = 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.allmoney = allmoney;
            model.enable_flag = "1";
            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_sale_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 sale_billing_id='" + sale_billing_id + "';");
                sysStringSql.sqlString = sb.ToString();
                sysStringSql.Param = dicParam;
                listSql.Add(sysStringSql);
            }
        }
コード例 #3
0
 private void buttonEx1_Click(object sender, EventArgs e)
 {
     try
     {
         List<string> listField = GetTestRecord();
         if (listField.Count > 0)
         {
             if (listField.Count == 0)
             {
                 MessageBoxEx.Show("请选择要发送的销售开单审核数据!");
                 return;
             }
             partsale partsalemodel = new partsale();
             tb_parts_sale_billing sale_bill_model = new tb_parts_sale_billing();
             DataTable dt_test = DBHelper.GetTable("查看一条销售开发订单信息", "tb_parts_sale_billing", "*", " sale_billing_id='" + listField[0] + "'", "", "");
             CommonFuncCall.SetModlByDataTable(sale_bill_model, dt_test, 0);
             partsalemodel.sale_date = DateTime.Now.ToString();
             partsalemodel.cust_name = sale_bill_model.contacts;
             partsalemodel.cust_phone = sale_bill_model.contacts_tel;
             partsalemodel.turner = string.Empty;
             partsalemodel.license_plate = string.Empty;
             partsalemodel.amount = sale_bill_model.allmoney.ToString();
             partsalemodel.remark = sale_bill_model.remark;
             DataTable dt_parts_test = DBHelper.GetTable("查看一条销售开发订单的配件信息", "tb_parts_sale_billing_p", "*", " sale_billing_id='" + listField[0] + "'", "", "");
             if (dt_parts_test != null && dt_parts_test.Rows.Count > 0)
             {
                 partDetail partDetailmodel = new partDetail();
                 partsalemodel.partDetails = new partDetail[dt_parts_test.Rows.Count];
                 tb_parts_sale_billing_p sale_bill_p_model = new tb_parts_sale_billing_p();
                 for (int i = 0; i < dt_parts_test.Rows.Count; i++)
                 {
                     partDetailmodel = new partDetail();
                     sale_bill_p_model = new tb_parts_sale_billing_p();
                     CommonFuncCall.SetModlByDataTable(sale_bill_p_model, dt_parts_test, i);
                     partDetailmodel.wh_code = sale_bill_p_model.wh_code;
                     partDetailmodel.car_parts_code = sale_bill_p_model.car_factory_code;
                     partDetailmodel.remark = sale_bill_p_model.remark;
                     partDetailmodel.business_count = sale_bill_p_model.business_count.ToString();
                     partDetailmodel.business_price = sale_bill_p_model.business_price.ToString();
                     partDetailmodel.amount = sale_bill_p_model.valorem_together.ToString();
                     partDetailmodel.parts_remark = sale_bill_p_model.remark;
                     partsalemodel.partDetails[i] = partDetailmodel;
                 }
             }
             string mess = DBHelper.WebServHandler("调用销售开发订单信息", SYSModel.EnumWebServFunName.UpLoadPartSale, partsalemodel);
             if (!string.IsNullOrEmpty(mess))
             {
                 mess = "操作成功!";
             } 
             MessageBoxEx.Show(mess);
         }
     }
     catch (Exception ex)
     { }
 }
コード例 #4
0
        /// <summary> 创建出入库单
        /// </summary>
        /// <param name="ordertype">单据类型</param>
        /// <param name="bill_model">采购开单信息</param>
        bool CreateIntoStock(string ordertype, tb_parts_sale_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();

            stoct_inout_model.order_date = Common.LocalDateTimeToUtcLong(DateTime.Now);
            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 = Convert.ToInt32(DataSources.EnumAllocationBillType.Storage).ToString();
            }
            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 = Convert.ToInt32(DataSources.EnumAllocationBillType.OutboundOrder).ToString();
            }
            stoct_inout_model.billing_type = Convert.ToInt32(DataSources.EnumAllocationBillingType.SaleBilling).ToString();
            stoct_inout_model.billing_type_name = Convert.ToInt32(DataSources.EnumAllocationBillingType.SaleBilling).ToString();
            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 = "";
            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);
        }
コード例 #5
0
        /// <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_sale_billing", "*", string.Format("sale_billing_id='{0}'", listField[i]), "", "");
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        tb_parts_sale_billing model = new tb_parts_sale_billing();
                        CommonFuncCall.SetModlByDataTable(model, dt);

                        #region 当金额大于0时,自动生成预收款单
                        if (model.current_collect > 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.cust_id;//客户ID
                            a.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.RECEIVABLE);//订单号
                            a.order_type = (int)DataSources.EnumOrderType.RECEIVABLE;
                            a.payment_type = (int)DataSources.EnumReceivableType.RECEIVABLE;
                            a.org_id = model.org_id;

                            b.billing_money = model.current_collect;//开单金额
                            b.documents_date = model.order_date;//单据日期
                            b.documents_id = model.org_id;//单据ID
                            b.documents_name = "销售开单";//单据名称
                            b.documents_num = model.order_num;//单据编码

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

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

                        #region 自动生产出入库单
                        //1:销售开单-->自动生成出库单
                        if (model.order_type == DataSources.EnumSaleOrderType.SaleBill.ToString())
                        {
                            string stock_inout_id = string.Empty;
                            //1.生成出库单
                            if (CreateIntoStock("出库单", model, ref stock_inout_id))
                            {
                                //2.查询配件信息,生成配件信息出库单
                                DataTable dt_parts = DBHelper.GetTable("查询销售开单配件信息表", "tb_parts_sale_billing_p", "*", " sale_billing_id='" + model.sale_billing_id + "'", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_sale_billing_p bill_p_model = new tb_parts_sale_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                        CreateIntoPartsStock(stock_inout_id, bill_p_model);
                                    }
                                }
                            }
                        }
                        //2:销售退货-->自动生成入库单
                        else if (model.order_type == DataSources.EnumSaleOrderType.SaleBack.ToString())
                        {
                            string stock_inout_id = string.Empty;
                            //1.生成入库单
                            if (CreateIntoStock("入库单", model, ref stock_inout_id))
                            {
                                //2.查询配件信息,生成配件信息入库单
                                DataTable dt_parts = DBHelper.GetTable("查询销售开单配件信息表", "tb_parts_sale_billing_p", "*", " sale_billing_id='" + model.sale_billing_id + "'", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_sale_billing_p bill_p_model = new tb_parts_sale_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                        CreateIntoPartsStock(stock_inout_id, bill_p_model);
                                    }
                                }
                            }
                        }
                        //3:销售换货-->自动生成出、入库单(数量大于0是出库,小于0是入库)
                        else if (model.order_type == DataSources.EnumSaleOrderType.SaleExchange.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_sale_billing_p", "*", " sale_billing_id='" + model.sale_billing_id + "' and library_count<0 ", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_sale_billing_p bill_p_model = new tb_parts_sale_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_sale_billing_p", "*", " sale_billing_id='" + model.sale_billing_id + "' and library_count>0 ", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_sale_billing_p bill_p_model = new tb_parts_sale_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                        CreateIntoPartsStock(stock_out_id, bill_p_model);
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
            }
        }
コード例 #6
0
        /// <summary> 创建报损单
        /// </summary>
        /// <param name="ordertype"></param>
        /// <param name="bill_model"></param>
        /// <param name="stock_loss_id"></param>
        /// <returns></returns>
        bool CreateIntoLoss(tb_parts_sale_billing bill_model, ref string stock_loss_id)
        {
            tb_parts_stock_loss stock_loss_model = new tb_parts_stock_loss();
            Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数

            stock_loss_model.stock_loss_id = Guid.NewGuid().ToString();
            stock_loss_id = stock_loss_model.stock_loss_id;

            stock_loss_model.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.LossBill);//获取报损单编号
            stock_loss_model.order_date = Common.LocalDateTimeToUtcLong(Convert.ToDateTime(DateTime.Now.ToShortDateString()));
            stock_loss_model.order_status = Convert.ToInt32(DataSources.EnumAuditStatus.AUDIT).ToString();
            stock_loss_model.order_status_name = DataSources.GetDescription(DataSources.EnumAuditStatus.AUDIT, true);

            stock_loss_model.out_wh_type_name = DataSources.GetDescription(DataSources.EnumOtherInoutType.Scrap, true);

            stock_loss_model.com_id = GlobalStaticObj.CurrUserCom_Id;
            stock_loss_model.com_name = GlobalStaticObj.CurrUserCom_Name;
            stock_loss_model.org_id = bill_model.org_id;
            stock_loss_model.org_name = bill_model.org_name;
            stock_loss_model.handle = bill_model.handle;
            stock_loss_model.handle_name = bill_model.handle_name;
            stock_loss_model.operators = bill_model.operators;
            stock_loss_model.operator_name = bill_model.operator_name;
            stock_loss_model.create_by = GlobalStaticObj.UserID;
            stock_loss_model.create_name = GlobalStaticObj.UserName;
            stock_loss_model.create_time = Common.LocalDateTimeToUtcLong(DateTime.Now);
            stock_loss_model.update_by = GlobalStaticObj.UserID;
            stock_loss_model.update_name = GlobalStaticObj.UserName;
            stock_loss_model.update_time = Common.LocalDateTimeToUtcLong(DateTime.Now);
            stock_loss_model.remark = "由单号为【" + bill_model.order_num + "】的销售开单生成";
            stock_loss_model.enable_flag = "1";

            foreach (PropertyInfo info in stock_loss_model.GetType().GetProperties())
            {
                string name = info.Name;
                object value = info.GetValue(stock_loss_model, null);
                dicParam.Add(name, value == null ? "" : value.ToString());
            }
            return DBHelper.Submit_AddOrEdit("根据销售开单生成报损单信息", "tb_parts_stock_loss", "stock_loss_id", "", dicParam);
        }
コード例 #7
0
        /// <summary>
        /// 审核通过后需要自动生成的单子的方法
        /// </summary>
        void CreateBill(List<string> listField)
        {
            if (listField.Count > 0)
            {
                List<SysSQLString> listSql = new List<SysSQLString>();
                DataTable TemplateTable = CommonFuncCall.CreatePartStatisticTable();//获取要填充的公用表
                for (int i = 0; i < listField.Count; i++)
                {
                    DataTable dt = DBHelper.GetTable("", "tb_parts_sale_billing", "*", string.Format("sale_billing_id='{0}'", listField[i]), "", "");
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        tb_parts_sale_billing model = new tb_parts_sale_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_sale_billing_p", "*", string.Format("sale_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_count"].ToString();//配件业务数量
                                dr["PartCount"] = Convert.ToDecimal(IOPartTable.Rows[a]["business_count"].ToString());//配件业务数量
                                dr["StatisticType"] = (int)DataSources.EnumStatisticType.PaperCount;//统计类型
                                TemplateTable.Rows.Add(dr);//添加新的数据行项
                            }
                        }
                        #endregion

                        #region 当金额大于0时,自动生成预收款单
                        if (model.current_collect > 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.cust_id;//客户ID
                            a.order_num = CommonUtility.GetNewNo(DataSources.EnumProjectType.RECEIVABLE);//订单号
                            a.order_type = (int)DataSources.EnumOrderType.RECEIVABLE;
                            a.payment_type = (int)DataSources.EnumReceivableType.RECEIVABLE;
                            a.org_id = model.org_id;

                            b.billing_money = model.current_collect;//开单金额
                            b.documents_date = model.order_date;//单据日期
                            b.documents_id = model.org_id;//单据ID
                            b.documents_name = "销售开单";//单据名称
                            b.documents_num = model.order_num;//单据编码

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

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

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

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

                            #region 当销售退货时,将勾选了报损的配件信息生成报损单
                            DataTable dt_loss_parts = DBHelper.GetTable("查询销售开单配件信息表", "tb_parts_sale_billing_p", "*", " is_loss='1' and sale_billing_id='" + model.sale_billing_id + "'", "", "");
                            if (dt_loss_parts != null && dt_loss_parts.Rows.Count > 0)
                            {
                                string stock_loss_id = string.Empty;
                                if (CreateIntoLoss(model, ref stock_loss_id))
                                {
                                    for (int a = 0; a < dt_loss_parts.Rows.Count; a++)
                                    {
                                        tb_parts_sale_billing_p bill_p_model = new tb_parts_sale_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_loss_parts, a);
                                        bool ret = CreateIntoPartsLoss(stock_loss_id, bill_p_model, model.sale_billing_id, model.order_num);
                                    }
                                }
                            }
                            #endregion
                        }
                        #endregion

                        #region 3:销售换货-->自动生成出、入库单(数量大于0是出库,小于0是入库)
                        else if (model.order_type == Convert.ToInt32(DataSources.EnumSaleOrderType.SaleExchange).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_sale_billing_p", "*", " sale_billing_id='" + model.sale_billing_id + "' and isnull(business_count,0)<0 ", "", "");
                                if (dt_parts != null && dt_parts.Rows.Count > 0)
                                {
                                    for (int a = 0; a < dt_parts.Rows.Count; a++)
                                    {
                                        tb_parts_sale_billing_p bill_p_model = new tb_parts_sale_billing_p();
                                        CommonFuncCall.SetModlByDataTable(bill_p_model, dt_parts, a);
                                        bool ret = CreateIntoPartsStock(stock_in_id, bill_p_model, model.sale_billing_id, model.order_num);
                                    }
                                }
                            }

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

                        #region 审核通过时,将本次现收更新到已结算金额中
                        if (model.current_collect > 0)
                        {
                            SysSQLString sysStringSql = new SysSQLString();
                            sysStringSql.cmdType = CommandType.Text;
                            Dictionary<string, string> dicParam = new Dictionary<string, string>();//参数
                            dicParam.Add("balance_money", model.current_collect.ToString());
                            dicParam.Add("sale_billing_id", listField[i]);
                            StringBuilder sb = new StringBuilder();
                            sb.Append(" Update tb_parts_sale_billing Set balance_money=@balance_money where sale_billing_id=@sale_billing_id");
                            sysStringSql.Param = dicParam;
                            sysStringSql.sqlString = sb.ToString();
                            listSql.Add(sysStringSql);
                        }
                        #endregion
                    }
                }
                CommonFuncCall.StatisticStock(TemplateTable, "销售开单审核通过后更新配件的账面库存");
                //审核通过时,将本次现收更新到已结算金额中
                if (listSql.Count > 0)
                {
                    DBHelper.BatchExeSQLStringMultiByTrans("采购销售审核通过时,将本次现收更新到已结算金额中", listSql);
                }
            }
        }