/// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool InsertCompanyBaseInfo(CompanyBaseInfoModel model)
 {
     try
     {
         string loginUserID = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).UserID;
         model.ModifiedUserID = loginUserID;
         return CompanyBaseInfoDBHelper.InsertCompanyBaseInfo(model);
     }
     catch(System .Exception ex)
     {
         throw ex;
     }
   
 }
 /// <summary>
 /// 初始化页面
 /// </summary>
 /// <param name="CompanyNo"></param>
 private void InitPage(string CompanyNo)
 {
     string companyCD = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).CompanyCD;
     txtCompanyCD.Text=companyCD;
     if (string.IsNullOrEmpty(CompanyNo))
     {
         return;
     }
     //修改企业信息
     //获取企业信息
     CompanyBaseInfoModel CompanyBaseInfoModel = new CompanyBaseInfoModel();
     CompanyBaseInfoModel model=CompanyBaseInfoBus.GetCompanyUnitInfo(companyCD,CompanyNo);
     txtCompanyNo.Text=model .CompanyNo;
     txtCompanyName.Text=model .CompanyName;
     txtDescription.Text=model.Description;
 }
        /// <summary>
        /// 添加企业信息
        /// </summary>
        /// <returns>bool</returns>
        public static bool InsertCompanyBaseInfo(CompanyBaseInfoModel model)
        {
            try
            {
                StringBuilder sql = new StringBuilder();
                sql.AppendLine("INSERT INTO officedba.CompanyBaseInfo");
                sql.AppendLine("		(  CompanyCD   ");
                sql.AppendLine("		,CompanyNo         ");
                sql.AppendLine("		,SuperCompanyID         ");
                sql.AppendLine("		,CompanyName         ");
                sql.AppendLine("		,UsedStatus         ");
                sql.AppendLine("		,Description         ");
                sql.AppendLine("		,ModifiedUserID )        ");
                sql.AppendLine("VALUES                  ");
                sql.AppendLine("		(@CompanyCD     ");
                sql.AppendLine("		,@CompanyNo        ");
                sql.AppendLine("		,@SuperCompanyID        ");
                sql.AppendLine("		,@CompanyName        ");
                sql.AppendLine("		,@UsedStatus        ");
                sql.AppendLine("		,@Description        ");
                sql.AppendLine("     ,@ModifiedUserID)");
                //设置参数
                SqlParameter[] param = new SqlParameter[7];
                param[0] = SqlHelper.GetParameter("@CompanyCD", model.CompanyCD);
                param[1] = SqlHelper.GetParameter("@CompanyNo", model.CompanyNo);
                param[2] = SqlHelper.GetParameter("@SuperCompanyID", model.SuperCompanyID);
                param[3] = SqlHelper.GetParameter("@CompanyName", model.CompanyName);
                param[4] = SqlHelper.GetParameter("@UsedStatus", model.UsedStatus);
                param[5] = SqlHelper.GetParameter("@Description", model.Description);
                param[6] = SqlHelper.GetParameter("@ModifiedUserID", model.ModifiedUserID);
                SqlHelper.ExecuteTransSql(sql.ToString(), param);
                bool flag = SqlHelper.Result.OprateCount > 0 ? true : false;
                return flag;
            }
            //SQL拼写

            catch
            {
                return false;
            }


        }
 public static CompanyBaseInfoModel GetCompanyUntiInfo(string CompanyCD, string CompanyNo)
 {
     string sql = "select ID, CompanyCD,CompanyNo,SuperCompanyID,CompanyName,case when UsedStatus='1'then '是'else '否'end as UsedStatus ,Description ";
     sql += "from officedba.CompanyBaseInfo";
     sql += " where CompanyCD=@CompanyCD and CompanyNo=@CompanyNo";
     SqlParameter[] parms = new SqlParameter[2];
     parms[0] = SqlHelper.GetParameter("@CompanyCD", CompanyCD);
     parms[1] = SqlHelper.GetParameter("@CompanyNo", CompanyNo);
     DataTable dt = SqlHelper.ExecuteSql(sql, parms);
     if (dt != null && dt.Rows.Count > 0)
     {
         CompanyBaseInfoModel CompanyBaseInfoModel = new CompanyBaseInfoModel();
         CompanyBaseInfoModel.UsedStatus = dt.Rows[0]["UsedStatus"].ToString();
         CompanyBaseInfoModel.CompanyName = dt.Rows[0]["CompanyName"].ToString();
         CompanyBaseInfoModel.Description = dt.Rows[0]["Description"].ToString();
         CompanyBaseInfoModel.SuperCompanyID = Convert.ToInt32(dt.Rows[0]["SuperCompanyID"]);
         return CompanyBaseInfoModel;
     }
     return null;
 }
  protected void btnModify_Click(object sender, EventArgs e)
 {
     CompanyBaseInfoModel Model = new CompanyBaseInfoModel();
     Model.CompanyCD = companyCD;
     Model.CompanyNo = this.txtCompanyNo.Text.Trim();
     Model.CompanyName = this.txtCompanyName.Text.Trim();
     Model.Description = this.txtDescription.Text.Trim();
     Model.UsedStatus = chkUsingFlag.Checked ? "1" : "0";
     if (SuperCompany.Value=="0")
     {
         Model.SuperCompanyID =0;
     }
     else
     {
         Model.SuperCompanyID =Convert .ToInt32 ( SuperCompany.Value);
     }
     if (CompanyBaseInfoBus.InsertCompanyBaseInfo(Model))
     {
         Response.Write("添加成功");
     }
   
 }