private DepartmentInfo GetInfoFromPageControl()
 {
     DepartmentInfo departInfo = null;
     switch (action)
     {
         case ActionType.Add:
             departInfo = new DepartmentInfo();
             departInfo.DepartmentID = CommonTools.Instance.GetMaxOrderNo(DepartmentInfoDBConst.TableName, DepartmentInfoDBConst.DepartmentID).ToString();
             break;
         case ActionType.Edit:
             departInfo = DepartmentInfoAdapter.Instance.LoadDepartmentInfo(departID);
             break;
     }
     departInfo.DepartmentCode = this.tbDepartmentCode.Text.Trim();
     departInfo.DepartmentName = this.tbDepartmentName.Text.Trim();
     if (this.ddlDepartment.SelectedIndex > 0)
     {
         departInfo.ParentID = this.ddlDepartment.SelectedValue;
         String nm = this.ddlDepartment.SelectedItem.Text.Replace(" ", "").Trim();
         departInfo.ParentName = nm.StartsWith("-") ? nm.Substring(1).Trim() : nm;
     }
     return departInfo;
 }
 public List<DepartmentInfo> GetDepartmentInfoList(WhereSqlClauseBuilder builder)
 {
     String sql = String.Format("SELECT * FROM {0} WHERE {1} ORDER BY DEPARTMENT_CODE", DepartmentInfoDBConst.TableName, builder.ToSqlString());
     DataTable dt = _DataHelper.GetDataTable(sql);
     List<DepartmentInfo> result = new List<DepartmentInfo>();
     for (Int32 i = 0; i < dt.Rows.Count; i++)
     {
         DepartmentInfo info = new DepartmentInfo();
         ORMapping.DataRowToObject(dt.Rows[i], info);
         result.Add(info);
     }
     return result;
 }
 public Int32 InsertDepartmentInfo(DepartmentInfo departmentInfo)
 {
     String sql = ORMapping.GetInsertSql(departmentInfo, BuilderEx.TSqlBuilderInstance);
     int result = _DataHelper.ExecuteSql(sql);
     return result;
 }
 public bool IsDeparmentNameUsed(DepartmentInfo departmentInfo, bool isAdd)
 {
     WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();
     builder.AppendItem(DepartmentInfoDBConst.DepartmentName, departmentInfo.DepartmentName);
     DepartmentInfo info = GetDepartmentInfoList(builder).FirstOrDefault();
     if (info == null)
     {
         return false;
     }
     else
     {
         if (isAdd)
         {
             return true;
         }
         else
         {
             return info.DepartmentID.Equals(departmentInfo.DepartmentID) ? false : true;
         }
     }
 }