public static bool ConfirmBill(StorageOutSellModel model,out string retstrval)
        {
            //判断源单是无来源还是有来源,无来源则不需要更新受订量
            string sqlFromType = "select a.FromType,a.CustID,b.TotalPrice from officedba.SellSend a"
                        + " inner join officedba.StorageOutSell b on b.FromBillID=a.ID and b.ID=" + model.ID;
            DataTable dtFrom = SqlHelper.ExecuteSql(sqlFromType);
            string FromBillFromType = dtFrom.Rows[0]["FromType"].ToString();//得到的是“0”或“1”


            ArrayList lstConfirm = new ArrayList();
            StringBuilder sql = new StringBuilder();
            sql.AppendLine(" UPDATE officedba.StorageOutSell SET");
            sql.AppendLine(" Confirmor          = @Confirmor,");
            sql.AppendLine(" confirmDate      = getdate(),");
            sql.AppendLine(" BillStatus              = 2,");
            sql.AppendLine(" ModifiedUserID      = @ModifiedUserID,");
            sql.AppendLine(" ModifiedDate                = getdate()");
            sql.AppendLine(" Where  CompanyCD=@CompanyCD and ID=@ID");

            SqlCommand comm = new SqlCommand();
            comm.CommandText = sql.ToString();
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Confirmor", model.Confirmor));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID", model.ModifiedUserID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD", model.CompanyCD));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ID", model.ID));

            lstConfirm.Add(comm);


            List<StorageOutSellDetailModel> modelList = new List<StorageOutSellDetailModel>();
            string sqlSele = "select a.ProductID,a.UnitPrice,a.CompanyCD,a.OutNo,a.StorageID,a.BatchNo,a.UsedUnitCount,a.FromLineNo,a.ProductCount,b.StorageID as DefaultStorageID from officedba.StorageOutSellDetail a"
            +" inner join officedba.ProductInfo b on b.ID=a.ProductID"
            + " where a.CompanyCD='" + model.CompanyCD + "'"
            + "and a.OutNo=(select OutNo from officedba.StorageOutSell where ID=" + model.ID + ")";
            DataTable dt = SqlHelper.ExecuteSql(sqlSele);
            if (dt != null && dt.Rows.Count > 0)
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    StorageOutSellDetailModel modelDetail = new StorageOutSellDetailModel();
                    if (dt.Rows[i]["ProductID"].ToString() != "")
                    {
                        modelDetail.ProductID = dt.Rows[i]["ProductID"].ToString();
                    }
                    if (dt.Rows[i]["StorageID"].ToString() != "")
                    {
                        modelDetail.StorageID = dt.Rows[i]["StorageID"].ToString();
                    }
                    if (dt.Rows[i]["ProductCount"].ToString() != "")
                    {
                        modelDetail.ProductCount = dt.Rows[i]["ProductCount"].ToString();
                    }
                    if (dt.Rows[i]["FromLineNo"].ToString() != "")
                    {
                        modelDetail.FromLineNo = dt.Rows[i]["FromLineNo"].ToString();
                    }
                    if (dt.Rows[i]["DefaultStorageID"].ToString() != "")
                    {
                        modelDetail.DefaultStorageID = dt.Rows[i]["DefaultStorageID"].ToString();
                    }
                    modelDetail.BatchNo = dt.Rows[i]["BatchNo"].ToString();
                    if (dt.Rows[i]["UsedUnitCount"].ToString() == "")
                        modelDetail.UsedUnitCount = dt.Rows[i]["ProductCount"].ToString();
                    else
                        modelDetail.UsedUnitCount = dt.Rows[i]["UsedUnitCount"].ToString();
                    modelList.Add(modelDetail);
                    #region 操作库存流水账
                    StorageAccountModel AccountM_ = new StorageAccountModel();
                    AccountM_.BatchNo = dt.Rows[i]["BatchNo"].ToString();
                    AccountM_.BillNo = dt.Rows[i]["OutNo"].ToString();
                    AccountM_.BillType=7;
                    AccountM_.CompanyCD = dt.Rows[i]["CompanyCD"].ToString();
                    AccountM_.Creator = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID;
                    AccountM_.HappenCount = Convert.ToDecimal(dt.Rows[i]["ProductCount"].ToString());
                    AccountM_.HappenDate = System.DateTime.Now;
                    AccountM_.PageUrl="../Office/StorageManager/StorageOutSellAdd.aspx";
                    AccountM_.Price=Convert.ToDecimal(dt.Rows[i]["UnitPrice"].ToString());
                    AccountM_.ProductCount= Convert.ToDecimal(dt.Rows[i]["ProductCount"].ToString());
                    AccountM_.ProductID= Convert.ToInt32(dt.Rows[i]["ProductID"].ToString());
                    AccountM_.StorageID=Convert.ToInt32(dt.Rows[i]["StorageID"].ToString());
                    SqlCommand AccountCom_=StorageAccountDBHelper.InsertStorageAccountCommand(AccountM_,"1");
                    lstConfirm.Add(AccountCom_);
                    #endregion
                }
            }
           
            if (modelList != null && modelList.Count > 0)//明细不为空的时候
            {
                StringBuilder strAddSSDetail = new StringBuilder();//增加销售发货单明细中的已出库数量
                strAddSSDetail.AppendLine("update officedba.SellSendDetail set ");
                strAddSSDetail.AppendLine(" OutCount =ISNULL(OutCount,0)+@ReOutCount where ");
                strAddSSDetail.AppendLine(" SendNo=(select SendNo from officedba.SellSend where ID=(select FromBillID from officedba.StorageOutSell where ID=" + model.ID + "))");
                strAddSSDetail.AppendLine(" and SortNo=@SortNo");


                for (int i = 0; i < modelList.Count; i++)
                {
                    SqlCommand commReSSD = new SqlCommand();
                    commReSSD.CommandText = strAddSSDetail.ToString();

                    commReSSD.Parameters.Add(SqlHelper.GetParameterFromString("@ReOutCount", modelList[i].UsedUnitCount));//回写增加的数量(多单位启用时用数量,没启用时用基本数量)
                    commReSSD.Parameters.Add(SqlHelper.GetParameterFromString("@SortNo", modelList[i].FromLineNo));
                    lstConfirm.Add(commReSSD);//循环加入数组(把SellSendDetail已经入库数量增加)


                    SqlCommand commPD = updateStorageProduct(modelList[i].BatchNo, modelList[i].ProductID, modelList[i].StorageID, modelList[i].ProductCount, model, false);
                    lstConfirm.Add(commPD);

                    if (FromBillFromType == "1")
                    {
                        //更新主放仓库的受订量
                        SqlCommand commOrder = new SqlCommand();
                        commOrder = updateOrderCount(modelList[i].BatchNo, modelList[i].ProductID, modelList[i].DefaultStorageID, modelList[i].ProductCount, model.CompanyCD);
                        lstConfirm.Add(commOrder);
                    }
                }
            }
            bool retval=SqlHelper.ExecuteTransWithArrayList(lstConfirm);
            if (retval)
            {
                DataTable dtCurrtype = XBase.Data.Office.FinanceManager.CurrTypeSettingDBHelper.GetMasterCurrency(model.CompanyCD);
                string IsVoucher=((UserInfoUtil)SessionUtil.Session["UserInfo"]).IsVoucher?"1":"0";
                string IsApply=((UserInfoUtil)SessionUtil.Session["UserInfo"]).IsApply?"1":"0";
                int custid = 0;
                if (dtFrom.Rows[0]["CustID"].ToString().Trim() != "")
                    custid = Convert.ToInt32(dtFrom.Rows[0]["CustID"].ToString());
                bool VocherFlag=XBase.Data.Office.FinanceManager.AutoVoucherDBHelper.AutoVoucherInsert(7, model.CompanyCD, IsVoucher,IsApply,Convert.ToDecimal(dtFrom.Rows[0]["TotalPrice"].ToString()), "officedba.StorageOutSell," + model.ID, dtCurrtype.Rows[0]["ID"].ToString()+","+dtCurrtype.Rows[0]["ExchangeRate"].ToString(),custid, out retstrval);
                if (VocherFlag) retstrval = "确认成功!";
                else retstrval = "确认成功!" + retstrval;
            }
            else retstrval = "";
            return retval;
        }
        /// <summary>
        /// 明细参数设置
        /// </summary>
        /// <param name="comm"></param>
        /// <param name="model"></param>
        private static void EditOutSellDetailInfo(SqlCommand comm, StorageOutSellDetailModel model)
        {
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD ", model.CompanyCD));//公司代码
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@OutNo ", model.OutNo));//入库单编号
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ProductID ", model.ProductID));//物品ID
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@StorageID ", model.StorageID));//仓库ID
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@UnitPrice ", model.UnitPrice));//入库单价(基本单价)
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ProductCount ", model.ProductCount));//入库数量(基本数量)
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalPrice ", model.TotalPrice));//入库金额
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Remark ", model.Remark));//备注
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Package ", model.Package));//包装

            comm.Parameters.Add(SqlHelper.GetParameterFromString("@UnitID ", model.UnitID));//基本单位
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@UsedUnitID ", model.UsedUnitID));//实际单位
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@UsedUnitCount ", model.UsedUnitCount));//实际数量
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@UsedPrice ", model.UsedPrice));//实际单价
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ExRate ", model.ExRate));//比率
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@BatchNo ", model.BatchNo));//批次

            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID ", model.ModifiedUserID));//最后更新用户ID(对应操作用户表中的UserID)
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromType ", model.FromType));//
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromBillID ", model.FromBillID));//
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromLineNo ", model.FromLineNo));//
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@SortNo ", model.SortNo));//

        }