Esempio n. 1
0
        public ActionResult EmpGroupForm()
        {
            ViewData["LoginUserInfo"] = LoginUserInfo;

            string ProgramID = "G002";

            if (!GeneralObj.CheckProgID(LoginUserInfo.ProgramList, ProgramID))
            {
                return(View("../SysMsg/NoAccess"));
            }
            else
            {
                ViewData["SysProgram"] = GeneralObj.GetProgram(LoginUserInfo.ProgramList, ProgramID);
            }


            UserFreeStyleModel UserFreeStyle;

            UserFreeStyle = JsonConvert.DeserializeObject <UserFreeStyleModel>(Session[UserFreeStyle_id].ToString());



            EmpGroupModel EmpGroup = ModelFactory.GetEmpGroup(UserFreeStyle.SignId);

            ViewData["EmpGroup"] = EmpGroup;

            return(View());
        }
Esempio n. 2
0
        public JsonResult EmpGroupSave(string EmpGroupJson)
        {
            EmpGroupModel EmpGroup = null;

            try
            {
                EmpGroup = JsonConvert.DeserializeObject <EmpGroupModel>(EmpGroupJson);



                if (ModelFactory.EmpGroupSave(EmpGroup))
                {
                    return(Json("1"));//代表已經處裡完
                }
                else
                {
                    return(Json(""));//失敗
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
            catch
            {
                return(Json("系統發生錯誤"));
            }
        }
        public bool EmpGroupSave(EmpGroupModel EmpGroup)
        {
            DbTransaction objTrans = DbAccess.CreateDbTransaction();


            try
            {
                DbAccess.ExecuteNonQuery("DELETE FROM tbEmpGroup Where EmployeeNo = @EmployeeNo ", objTrans,
                                         new DbParameter[] {
                    DataAccess.CreateParameter("EmployeeNo", DbType.String, EmpGroup.Emp.EmployeeNo.ToString())
                }
                                         );



                for (int i = 0; i < EmpGroup.GroupList.Count(); i++)
                {
                    DbAccess.ExecuteNonQuery("INSERT INTO tbEmpGroup (EmployeeNo,GroupID) VALUES (@EmployeeNo,@GroupID) ", objTrans,
                                             new DbParameter[] {
                        DataAccess.CreateParameter("EmployeeNo", DbType.String, EmpGroup.Emp.EmployeeNo.ToString()),
                        DataAccess.CreateParameter("GroupID", DbType.String, EmpGroup.GroupList[i].GroupID.ToString())
                    });
                }


                objTrans.Commit();

                return(true);
            }
            catch
            {
                objTrans.Rollback();
                return(false);
            }
            finally
            {
                if (objTrans != null)
                {
                    objTrans.Dispose();
                }
            }
        }
        public EmpGroupModel GetEmpGroup(string EmpNo)
        {
            DataTable dt = DbAccess.ExecuteDataTable("SELECT * FROM gvEmployeeAll Where EmployeeNo = @EmployeeNo ",
                                                     new DbParameter[] {
                DataAccess.CreateParameter("EmployeeNo", DbType.String, EmpNo.ToString())
            }
                                                     );

            EmpModel Emp = null;

            Emp                = new EmpModel();
            Emp.EmployeeNo     = dt.Rows[0]["EmployeeNo"].ToString();
            Emp.EmployeeName   = dt.Rows[0]["EmployeeName"].ToString();
            Emp.DepartMentName = dt.Rows[0]["DepartMentName"].ToString();
            Emp.DepartMentNo   = dt.Rows[0]["DepartMentNo"].ToString();
            Emp.Company        = dt.Rows[0]["Company"].ToString();
            Emp.CompanyName    = dt.Rows[0]["CompanyName"].ToString();

            Emp.EmployeeEName = dt.Rows[0]["EmployeeEName"].ToString();
            //########################



            EmpGroupModel EmpGroup = new EmpGroupModel();

            EmpGroup.Emp = Emp;



            string sql = "";



            sql = "SELECT GroupID,GroupName,ViewLevel,Power,0 as Flag FROM tbGroup WHERE GroupID Not IN (SELECT GroupID FROM tbEmpGroup WHERE EmployeeNo=@EmployeeNo) "
                  + " UNION SELECT GP.GroupID,GP.GroupName,GP.ViewLevel,GP.Power,1 as Flag FROM tbEmpGroup EG LEFT OUTER JOIN tbGroup GP ON GP.GroupID=EG.GroupID WHERE EmployeeNo=@EmployeeNo ";



            dt = DbAccess.ExecuteDataTable(sql,
                                           new DbParameter[] {
                DataAccess.CreateParameter("EmployeeNo", DbType.String, EmpNo)
            });


            List <ItemModel> ViewLevelList = GeneralModelFactory.GetGroupViewLevelList();

            ProgramModelFactory Factory     = new ProgramModelFactory();
            List <ProgramModel> ProgramList = Factory.GetGroupProgramList();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string tmp = (from tmpViewLevel in ViewLevelList
                              where tmpViewLevel.ItemID == dt.Rows[i]["ViewLevel"].ToString()
                              select tmpViewLevel.ItemName).First();


                int tmpPower = int.Parse(dt.Rows[i]["Power"].ToString());

                List <ProgramModel> tmpProgramList = (from tmpProgram in ProgramList
                                                      where (tmpPower & tmpProgram.Power) == tmpProgram.Power
                                                      select tmpProgram).ToList();


                if (dt.Rows[i]["Flag"].ToString() == "1")
                {
                    EmpGroup.GroupList.Add(new GroupModel()
                    {
                        GroupID          = dt.Rows[i]["GroupID"].ToString(),
                        GroupName        = dt.Rows[i]["GroupName"].ToString(),
                        ViewLevel        = tmp,
                        GroupProgramList = tmpProgramList
                    });
                }
                else
                {
                    EmpGroup.NoGroupList.Add(new GroupModel()
                    {
                        GroupID          = dt.Rows[i]["GroupID"].ToString(),
                        GroupName        = dt.Rows[i]["GroupName"].ToString(),
                        ViewLevel        = tmp,
                        GroupProgramList = tmpProgramList
                    });
                }
            }



            return(EmpGroup);
        }