protected void btnImport_Click(object sender, ImageClickEventArgs e)
    {
        PurchaseAskPriceModel PurchaseAskPriceM = new PurchaseAskPriceModel();
        PurchaseAskPriceM.CompanyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD;
        PurchaseAskPriceM.AskNo = txtAskNo.Value;
        PurchaseAskPriceM.AskTitle = txtAskTitle.Value;
        PurchaseAskPriceM.FromType = ddlFromType.Value;
        PurchaseAskPriceM.DeptID = hidDeptID.Value;
        PurchaseAskPriceM.AskUserID = hidUserID.Value;
        PurchaseAskPriceM.BillStatus = ddlBillStatus.Value;
        PurchaseAskPriceM.ProviderID = hidProviderID.Value;
        PurchaseAskPriceM.FlowStatus = ddlFlowStatus.Value;
        PurchaseAskPriceM.AskDate = StartAskDate.Value;
        PurchaseAskPriceM.EndAskDate = EndAskDate.Value;
        PurchaseAskPriceM.EFDesc = GetBillExAttrControl1.GetExtTxtValue;
        PurchaseAskPriceM.EFIndex = GetBillExAttrControl1.GetExtIndexValue;

        string OrderBy = hidOrderBy.Value;
        DataTable dt = PurchaseAskPriceBus.GetPurchaseAskPrice(PurchaseAskPriceM,OrderBy);


        OutputToExecl.ExportToTableFormat(this, dt,
            new string[] { "询价单编号", "询价单主题", "供应商", "询价日期", "询价员", "当前询价次数", "金额合计", "税额合计", "含税金额合计", "单据状态", "审批状态" },
            new string[] { "AskNo", "AskTitle", "ProviderName", "AskDate", "AskUserName", "AskOrder", "TotalPrice", "TotalTax", "TotalFee", "BillStatusName", "FlowStatusName" },
            "采购询价单列表");
    }
        /// <summary>
        /// 插入采购询价主表
        /// </summary>
        /// <param name="PurchaseAskPriceM">采购询价主表model</param>
        /// <returns>sqlcommend</returns>
        /// 
        public static SqlCommand InsertPurAskPricePri(PurchaseAskPriceModel PurchaseAskPriceM)
        {
            SqlCommand comm = new SqlCommand();
            #region SQL文
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("INSERT INTO officedba.PurchaseAskPrice");
            sql.AppendLine("           (CompanyCD                 ");
            sql.AppendLine("           ,AskNo                     ");
            sql.AppendLine("           ,AskOrder                  ");
            sql.AppendLine("           ,AskTitle                  ");
            sql.AppendLine("           ,FromType                  ");
            sql.AppendLine("           ,AskDate                   ");
            sql.AppendLine("           ,ProviderID                ");
            sql.AppendLine("           ,DeptID                    ");
            sql.AppendLine("           ,AskUserID                 ");
            sql.AppendLine("           ,TypeID                    ");
            sql.AppendLine("           ,CurrencyType              ");
            sql.AppendLine("           ,Rate                      ");
            sql.AppendLine("           ,TotalPrice                ");
            sql.AppendLine("           ,TotalTax                  ");
            sql.AppendLine("           ,TotalFee                  ");
            sql.AppendLine("           ,Discount                  ");
            sql.AppendLine("           ,DiscountTotal             ");
            sql.AppendLine("           ,RealTotal                 ");
            sql.AppendLine("           ,isAddTax                  ");
            sql.AppendLine("           ,CountTotal                ");
            sql.AppendLine("           ,remark                    ");
            sql.AppendLine("           ,BillStatus                ");
            sql.AppendLine("           ,Creator                   ");
            sql.AppendLine("           ,CreateDate                ");
            sql.AppendLine("           ,ModifiedDate              ");
            sql.AppendLine("           ,ModifiedUserID            ");
            //sql.AppendLine("           ,Confirmor                 ");
            //sql.AppendLine("           ,ConfirmDate               ");
            //sql.AppendLine("           ,Closer                    ");
            //sql.AppendLine("           ,CloseDate                ");
            sql.AppendLine(")");
            sql.AppendLine("     VALUES                           ");
            sql.AppendLine("     	   (@CompanyCD                 ");
            sql.AppendLine("           ,@AskNo                    ");
            sql.AppendLine("           ,@AskOrder                 ");
            sql.AppendLine("           ,@AskTitle                 ");
            sql.AppendLine("           ,@FromType                 ");
            sql.AppendLine("           ,@AskDate                  ");
            sql.AppendLine("           ,@ProviderID               ");
            sql.AppendLine("           ,@DeptID                   ");
            sql.AppendLine("           ,@AskUserID                ");
            sql.AppendLine("           ,@TypeID                   ");
            sql.AppendLine("           ,@CurrencyType             ");
            sql.AppendLine("           ,@Rate                     ");
            sql.AppendLine("           ,@TotalPrice               ");
            sql.AppendLine("           ,@TotalTax                 ");
            sql.AppendLine("           ,@TotalFee                 ");
            sql.AppendLine("           ,@Discount                 ");
            sql.AppendLine("           ,@DiscountTotal            ");
            sql.AppendLine("           ,@RealTotal                ");
            sql.AppendLine("           ,@isAddTax                 ");
            sql.AppendLine("           ,@CountTotal               ");
            sql.AppendLine("           ,@remark                   ");
            sql.AppendLine("           ,@BillStatus               ");
            sql.AppendLine("           ,@Creator                  ");
            sql.AppendLine("           ,@CreateDate               ");
            sql.AppendLine("           ,@ModifiedDate             ");
            sql.AppendLine("           ,@ModifiedUserID           ");
            //sql.AppendLine("           ,@Confirmor                ");
            //sql.AppendLine("           ,@ConfirmDate              ");
            //sql.AppendLine("           ,@Closer                   ");
            //sql.AppendLine("           ,@CloseDate               ");
            sql.AppendLine(")");
            sql.AppendLine("set @IndexID = @@IDENTITY");

            #endregion

            #region 传参
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD",((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskNo", PurchaseAskPriceM.AskNo));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskOrder", PurchaseAskPriceM.AskOrder));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskTitle", PurchaseAskPriceM.AskTitle));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromType", PurchaseAskPriceM.FromType));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskDate", PurchaseAskPriceM.AskDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ProviderID", PurchaseAskPriceM.ProviderID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@DeptID", PurchaseAskPriceM.DeptID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskUserID", PurchaseAskPriceM.AskUserID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TypeID", PurchaseAskPriceM.TypeID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CurrencyType", PurchaseAskPriceM.CurrencyType));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Rate", PurchaseAskPriceM.Rate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalPrice", PurchaseAskPriceM.TotalPrice));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalTax", PurchaseAskPriceM.TotalTax));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalFee", PurchaseAskPriceM.TotalFee));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Discount", PurchaseAskPriceM.Discount));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@DiscountTotal", PurchaseAskPriceM.DiscountTotal));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@RealTotal", PurchaseAskPriceM.RealTotal));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@isAddTax", PurchaseAskPriceM.isAddTax));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CountTotal", PurchaseAskPriceM.CountTotal));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@remark", PurchaseAskPriceM.remark));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@BillStatus", PurchaseAskPriceM.BillStatus));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Creator", PurchaseAskPriceM.Creator));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CreateDate", PurchaseAskPriceM.CreateDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedDate", PurchaseAskPriceM.ModifiedDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID", PurchaseAskPriceM.ModifiedUserID));
            //comm.Parameters.Add(SqlHelper.GetParameterFromString("@Confirmor", PurchaseAskPriceM.Confirmor));
            //comm.Parameters.Add(SqlHelper.GetParameterFromString("@ConfirmDate", PurchaseAskPriceM.ConfirmDate));
            //comm.Parameters.Add(SqlHelper.GetParameterFromString("@Closer", PurchaseAskPriceM.Closer));
            //comm.Parameters.Add(SqlHelper.GetParameterFromString("@CloseDate", PurchaseAskPriceM.CloseDate));

            SqlParameter IndexID = new SqlParameter("@IndexID", SqlDbType.Int);
            IndexID.Direction = ParameterDirection.Output;
            comm.Parameters.Add(IndexID);
            #endregion

            comm.CommandText = sql.ToString();
            return comm;
        }
        public static DataTable SelectPurAskPricePri(PurchaseAskPriceModel PurchaseAskPriceM, string OrderBy)
        {
            SqlCommand comm = new SqlCommand();

            #region SQL文
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("Select ID,CompanyCD,AskNo,AskOrder,AskTitle,FromType,FromTypeName,AskDate,AskUserID,DeptID,AskUserName,ProviderID,ProviderName,TotalPrice,TotalTax     ");
            sql.AppendLine(",TotalFee,BillStatus,BillStatusName,isnull(FlowStatus,'') AS FlowStatus                                                                         ");
            sql.AppendLine(",case FlowStatus WHEN '1' then '待审批' when '2' then '审批中' when '3' then '审批通过'                                                         ");
            sql.AppendLine("when '4' then '审批不通过' when '5' then '撤销审批' else '' end as FlowStatusName,ExtField1,ExtField2,ExtField3,ExtField4,ExtField5,ExtField6,ExtField7,ExtField8,ExtField9,ExtField10                                                            ");
            sql.AppendLine(" from (SELECT A.ID                                                                                                                              ");
            sql.AppendLine("     , isnull(A.CompanyCD  ,'') AS  CompanyCD                                                                                                   ");
            sql.AppendLine("     , isnull(A.AskNo      ,'') AS  AskNo                                                                                                       ");
            sql.AppendLine("     , isnull(A.AskOrder   ,0) AS  AskOrder                                                                                                     ");
            sql.AppendLine("     , isnull(A.AskTitle   ,'') AS  AskTitle                                                                                                    ");
            sql.AppendLine("     , isnull(A.FromType   ,'') AS  FromType                                                                                                    ");
            sql.AppendLine("     ,case A.FromType when '1' then '采购申请单' when '2' then '采购计划单' else '无来源' end as FromTypeName                                   ");
            sql.AppendLine("     , isnull(CONVERT(varchar(23),A.AskDate,23),'') AS  AskDate                                                                                 ");
            sql.AppendLine("     ,isnull(A.AskUserID,0) AS AskUserID   ,A.DeptID");
            sql.AppendLine("     ,isnull(D.EmployeeName,'') AS AskUserName                                                                                                  ");
            sql.AppendLine("     , isnull(A.ProviderID ,0) AS  ProviderID                                                                                                   ");
            sql.AppendLine("     , isnull(B.CustName   ,'') AS  ProviderName                                                                                                ");
            sql.AppendLine("     , isnull(A.TotalPrice ,0) AS  TotalPrice                                                                                                   ");
            sql.AppendLine("     , isnull(A.TotalTax   ,0) AS  TotalTax                                                                                                     ");
            sql.AppendLine("     , isnull(A.TotalFee   ,0) AS  TotalFee                                                                                                     ");
            sql.AppendLine("     , isnull(A.BillStatus ,'') AS  BillStatus                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField1 ,'') AS  ExtField1                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField2 ,'') AS  ExtField2                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField3 ,'') AS  ExtField3                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField4 ,'') AS  ExtField4                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField5 ,'') AS  ExtField5                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField6 ,'') AS  ExtField6                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField7 ,'') AS  ExtField7                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField8 ,'') AS  ExtField8                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField9 ,'') AS  ExtField9                                                                                                  ");
            sql.AppendLine("     , isnull(A.ExtField10 ,'') AS  ExtField10                                                                                                  ");
            sql.AppendLine("     ,case A.BillStatus when '1' then '制单' when '2' then '执行' when '3' then '变更'                                                          ");
            sql.AppendLine("when '4' then '手工结单' when '5' then '自动结单' end AS BillStatusName                                                                         ");
            sql.AppendLine(",(SELECT top 1 FlowStatus FROM officedba.FlowInstance  WHERE BillTypeFlag=6 AND BillTypeCode=3 AND BillID= A.ID ORDER BY ID DESC ) AS FlowStatus");
            sql.AppendLine(" FROM         officedba.PurchaseAskPrice AS A                                                                                                   ");
            sql.AppendLine(" LEFT JOIN officedba.ProviderInfo AS B ON A.ProviderID = B.ID                                                                                   ");
            sql.AppendLine(" LEFT JOIN officedba.EmployeeInfo AS D ON A.AskUserID = D.ID  )AS E                                                                             ");

            sql.AppendLine(" WHERE CompanyCD=@CompanyCD");
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD", ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD));

            if (PurchaseAskPriceM.AskNo != "")
            {
                sql.AppendLine(" AND AskNo like @AskNo");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskNo", "%" + PurchaseAskPriceM.AskNo + "%"));
            }
            if (PurchaseAskPriceM.AskTitle != "")
            {
                sql.AppendLine(" AND AskTitle like @AskTitle");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskTitle", "%" + PurchaseAskPriceM.AskTitle + "%"));
            }
            if (PurchaseAskPriceM.FromType != "a")
            {
                sql.AppendLine(" AND FromType=@FromType");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromType", PurchaseAskPriceM.FromType));
            }
            if (PurchaseAskPriceM.DeptID != "")
            {
                sql.AppendLine(" AND DeptID=@DeptID");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@DeptID", PurchaseAskPriceM.DeptID));
            }
            if (PurchaseAskPriceM.AskUserID != "")
            {
                sql.AppendLine(" AND AskUserID=@AskUserID");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskUserID", PurchaseAskPriceM.AskUserID));
            }
            if (PurchaseAskPriceM.ProviderID != "")
            {
                sql.AppendLine(" AND ProviderID=@ProviderID");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@ProviderID", PurchaseAskPriceM.ProviderID));
            }
            if (PurchaseAskPriceM.BillStatus != "0")
            {
                sql.AppendLine(" AND BillStatus=@BillStatus");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@BillStatus", PurchaseAskPriceM.BillStatus));
            }
            if (PurchaseAskPriceM.FlowStatus != "")
            {
                if (PurchaseAskPriceM.FlowStatus == "0")
                {
                    sql.AppendLine(" AND FlowStatus is NULL ");
                }
                else
                {
                    sql.AppendLine(" AND FlowStatus=@FlowStatus");
                    comm.Parameters.Add(SqlHelper.GetParameterFromString("@FlowStatus", PurchaseAskPriceM.FlowStatus));
                }
            }
            if (PurchaseAskPriceM.AskDate != "")
            {
                sql.AppendLine(" AND AskDate >= @StartAskDate");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@StartAskDate", PurchaseAskPriceM.AskDate));

            }
            if (PurchaseAskPriceM.EndAskDate != "")
            {
                sql.AppendLine(" AND AskDate <= @EndAskDate");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@EndAskDate", PurchaseAskPriceM.EndAskDate));
            }
            if (!string.IsNullOrEmpty(PurchaseAskPriceM.EFIndex) && !string.IsNullOrEmpty(PurchaseAskPriceM.EFDesc))
            {
                sql.AppendLine(" and ExtField" + PurchaseAskPriceM.EFIndex + " LIKE @EFDesc");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@EFDesc", "%" + PurchaseAskPriceM.EFDesc + "%"));
            }
            sql.AppendLine(" ORDER BY "+OrderBy+"");
            #endregion

            comm.CommandText = sql.ToString();
            return SqlHelper.ExecuteSearch(comm);
        }
        /// <summary>
        ///更新采购询价主表
        /// </summary>
        /// <param name="PurchaseAskPriceM">采购询价主表model</param>
        /// <returns>sqlcommend</returns>
        /// 
        public static SqlCommand UpdatePurAskPricePri(PurchaseAskPriceModel PurchaseAskPriceM)
        {
            SqlCommand comm = new SqlCommand();

            #region SQL文
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("UPDATE officedba.PurchaseAskPrice ");
            sql.AppendLine("   SET CompanyCD      =@CompanyCD       ");
            sql.AppendLine("      ,AskNo          =@AskNo           ");
            sql.AppendLine("      ,AskOrder       =@AskOrder        ");
            sql.AppendLine("      ,AskTitle       =@AskTitle        ");
            sql.AppendLine("      ,FromType       =@FromType        ");
            sql.AppendLine("      ,AskDate        =@AskDate         ");
            sql.AppendLine("      ,ProviderID     =@ProviderID      ");
            sql.AppendLine("      ,DeptID         =@DeptID          ");
            sql.AppendLine("      ,AskUserID      =@AskUserID       ");
            sql.AppendLine("      ,TypeID         =@TypeID          ");
            sql.AppendLine("      ,CurrencyType   =@CurrencyType    ");
            sql.AppendLine("      ,Rate           =@Rate            ");
            sql.AppendLine("      ,TotalPrice     =@TotalPrice      ");
            sql.AppendLine("      ,TotalTax       =@TotalTax        ");
            sql.AppendLine("      ,TotalFee       =@TotalFee        ");
            sql.AppendLine("      ,Discount       =@Discount        ");
            sql.AppendLine("      ,DiscountTotal  =@DiscountTotal   ");
            sql.AppendLine("      ,RealTotal      =@RealTotal       ");
            sql.AppendLine("      ,isAddTax       =@isAddTax        ");
            sql.AppendLine("      ,CountTotal     =@CountTotal      ");
            sql.AppendLine("      ,BillStatus     =@BillStatus      ");
            sql.AppendLine("      ,Confirmor      =@Confirmor     ");
            sql.AppendLine("      ,ConfirmDate    =@ConfirmDate ");
            sql.AppendLine("      ,remark         =@remark          ");
            sql.AppendLine("      ,ModifiedDate   =getDate()    ");
            sql.AppendLine("      ,ModifiedUserID =@ModifiedUserID  ");
            sql.AppendLine("WHERE ID=@ID                            ");
            #endregion

            #region 传参
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD", ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskNo", PurchaseAskPriceM.AskNo));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskOrder", PurchaseAskPriceM.AskOrder));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskTitle", PurchaseAskPriceM.AskTitle));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromType", PurchaseAskPriceM.FromType));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskDate", PurchaseAskPriceM.AskDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ProviderID", PurchaseAskPriceM.ProviderID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@DeptID", PurchaseAskPriceM.DeptID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@AskUserID", PurchaseAskPriceM.AskUserID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TypeID", PurchaseAskPriceM.TypeID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CurrencyType", PurchaseAskPriceM.CurrencyType));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Rate", PurchaseAskPriceM.Rate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalPrice", PurchaseAskPriceM.TotalPrice));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalTax", PurchaseAskPriceM.TotalTax));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalFee", PurchaseAskPriceM.TotalFee));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Discount", PurchaseAskPriceM.Discount));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@DiscountTotal", PurchaseAskPriceM.DiscountTotal));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@RealTotal", PurchaseAskPriceM.RealTotal));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@isAddTax", PurchaseAskPriceM.isAddTax));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CountTotal", PurchaseAskPriceM.CountTotal));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@BillStatus", PurchaseAskPriceM.BillStatus));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Confirmor", PurchaseAskPriceM.Confirmor));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ConfirmDate", PurchaseAskPriceM.ConfirmDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@remark", PurchaseAskPriceM.remark));
            //comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedDate", PurchaseAskPriceM.ModifiedDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID", PurchaseAskPriceM.ModifiedUserID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ID", PurchaseAskPriceM.ID));
            #endregion

            comm.CommandText = sql.ToString();
            return comm;
        }
        /// <summary>
        /// 插入采购询价单
        /// </summary>
        /// <param name="PurchaseAskPriceM">采购询价单主表model</param>
        /// <param name="PurchaseAskPriceDetailMList">采购询价单明细表model列表</param>
        /// <returns>bool</returns>
        public static bool InsertPurchaseAskPrice(PurchaseAskPriceModel PurchaseAskPriceM
            , List<PurchaseAskPriceDetailModel> PurchaseAskPriceDetailMList, out int IndexIDentity, Hashtable htExtAttr)
        {
            try
            {
                ArrayList lstAdd = new ArrayList();
                SqlCommand AddPri = PurchaseAskPriceDBHelper.InsertPurAskPricePri(PurchaseAskPriceM);
                lstAdd.Add(AddPri);
                foreach (PurchaseAskPriceDetailModel PurchaseAskPriceDetailM in PurchaseAskPriceDetailMList)
                {
                    SqlCommand AddDtl = PurchaseAskPriceDBHelper.InsertPurAskPriceDetail(PurchaseAskPriceDetailM);
                    lstAdd.Add(AddDtl);
                }

                #region 拓展属性
                SqlCommand cmd = new SqlCommand();
                GetExtAttrCmd(PurchaseAskPriceM, htExtAttr, cmd);
                if (htExtAttr.Count > 0)
                    lstAdd.Add(cmd);
                #endregion

                //获取登陆用户信息
                UserInfoUtil userInfo = (UserInfoUtil)SessionUtil.Session["UserInfo"];
                //定义返回变量
                bool isSucc = false;
                /* 
                 * 定义日志内容变量 
                 * 增删改相关的日志,需要输出操作日志,该类型日志插入到数据库
                 * 其他的 如出现异常时,需要输出系统日志,该类型日志保存到日志文件
                 */

                //执行插入操作
                try
                {
                    isSucc = SqlHelper.ExecuteTransWithArrayList(lstAdd);
                }
                catch (Exception ex)
                {
                    //输出日志
                    WriteSystemLog(userInfo, ex);
                }


                //定义变量
                string remark;
                //成功时
                if (isSucc)
                {
                    //设置操作成功标识
                    remark = ConstUtil.LOG_PROCESS_SUCCESS;
                    IndexIDentity = int.Parse(((SqlCommand)AddPri).Parameters["@IndexID"].Value.ToString());
                }
                else
                {
                    //设置操作成功标识 
                    remark = ConstUtil.LOG_PROCESS_FAILED;
                    IndexIDentity = 0;
                }

                LogInfoModel logModel = InitLogInfo(PurchaseAskPriceM.AskNo);
                //涉及关键元素 这个需要根据每个页面具体设置,本页面暂时设置为空
                logModel.Element = ConstUtil.LOG_PROCESS_INSERT;
                //设置操作成功标识
                logModel.Remark = remark;

                //登陆日志
                LogDBHelper.InsertLog(logModel);
                return isSucc;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable GetPurchaseAskPrice(PurchaseAskPriceModel PurchaseAskPriceM, string OrderBy)
        {
            try
            {
                DataTable dt = PurchaseAskPriceDBHelper.SelectPurAskPricePri(PurchaseAskPriceM,OrderBy);
                //DataColumn JoinName = new DataColumn();
                //dt.Columns.Add("IsCite");
                //for (int i = 0; i < dt.Rows.Count; i++)
                //{
                //    string ID = dt.Rows[i]["ID"].ToString();

                //    bool IsCite = PurchaseAskPriceDBHelper.IsCite(ID);

                //    dt.Rows[i]["IsCite"] = IsCite;
                //}
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新采购询价单
        /// </summary>
        /// <param name="PurchaseAskPriceM">采购询价单主表model</param>
        /// <param name="PurchaseAskPriceDetailMList">采购询价单明细表model列表</param>
        /// <returns>bool</returns>
        /// 
        public static bool UpdatePurchaseAskPrice(PurchaseAskPriceModel PurchaseAskPriceM
            , List<PurchaseAskPriceDetailModel> PurchaseAskPriceDetailMList, Hashtable htExtAttr)
        {
            try
            {
                ArrayList lstUpdate = new ArrayList();
                if (PurchaseAskPriceM.AskAgain == "1")
                {//再次询价,需将此次询价之前的那次询价记录记入询价历史表
                    SqlCommand AskAgain = PurchaseAskPriceDBHelper.InsertPurchaseAskHistory(PurchaseAskPriceM.ID);
                    lstUpdate.Add(AskAgain);
                }
                SqlCommand UpdatePri = PurchaseAskPriceDBHelper.UpdatePurAskPricePri(PurchaseAskPriceM);
                lstUpdate.Add(UpdatePri);
                  #region 拓展属性
            SqlCommand cmd = new SqlCommand();
            GetExtAttrCmd(PurchaseAskPriceM, htExtAttr, cmd);
            if (htExtAttr.Count > 0)
                lstUpdate.Add(cmd);
            #endregion

                SqlCommand DelDtl = PurchaseAskPriceDBHelper.DeletePurAskPriceDetail(PurchaseAskPriceM.AskNo);
                lstUpdate.Add(DelDtl);
                foreach (PurchaseAskPriceDetailModel PurchaseAskPriceDetailM in PurchaseAskPriceDetailMList)
                {
                    SqlCommand AddDtl = PurchaseAskPriceDBHelper.InsertPurAskPriceDetail(PurchaseAskPriceDetailM);
                    lstUpdate.Add(AddDtl);
                }

                //获取登陆用户信息
                UserInfoUtil userInfo = (UserInfoUtil)SessionUtil.Session["UserInfo"];
                //定义返回变量
                bool isSucc = false;
                /* 
                 * 定义日志内容变量 
                 * 增删改相关的日志,需要输出操作日志,该类型日志插入到数据库
                 * 其他的 如出现异常时,需要输出系统日志,该类型日志保存到日志文件
                 */

                //执行插入操作
                try
                {
                    isSucc = SqlHelper.ExecuteTransWithArrayList(lstUpdate);
                }
                catch (Exception ex)
                {
                    //输出日志
                    WriteSystemLog(userInfo, ex);
                }


                //定义变量
                string remark;
                //成功时
                if (isSucc)
                {
                    //设置操作成功标识
                    remark = ConstUtil.LOG_PROCESS_SUCCESS;
                }
                else
                {
                    //设置操作成功标识 
                    remark = ConstUtil.LOG_PROCESS_FAILED;
                }

                LogInfoModel logModel = InitLogInfo(PurchaseAskPriceM.AskNo);
                //涉及关键元素 这个需要根据每个页面具体设置,本页面暂时设置为空
                logModel.Element = ConstUtil.LOG_PROCESS_INSERT;
                //设置操作成功标识
                logModel.Remark = remark;

                //登陆日志
                LogDBHelper.InsertLog(logModel);
                return isSucc;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 扩展属性保存操作
        /// </summary>
        /// <returns></returns>
        private static void GetExtAttrCmd(PurchaseAskPriceModel model, Hashtable htExtAttr, SqlCommand cmd)
        {
            try
            {
                string strSql = string.Empty;

                strSql = "UPDATE officedba.PurchaseAskPrice set ";
                foreach (DictionaryEntry de in htExtAttr)// fileht为一个Hashtable实例
                {
                    strSql += de.Key.ToString().Trim() + "=@" + de.Key.ToString().Trim() + ",";
                    cmd.Parameters.AddWithValue("@" + de.Key.ToString().Trim(), de.Value.ToString().Trim());
                }
                int iLength = strSql.Length - 1;
                strSql = strSql.Substring(0, iLength);
                strSql += " where CompanyCD = @CompanyCD  AND AskNo = @AskNo";
                cmd.Parameters.AddWithValue("@CompanyCD",((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD);
                cmd.Parameters.AddWithValue("@AskNo", model.AskNo );
                cmd.CommandText = strSql;
            }
            catch (Exception)
            { }


        }