protected void btnImport_Click(object sender, ImageClickEventArgs e)
    {
        PurchasePlanModel PurchasePlanM = new PurchasePlanModel();
        PurchasePlanM.CompanyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD;
        PurchasePlanM.PlanNo = txtPlanNo.Value;
        PurchasePlanM.Title = txtPlanTitle.Value;

        PurchasePlanM.PlanUserID = PlanUserID.Value;
        PurchasePlanM.PlanMoney = txtTotalMoneyMin.Value;
        PurchasePlanM.TotalMoneyMax = txtTotalMoneyMax.Value;
        PurchasePlanM.PlanDeptID = txtDeptID.Value;
        PurchasePlanM.PlanDate = txtStartPlanDate.Value;
        PurchasePlanM.EndPlanDate = txtEndPlanDate.Value;
        PurchasePlanM.BillStatus = ddlFlowStatus.Value;
        PurchasePlanM.FlowStatus = ddlFlowStatus.Value;
        PurchasePlanM.EFIndex = GetBillExAttrControl1.GetExtIndexValue;
        PurchasePlanM.EFDesc = GetBillExAttrControl1.GetExtTxtValue;
        string OrderBy = hidOrderBy.Value;
        //XElement dsXML = ConvertDataTableToXML(PurchasePlanBus.SelectPurchasePlan(PurchasePlanM));
        DataTable dt = PurchasePlanBus.SelectPurchasePlan(PurchasePlanM,OrderBy);

        OutputToExecl.ExportToTableFormat(this, dt,
            new string[] { "计划单编号", "计划单主题", "计划员", "预控金额", "计划时间", "单据状态", "审批状态"},
            new string[] { "PlanNo", "PlanTitle", "PlanUserName", "PlanMoney", "PlanDate", "BillStatusName", "FlowStatusName"},
            "采购计划列表");
    }
 public static DataTable SelectPurchasePlan(PurchasePlanModel PurchasePlanM, string OrderBy)
 {
     try
     {
         DataTable dt = PurchasePlanDBHelper.SelectPurchasePlanPrimary(PurchasePlanM, OrderBy);
         return dt;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static DataTable SelectPurchasePlan(PurchasePlanModel PurchasePlanM, int pageIndex, int pageCount, string OrderBy, ref int totalCount)
        {
            try
            {
                DataTable dt = PurchasePlanDBHelper.SelectPurchasePlanPrimary(PurchasePlanM,pageIndex,pageCount,OrderBy,ref totalCount);
                //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 = PurchasePlanDBHelper.IsCitePurPlan(ID);

                //    dt.Rows[i]["IsCite"] = IsCite;
                //}
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 采购计划新增
        /// </summary>
        /// <param name="PurchasePlanM">主表model</param>
        /// <param name="PurchasePlanSourceMList">明细来源表model列表</param>
        /// <param name="PurchasePlanDetailMList">明细表model列表</param>
        /// <param name="IndexIDentity">主表ID</param>
        /// <returns>bool</returns>
        public static bool InsertPurchasePlanAll(PurchasePlanModel PurchasePlanM, List<PurchasePlanSourceModel> PurchasePlanSourceMList,
            List<PurchasePlanDetailModel> PurchasePlanDetailMList, out int IndexIDentity, Hashtable htExtAttr)
        {
            ArrayList lstAdd = new ArrayList();

            SqlCommand AddPri = PurchasePlanDBHelper.InsertPurchasePlanPrimary(PurchasePlanM);
            lstAdd.Add(AddPri);
            foreach (PurchasePlanSourceModel PurchasePlanSourceM in PurchasePlanSourceMList)
            {
                SqlCommand AddSource = PurchasePlanDBHelper.InsertPurchasePlanSource(PurchasePlanSourceM);
                lstAdd.Add(AddSource);
            }
            foreach (PurchasePlanDetailModel PurchasePlanDetailM in PurchasePlanDetailMList)
            {
                SqlCommand AddDetail = PurchasePlanDBHelper.InsertPurchasePlanDetail(PurchasePlanDetailM);
                lstAdd.Add(AddDetail);
            }
            #region 拓展属性
            SqlCommand cmd = new SqlCommand();
            GetExtAttrCmd(PurchasePlanM, 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(PurchasePlanM.PlanNo);
            //涉及关键元素 这个需要根据每个页面具体设置,本页面暂时设置为空
            logModel.Element = ConstUtil.LOG_PROCESS_INSERT;
            //设置操作成功标识
            logModel.Remark = remark;

            //登陆日志
            LogDBHelper.InsertLog(logModel);
            return isSucc;
        }
        /// <summary>
        /// 修改采购计划
        /// </summary>
        /// <param name="PurchasePlanM">主表model</param>
        /// <param name="PurchasePlanSourceMList">明细来源表model列表</param>
        /// <param name="PurchasePlanDetailMList">明细表model列表</param>
        /// <returns>bool</returns>
        public static bool UpdatePurchasePlanAll(PurchasePlanModel PurchasePlanM, List<PurchasePlanSourceModel> PurchasePlanSourceMList,
            List<PurchasePlanDetailModel> PurchasePlanDetailMList, Hashtable htExtAttr)
        {
            ArrayList lstUpdate = new ArrayList();

            //更新主表
            SqlCommand UpdatePri = PurchasePlanDBHelper.UpdatePurchasePlanPrimary(PurchasePlanM);
            lstUpdate.Add(UpdatePri);
              #region 拓展属性
            SqlCommand cmd = new SqlCommand();
            GetExtAttrCmd(PurchasePlanM, htExtAttr, cmd);
            if (htExtAttr.Count > 0)
                lstUpdate.Add(cmd);
            #endregion

            //删除来源表
            SqlCommand DeleteSource = PurchasePlanDBHelper.DeletePurchasePlanSource(PurchasePlanM.PlanNo);
            lstUpdate.Add(DeleteSource);

            //新增来源表
            foreach (PurchasePlanSourceModel PurchasePlanSourceM in PurchasePlanSourceMList)
            {
                SqlCommand AddSource = PurchasePlanDBHelper.InsertPurchasePlanSource(PurchasePlanSourceM);
                lstUpdate.Add(AddSource);
            }

            //删除明细表
            SqlCommand DeleteDetail = PurchasePlanDBHelper.DeletePurchasePlanDetail(PurchasePlanM.PlanNo);
            lstUpdate.Add(DeleteDetail);

            //新增明细表
            foreach (PurchasePlanDetailModel PurchasePlanDetailM in PurchasePlanDetailMList)
            {
                SqlCommand AddDetail = PurchasePlanDBHelper.InsertPurchasePlanDetail(PurchasePlanDetailM);
                lstUpdate.Add(AddDetail);
            }
            

            //获取登陆用户信息
            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(PurchasePlanM.PlanNo);
            //涉及关键元素 这个需要根据每个页面具体设置,本页面暂时设置为空
            logModel.Element = ConstUtil.LOG_PROCESS_UPDATE;
            //设置操作成功标识
            logModel.Remark = remark;

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

                strSql = "UPDATE officedba.PurchasePlan 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 PlanNo = @PlanNo";
                cmd.Parameters.AddWithValue("@CompanyCD", model.CompanyCD);
                cmd.Parameters.AddWithValue("@PlanNo", model.PlanNo );
                cmd.CommandText = strSql;
            }
            catch (Exception)
            { }


        }
        public static DataTable SelectPurchasePlanPrimary(PurchasePlanModel PurchasePlanM, string OrderBy)
        {
            SqlCommand comm = new SqlCommand();

            #region SQL文
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("SELECT isnull(A.ID          ,0)   AS  ID                                                 ");
            sql.AppendLine("      ,isnull(A.PlanNo      ,'')  AS  PlanNo                                             ");
            sql.AppendLine("      ,isnull(A.Title       ,'')  AS  PlanTitle                                          ");
            sql.AppendLine("      ,isnull(A.PlanUserID  ,0)   AS  PlanUserID                                         ");
            sql.AppendLine("      ,isnull(B.EmployeeName,'')  AS  PlanUserName                                       ");
            sql.AppendLine("      ,isnull(CONVERT(varchar(100), A.PlanDate, 23),'') as PlanDate                   ");
            sql.AppendLine("      ,isnull(A.PlanDeptID  ,0)   AS  PlanDeptID                                         ");
            sql.AppendLine("	  	,isnull(C.DeptName    ,'')  AS  PlanDeptName                                     ");
            sql.AppendLine("      ,isnull(A.PlanMoney   , 0)  AS  PlanMoney                                          ");
            sql.AppendLine("      ,isnull(A.BillStatus  ,'')  AS  BillStatus                                         ");
            sql.AppendLine(" ,isnull(A.CountTotal,0) AS CountTotal ");
            sql.AppendLine(" ,case A.BillStatus when '1' then '制单' when '2' then '执行' when '3' then '变更'       ");
            sql.AppendLine(" when '4' then '手动结单' when '5' then '自动结单' else '出错了' end AS BillStatusName   ");
            sql.AppendLine("	,isnull(D.FlowStatus,'')  AS FlowStatus                                              ");
            sql.AppendLine(" ,case D.FlowStatus when '1' then '待审批' when '2' then '审批中' when '3' then '审批通过' ");
            sql.AppendLine(" when '4' then '审批不通过' else '' END AS FlowStatusName");
            sql.AppendLine("  FROM officedba.PurchasePlan AS A                                                       ");
            sql.AppendLine("  LEFT JOIN officedba.EmployeeInfo AS B ON A.CompanyCD=B.CompanyCD AND A.PlanUserID=B.ID ");
            sql.AppendLine("  LEFT JOIN officedba.DeptInfo AS C ON A.CompanyCD=C.CompanyCD AND A.PlanDeptID=C.ID     ");
            sql.AppendLine("  LEFT JOIN officedba.FlowInstance AS D ON A.CompanyCD=D.CompanyCD AND D.BillTypeFlag=6  ");
            sql.AppendLine("  AND D.BillTypeCode=2 AND A.ID=D.BillID                                 ");
            sql.AppendLine(" AND D.ID=(SELECT max(ID) FROM officedba.FlowInstance AS F WHERE A.ID = F.BillID AND F.BillTypeFlag = 6 AND F.BillTypeCode = 2)");
            sql.AppendLine(" WHERE 1=1");
            sql.AppendLine(" AND A.CompanyCD=@CompanyCD");
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD", PurchasePlanM.CompanyCD));
            if (PurchasePlanM.PlanNo != "")
            {
                sql.AppendLine(" AND  A.PlanNo like @PlanNo");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanNo", "%" + PurchasePlanM.PlanNo + "%"));
            }
            if (PurchasePlanM.Title != "")
            {
                sql.AppendLine("  AND A.Title like @Title ");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@Title", "%" + PurchasePlanM.Title + "%"));
            }
            if (PurchasePlanM.PlanUserID != "")
            {
                sql.AppendLine(" AND A.PlanUserID = @PlanUserID");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanUserID", PurchasePlanM.PlanUserID));
            }
            if (PurchasePlanM.PlanMoney != "")
            {
                sql.AppendLine(" AND A.PlanMoney >= @PlanMoney");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanMoney", PurchasePlanM.PlanMoney));
            }
            if (PurchasePlanM.TotalMoneyMax != "")
            {
                sql.AppendLine(" AND A.PlanMoney <= @TotalMoneyMax");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalMoneyMax", PurchasePlanM.TotalMoneyMax));
            }
            if (PurchasePlanM.PlanDeptID != "")
            {
                sql.AppendLine(" AND A.PlanDeptID = @PlanDeptID");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanDeptID", PurchasePlanM.PlanDeptID));
            }
            if (PurchasePlanM.PlanDate != "")
            {
                sql.AppendLine(" AND A.PlanDate >= @PlanDate");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanDate", PurchasePlanM.PlanDate));
            }
            if (PurchasePlanM.EndPlanDate != "")
            {
                sql.AppendLine(" AND A.PlanDate <= @EndPlanDate");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@EndPlanDate", PurchasePlanM.EndPlanDate));
            }
            if (PurchasePlanM.FlowStatus != "0")
            {
                if (PurchasePlanM.FlowStatus == "")
                {
                    sql.AppendLine(" AND D.FlowStatus is null");
                }
                else
                {
                    sql.AppendLine(" AND D.FlowStatus = @FlowStatus ");
                    comm.Parameters.Add(SqlHelper.GetParameterFromString("@FlowStatus", PurchasePlanM.FlowStatus));
                }
            }
            if (PurchasePlanM.BillStatus != "0")
            {
                sql.AppendLine(" AND A.BillStatus = @BillStatus");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@BillStatus", PurchasePlanM.BillStatus));
            }

            if (!string.IsNullOrEmpty(PurchasePlanM.EFIndex) && !string.IsNullOrEmpty(PurchasePlanM.EFDesc))
            {
                sql.AppendLine(" and a.ExtField" + PurchasePlanM.EFIndex + " LIKE @EFDesc");
                comm.Parameters.Add(SqlHelper.GetParameterFromString("@EFDesc", "%" + PurchasePlanM.EFDesc + "%"));
            }



            sql.AppendLine(" ORDER BY "+OrderBy+"");
            #endregion
            comm.CommandText = sql.ToString();
            return SqlHelper.ExecuteSearch(comm);

            //return SqlHelper.ExecuteSql(sql.ToString());
        }
        public static SqlCommand UpdatePurchasePlanPrimary(PurchasePlanModel PurchasePlanM)
        {
            SqlCommand comm = new SqlCommand();

            #region SQL文
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("UPDATE officedba.PurchasePlan          ");
            sql.AppendLine("   SET CompanyCD     =@CompanyCD       ");
            sql.AppendLine("      ,PlanNo        =@PlanNo          ");
            sql.AppendLine("      ,Title         =@Title           ");
            sql.AppendLine("      ,FromType      =@FromType        ");
            sql.AppendLine("      ,PlanUserID    =@PlanUserID      ");
            sql.AppendLine("      ,Purchaser     =@Purchaser       ");
            sql.AppendLine("      ,PlanDate      =@PlanDate        ");
            sql.AppendLine("      ,PlanDeptID    =@PlanDeptID      ");
            sql.AppendLine("      ,PlanMoney     =@PlanMoney       ");
            sql.AppendLine("      ,CountTotal    =@CountTotal      ");
            sql.AppendLine("      ,CurrencyType  =@CurrencyType    ");
            sql.AppendLine("      ,Rate          =@Rate            ");
            sql.AppendLine("      ,BillStatus    =@BillStatus      ");
            sql.AppendLine("      ,TypeID        =@TypeID          ");
            sql.AppendLine("      ,Remark        =@Remark          ");
            sql.AppendLine("      ,Creator       =@Creator         ");
            sql.AppendLine("      ,CreateDate    =@CreateDate      ");
            sql.AppendLine("      ,Confirmor     =@Confirmor       ");
            sql.AppendLine("      ,ConfirmDate   =@ConfirmDate     ");
            sql.AppendLine("      ,Closer        =@Closer          ");
            sql.AppendLine("      ,CloseDate     =@CloseDate       ");
            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("@PlanNo", PurchasePlanM.PlanNo));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Title", PurchasePlanM.Title));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromType", PurchasePlanM.FromType));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanUserID", PurchasePlanM.PlanUserID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Purchaser", PurchasePlanM.Purchaser));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanDate", PurchasePlanM.PlanDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanDeptID", PurchasePlanM.PlanDeptID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanMoney", PurchasePlanM.PlanMoney));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CountTotal", PurchasePlanM.CountTotal));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CurrencyType", PurchasePlanM.CurrencyType));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Rate", PurchasePlanM.Rate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@BillStatus", PurchasePlanM.BillStatus));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TypeID", PurchasePlanM.TypeID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Remark", PurchasePlanM.Remark));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Creator", PurchasePlanM.Creator));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CreateDate", PurchasePlanM.CreateDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Confirmor", PurchasePlanM.Confirmor));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ConfirmDate", PurchasePlanM.ConfirmDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Closer", PurchasePlanM.Closer));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CloseDate", PurchasePlanM.CloseDate));
            //comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedDate", PurchasePlanM.ModifiedDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID", PurchasePlanM.ModifiedUserID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ID", PurchasePlanM.ID));
            #endregion

            comm.CommandText = sql.ToString();

            return comm;
        }
        public static SqlCommand InsertPurchasePlanPrimary(PurchasePlanModel PurchasePlanM)
        {
            SqlCommand comm = new SqlCommand();

            #region SQL文
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("INSERT INTO officedba.PurchasePlan ");
            sql.AppendLine("           (CompanyCD              ");
            sql.AppendLine("           ,PlanNo                 ");
            sql.AppendLine("           ,Title                  ");
            sql.AppendLine("           ,FromType               ");
            sql.AppendLine("           ,PlanUserID             ");
            sql.AppendLine("           ,Purchaser              ");
            sql.AppendLine("           ,PlanDate               ");
            sql.AppendLine("           ,PlanDeptID             ");
            sql.AppendLine("           ,PlanMoney              ");
            sql.AppendLine("           ,CountTotal             ");
            sql.AppendLine("           ,CurrencyType           ");
            sql.AppendLine("           ,Rate                   ");
            sql.AppendLine("           ,BillStatus             ");
            sql.AppendLine("           ,TypeID                 ");
            sql.AppendLine("           ,Remark                 ");
            sql.AppendLine("           ,Creator                ");
            sql.AppendLine("           ,CreateDate             ");
            sql.AppendLine("           ,Confirmor              ");
            sql.AppendLine("           ,ConfirmDate            ");
            sql.AppendLine("           ,Closer                 ");
            sql.AppendLine("           ,CloseDate              ");
            sql.AppendLine("           ,ModifiedDate           ");
            sql.AppendLine("           ,ModifiedUserID         ");
            sql.AppendLine("           )                       ");
            sql.AppendLine("     VALUES(                       ");
            sql.AppendLine("    		@CompanyCD             ");
            sql.AppendLine("           ,@PlanNo                ");
            sql.AppendLine("           ,@Title                 ");
            sql.AppendLine("           ,@FromType              ");
            sql.AppendLine("           ,@PlanUserID            ");
            sql.AppendLine("           ,@Purchaser             ");
            sql.AppendLine("           ,@PlanDate              ");
            sql.AppendLine("           ,@PlanDeptID            ");
            sql.AppendLine("           ,@PlanMoney             ");
            sql.AppendLine("           ,@CountTotal            ");
            sql.AppendLine("           ,@CurrencyType          ");
            sql.AppendLine("           ,@Rate                  ");
            sql.AppendLine("           ,@BillStatus            ");
            sql.AppendLine("           ,@TypeID                ");
            sql.AppendLine("           ,@Remark                ");
            sql.AppendLine("           ,@Creator               ");
            sql.AppendLine("           ,@CreateDate            ");
            sql.AppendLine("           ,@Confirmor             ");
            sql.AppendLine("           ,@ConfirmDate           ");
            sql.AppendLine("           ,@Closer                ");
            sql.AppendLine("           ,@CloseDate             ");
            sql.AppendLine("           ,@ModifiedDate          ");
            sql.AppendLine("           ,@ModifiedUserID        ");
            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("@PlanNo", PurchasePlanM.PlanNo));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Title", PurchasePlanM.Title));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromType", PurchasePlanM.FromType));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanUserID", PurchasePlanM.PlanUserID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Purchaser", PurchasePlanM.Purchaser));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanDate", PurchasePlanM.PlanDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanDeptID", PurchasePlanM.PlanDeptID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@PlanMoney", PurchasePlanM.PlanMoney));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CountTotal", PurchasePlanM.CountTotal));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CurrencyType", PurchasePlanM.CurrencyType));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Rate", PurchasePlanM.Rate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@BillStatus", PurchasePlanM.BillStatus));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@TypeID", PurchasePlanM.TypeID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Remark", PurchasePlanM.Remark));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Creator", PurchasePlanM.Creator));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CreateDate", PurchasePlanM.CreateDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Confirmor", PurchasePlanM.Confirmor));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ConfirmDate", PurchasePlanM.ConfirmDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Closer", PurchasePlanM.Closer));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CloseDate", PurchasePlanM.CloseDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedDate", PurchasePlanM.ModifiedDate));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID", PurchasePlanM.ModifiedUserID));

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

            comm.CommandText = sql.ToString();

            return comm;
        }