public static BG_Department AddBG_Department(BG_Department bG_Department)
        {
            string sql =
                "INSERT BG_Department (DepLev, FaDepID, DepCode, DepName, DepQua, DepSta, DepRem)" +
                "VALUES (@DepLev, @FaDepID, @DepCode, @DepName, @DepQua, @DepSta, @DepRem)";

            sql += " ; SELECT @@IDENTITY";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@DepLev", bG_Department.DepLev),
                    new SqlParameter("@FaDepID", bG_Department.FaDepID),
                    new SqlParameter("@DepCode", bG_Department.DepCode),
                    new SqlParameter("@DepName", bG_Department.DepName),
                    new SqlParameter("@DepQua", bG_Department.DepQua),
                    new SqlParameter("@DepSta", bG_Department.DepSta),
                    new SqlParameter("@DepRem", bG_Department.DepRem)
                };

                string IdStr = DBUnity.ExecuteScalar(CommandType.Text, sql, para);
                int newId = Convert.ToInt32(IdStr);
                return GetBG_DepartmentByDepID(newId);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
        public static BG_Department GetBG_DepartmentByFaDepID(int depID)
        {
            string sql = "SELECT * FROM BG_Department WHERE FaDepID = @FaDepID";

            try
            {
                SqlParameter para = new SqlParameter("@DepID", depID);
                DataTable dt = DBUnity.AdapterToTab(sql, para);

                if (dt.Rows.Count > 0)
                {
                    BG_Department bG_Department = new BG_Department();

                    bG_Department.DepID = dt.Rows[0]["DepID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["DepID"];
                    bG_Department.DepLev = dt.Rows[0]["DepLev"] == DBNull.Value ? 0 : (int)dt.Rows[0]["DepLev"];
                    bG_Department.FaDepID = dt.Rows[0]["FaDepID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["FaDepID"];
                    bG_Department.DepCode = dt.Rows[0]["DepCode"] == DBNull.Value ? "" : (string)dt.Rows[0]["DepCode"];
                    bG_Department.DepName = dt.Rows[0]["DepName"] == DBNull.Value ? "" : (string)dt.Rows[0]["DepName"];
                    bG_Department.DepQua = dt.Rows[0]["DepQua"] == DBNull.Value ? "" : (string)dt.Rows[0]["DepQua"];
                    bG_Department.DepSta = dt.Rows[0]["DepSta"] == DBNull.Value ? "" : (string)dt.Rows[0]["DepSta"];
                    bG_Department.DepRem = dt.Rows[0]["DepRem"] == DBNull.Value ? "" : (string)dt.Rows[0]["DepRem"];

                    return bG_Department;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 /// <summary>
 /// 添加一条部门记录
 /// </summary>
 /// <param name="dep">一个部门实例</param>
 /// <returns>bool</returns>
 public static bool AddDep(BG_Department dep)
 {
     bool falg = false;
     string sqlStr = @"insert into BG_Department(DepLev,DepCode,DepName,DepQua,DepSta,DepRem,FaDepID) values
         (@DepLev,@DepCode,@DepName,@DepQua,@DepSta,@DepRem, @FaDepID)";
     try
     {
         SqlParameter[] pars = new SqlParameter[]{
                   new SqlParameter("@DepLev",dep.DepLev),
                   new SqlParameter("@DepCode",dep.DepCode),
                   new SqlParameter("@DepName",dep.DepName),
                   new SqlParameter("@DepQua",dep.DepQua),
                   new SqlParameter("@DepSta",dep.DepSta),
                   new SqlParameter("@DepRem",dep.DepRem),
                   new SqlParameter("@FaDepID",dep.FaDepID)
                           };
         falg = DBUnity.ExecuteNonQuery(CommandType.Text, sqlStr, pars) > 0;
     }
     catch (Exception ex)
     {
         falg = false;
         Log.WriteLog(ex.Message, "BGDepartmentService--AddDep");
     }
     return falg;
 }
 protected void btnWinAdd_DirectClick(object sender, DirectEventArgs e)
 {
     if (AdName.Text != null)
     {
         if (BG_DepartmentLogic.GetBG_DepartmentByName(AdName.Text.Trim())!=null)
         {
             X.Msg.Alert("提示", "部门名称重复,请重新填写.").Show();
             return;
         }
         BG_Department dp = new BG_Department();
         dp.DepName = AdName.Text.ToString();
         dp.DepRem = AdDes.Text.ToString();
         dp.FaDepID = AreaDepID;
         dp.DepLev = 4;
         BG_DepartmentManager.AddBG_Department(dp);
         DtDataBind();
         resetform.Reset();
     }
     else
     {
         X.Msg.Alert("提示", "部门为必填项").Show();
     }
 }
 /// <summary>
 /// 添加一条部门记录
 /// </summary>
 /// <param name="dep">一个部门实例</param>
 /// <returns>bool</returns>
 public static bool AddDep(BG_Department dep)
 {
     return BGDepartmentService.AddDep(dep);
 }
 /// <summary>
 /// 修改一条部门记录
 /// </summary>
 /// <param name="dep">部门ID</param>
 /// <returns>bool</returns>
 public static bool UpdDpe(BG_Department dep)
 {
     return BGDepartmentService.UpdDpe(dep);
 }
 /// <summary>
 /// 更改部门状态(正常/禁用)
 /// </summary>
 /// <param name="depid">DepID</param>
 /// <returns>bool</returns>
 public static bool UpdDepSta(BG_Department depid)
 {
     return BG_DepartmentService.ModifyBG_Department(depid);
 }
 public static bool ModifyBG_Department(BG_Department bG_Department)
 {
     return BG_DepartmentService.ModifyBG_Department(bG_Department);
 }
 public static bool DeleteBG_Department(BG_Department bG_Department)
 {
     return BG_DepartmentService.DeleteBG_Department(bG_Department);
 }
 public static BG_Department AddBG_Department(BG_Department bG_Department)
 {
     return BG_DepartmentService.AddBG_Department(bG_Department);
 }
 public static bool DeleteBG_Department(BG_Department bG_Department)
 {
     return DeleteBG_DepartmentByDepID( bG_Department.DepID );
 }
        public static bool ModifyBG_Department(BG_Department bG_Department)
        {
            string sql =
                "UPDATE BG_Department " +
                "SET " +
                    "DepLev = @DepLev, " +
                    "FaDepID = @FaDepID, " +
                    "DepCode = @DepCode, " +
                    "DepName = @DepName, " +
                    "DepQua = @DepQua, " +
                    "DepSta = @DepSta, " +
                    "DepRem = @DepRem " +
                "WHERE DepID = @DepID";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@DepID", bG_Department.DepID),
                    new SqlParameter("@DepLev", bG_Department.DepLev),
                    new SqlParameter("@FaDepID", bG_Department.FaDepID),
                    new SqlParameter("@DepCode", bG_Department.DepCode),
                    new SqlParameter("@DepName", bG_Department.DepName),
                    new SqlParameter("@DepQua", bG_Department.DepQua),
                    new SqlParameter("@DepSta", bG_Department.DepSta),
                    new SqlParameter("@DepRem", bG_Department.DepRem)
                };

                int t = DBUnity.ExecuteNonQuery(CommandType.Text, sql, para);
                if(t>0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 /// <summary>
 /// 修改一条部门记录
 /// </summary>
 /// <param name="dep">部门ID</param>
 /// <returns>bool</returns>
 public static bool UpdDpe(BG_Department dep)
 {
     bool falg = false;
     try
     {
         string sqlStr = @"update BG_Department set DepLev=@DepLev,FaDepID=@FaDepID,DepCode=@DepCode,
     DepName=@DepName,DepQua=@DepQua,DepSta=@DepSta,DepRem=@DepRem where DepID=@DepID";
         SqlParameter[] pars = new SqlParameter[]{
                         new SqlParameter("@DepID",dep.DepID),
                         new SqlParameter("@DepLev",dep.DepLev),
                         new SqlParameter("@FaDepID",dep.FaDepID),
                         new SqlParameter("@DepCode",dep.DepCode),
                         new SqlParameter("@DepName",dep.DepName),
                         new SqlParameter("@DepQua",dep.DepQua),
                         new SqlParameter("@DepSta",dep.DepSta),
                         new SqlParameter("@DepRem",dep.DepRem)
                         };
         falg = DBUnity.ExecuteNonQuery(CommandType.Text, sqlStr, pars) > 0;
     }
     catch (Exception ex)
     {
         falg = false;
         Log.WriteLog(ex.Message, "BGDepartmentService--UpdDpe");
     }
     return falg;
 }
 /// <summary>
 /// 更改部门状态(正常/禁用)
 /// </summary>
 /// <param name="depid">DepID</param>
 /// <returns>bool</returns>
 public static bool UpdDepSta(BG_Department depid)
 {
     bool falg = false;
     try
     {
         string sqlStr = "update BG_Department set DepSta=@DepSta where DepID=@DepID";
         SqlParameter[] pars = new SqlParameter[]{
                         new SqlParameter("@DepID",depid.DepID),
                         new SqlParameter("@DepSta",depid.DepSta)
                         };
         falg = DBUnity.ExecuteNonQuery(CommandType.Text, sqlStr, pars) > 0;
     }
     catch (Exception ex)
     {
         falg = false;
         Log.WriteLog(ex.Message, "BGDepartmentService--UpdDepSta");
     }
     return falg;
 }
 /// <summary>
 /// 根据部门ID查询一条记录
 /// </summary>
 /// <param name="depid">部门ID</param>
 /// <returns>BGDepartment</returns>
 public static BG_Department GetDepBydepid(string depid)
 {
     BG_Department dep = new BG_Department();
     try
     {
         string sqlStr = "select * from BG_Department where DepID='{0}'";
         sqlStr = string.Format(sqlStr, depid);
         DataTable dt = DBUnity.AdapterToTab(sqlStr);
         if (dt.Rows.Count > 0)
         {
             dep.DepID = (int)dt.Rows[0]["DepID"];
             dep.DepLev = (int)dt.Rows[0]["DepLev"];
             dep.FaDepID = (int)dt.Rows[0]["FaDepID"];
             dep.DepCode = dt.Rows[0]["DepCode"].ToString();
             dep.DepName = dt.Rows[0]["DepName"].ToString();
             dep.DepQua = dt.Rows[0]["DepQua"].ToString();
             dep.DepSta = dt.Rows[0]["DepSta"].ToString();
             dep.DepRem = dt.Rows[0]["DepRem"].ToString();
         }
     }
     catch (Exception ex)
     {
         dep = new BG_Department();
         Log.WriteLog(ex.Message, "BGDepartmentService--GetDepBydepid");
     }
     return dep;
 }