Exemple #1
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Add(Dept model)
 {
     using (DBHelper db = DBHelper.Create())
     {
         db.Insert<Dept>(model);
     }
 }
Exemple #2
0
 public JsonResult AddDept(string PID, string DeptName)
 {
     string selectCode = "select max(code) from t_dept where PID = @PID";
     DeptRule rule = new DeptRule();
     string code = rule.GetDeptCode(selectCode, new string[] { "PID" }, new string[] { PID });
     string selectPCode = "select code from t_dept where ID = @ID";
     string PCode = rule.GetDeptCode(selectPCode, new string[] { "ID" }, new string[] { PID });
     if (string.IsNullOrEmpty(code))
         code = PCode + "0001";
     else
         code = code.Substring(0, code.Length - 4) + (Convert.ToInt32(code.Substring(code.Length - 4)) + 1).ToString().PadLeft(4, '0');
     string id = Guid.NewGuid().ToString().Replace("-", "");
     Dept dept = new Dept() { ID = id, PY = Pinyin.GetPinyin(DeptName), Status = 1, Code = code, PID = PID, Name = DeptName };
     rule.Add(dept);
     string sql = "select id,pid,name,code,status,case status when 0 then '在用' else '停用' end as statusName from t_dept where id=@ID";
     return Json(rule.GetDeptDynamic(sql, new string[] { "ID" }, new string[] { id }), JsonRequestBehavior.AllowGet);
 }
Exemple #3
0
 /// <summary>
 /// 获得数据列表
 /// </summary>
 public List<Dept> DataTableToList(DataTable dt)
 {
     List<Dept> modelList = new List<Dept>();
     int rowsCount = dt.Rows.Count;
     if (rowsCount > 0)
     {
         Dept model;
         for (int n = 0; n < rowsCount; n++)
         {
             model = new Dept();
             if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
             {
                 model.ID = dt.Rows[n]["ID"].ToString();
             }
             if (dt.Rows[n]["PID"] != null && dt.Rows[n]["PID"].ToString() != "")
             {
                 model.PID = dt.Rows[n]["PID"].ToString();
             }
             if (dt.Rows[n]["Code"] != null && dt.Rows[n]["Code"].ToString() != "")
             {
                 model.Code = dt.Rows[n]["Code"].ToString();
             }
             if (dt.Rows[n]["Name"] != null && dt.Rows[n]["Name"].ToString() != "")
             {
                 model.Name = dt.Rows[n]["Name"].ToString();
             }
             if (dt.Rows[n]["PY"] != null && dt.Rows[n]["PY"].ToString() != "")
             {
                 model.PY = dt.Rows[n]["PY"].ToString();
             }
             if (dt.Rows[n]["Status"] != null && dt.Rows[n]["Status"].ToString() != "")
             {
                 model.Status = Convert.ToInt32(dt.Rows[n]["Status"].ToString());
             }
             modelList.Add(model);
         }
     }
     return modelList;
 }
Exemple #4
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Dept model)
 {
     using (DBHelper db = DBHelper.Create())
     {
         db.Update<Dept>(model);
         return true;
     }
 }
Exemple #5
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Add(Dept model)
 {
     dal.Add(model);
 }
Exemple #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Dept model)
 {
     return dal.Update(model);
 }
Exemple #7
0
 public JsonResult Modify(Dept dept)
 {
     DeptRule rule = new DeptRule();
     try
     {
         if (rule.Update(dept.ID, dept.Name))
         {
             return GetDept(dept.ID);
         }
         else
         {
             throw new Exception();
         }
     }
     catch
     {
         return null;
     }
 }
Exemple #8
0
 public JsonResult GetDeptList(Dept dept)
 {
     StringBuilder temp = new StringBuilder("select id,pid,name,code,status,case status when 0 then '在用' else '停用' end as statusName from t_dept where 1=1 ");
     if (dept != null)
     {
         if (!string.IsNullOrEmpty(dept.Code))
         {
             temp.Append(" and code like '" + dept.Code + "%'");
         }
         if (!string.IsNullOrEmpty(dept.ID))
         {
             temp.Append(" and ID = '" + dept.ID + "'");
         }
         if (string.IsNullOrEmpty(dept.PID))
         {
             temp.Append(" and PID is null");
         }
         else
         {
             temp.Append(" and pid = '" + dept.PID + "'");
         }
         if (!string.IsNullOrEmpty(dept.Name))
         {
             temp.Append(" and Name like '%" + dept.Name + "%'");
         }
         if (!string.IsNullOrEmpty(dept.PY))
         {
             temp.Append(" and NamePY like '%" + dept.PY + "%'");
         }
         temp.Append(" and status = " + dept.Status);
     }
     List<object> lists = new List<object>();
     lists = new DeptRule().GetDeptDynamicList(temp.ToString(), null, null);
     return Json(lists, JsonRequestBehavior.AllowGet);
 }