Exemplo n.º 1
0
        protected bool UserLogin(string userName, string password)
        {
            _user.es.Connection.Name = "KENCANA";
            //_user.es.Connection.Name = "LOCAL_HIS";
            if (_user.LoadByPrimaryKey(userName))
            {
                if (_user.Password.Equals(Crypto.Encrypt(password)))
                {
                    ADefHelpDeskUsersQuery q = new ADefHelpDeskUsersQuery();
                    q.SelectAll().Where(q.Username == userName);
                    ADefHelpDeskUsersCollection c = new ADefHelpDeskUsersCollection();
                    c.Load(q);
                    ADefHelpDeskUsers a = new ADefHelpDeskUsers();
                    if (c.Count == 0)
                    {
                        a.Username    = userName;
                        a.Password    = _user.Password;
                        a.FirstName   = _user.UserName;
                        a.LastName    = ".";
                        a.IsSuperUser = false;
                        a.Email       = userName + "@rscmkencana.com";
                        a.Save();

                        ADefHelpDeskUsersQuery      aa = new ADefHelpDeskUsersQuery();
                        ADefHelpDeskUsersCollection ac = new ADefHelpDeskUsersCollection();
                        aa.SelectAll().Where(aa.Username == userName);
                        ac.Load(aa);

                        foreach (ADefHelpDeskUsers U in ac)
                        {
                            ADefHelpDeskUsers _u = new ADefHelpDeskUsers();
                            _u.UserID            = (int)U.UserID;
                            _u.Username          = userName;
                            _u.FirstName         = _user.UserName;
                            AppSession.UserLogin = _u;
                        }
                    }
                    if (c.Count == 1)
                    {
                        foreach (ADefHelpDeskUsers U in c)
                        {
                            if (a.LoadByPrimaryKey((int)U.UserID))
                            {
                                ADefHelpDeskUsers _u = new ADefHelpDeskUsers();
                                _u.UserID            = (int)U.UserID;
                                _u.Username          = userName;
                                _u.FirstName         = _user.UserName;
                                AppSession.UserLogin = _u;

                                a.Username    = userName;
                                a.Password    = _user.Password;
                                a.FirstName   = _user.UserName;
                                a.LastName    = ".";
                                a.IsSuperUser = false;
                                a.Email       = userName + "@rscmkencana.com";
                                a.Save();
                            }
                        }
                    }
                    //Get user service unit
                    ADefHelpDeskUserUserGroupQuery      ugQ = new ADefHelpDeskUserUserGroupQuery("a");
                    ADefHelpDeskUserUserGroupCollection ugC = new ADefHelpDeskUserUserGroupCollection();
                    ugQ.SelectAll().Where(ugQ.UserID == userName).es.Top = 1;
                    ugC.Load(ugQ);
                    if (ugC.Count == 1)
                    {
                        foreach (ADefHelpDeskUserUserGroup ug in ugC)
                        {
                            Session["ServiceUnitID"] = ug.UserServiceUnitID;
                            AppSession.ServiceUnit   = ug;
                        }
                    }
                    else
                    {
                        X.Msg.Notify("Error", "This user has not been registered to any service unit").Show();
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public void grdServiceUnit_Select()
        {
            string            ServiceUnitID = string.Empty;
            RowSelectionModel rmSU          = this.grdServiceUnit.GetSelectionModel() as RowSelectionModel;

            if (rmSU.SelectedRows.Count > 0)
            {
                ServiceUnitID            = rmSU.SelectedRow.RecordID;
                Session["ServiceUnitID"] = ServiceUnitID;
            }

            MessageBus.Default.Publish("grdServiceUnit_Select", ServiceUnitID);

            //Select all user that still unassigned
            ADefHelpDeskUserUserGroupQuery  userGroupC   = new ADefHelpDeskUserUserGroupQuery("ug");
            ADefHelpDeskUserRolesCollection userGroupCol = new ADefHelpDeskUserRolesCollection();

            userGroupC.Select(userGroupC.UserID);
            //userGroupC.Where(userGroupC.UserServiceUnitID == Session["ServiceUnitID"].ToString().Trim());

            ADefHelpDeskUsersQuery      userQ = new ADefHelpDeskUsersQuery("u");
            ADefHelpDeskUsersCollection userC = new ADefHelpDeskUsersCollection();

            userQ.Select(userQ.Username.As("UserID"), userQ.FirstName.As("UserName")).Where(userQ.Username.NotIn(userGroupC)).OrderBy(userQ.FirstName.Ascending);
            DataTable dtU = new DataTable();

            dtU = userQ.LoadDataTable();

            string UserID = string.Empty;

            foreach (DataRow dr in dtU.Rows)
            {
                UserID = dr["UserID"].ToString();
                ADefHelpDeskUserUserGroupQuery      uQ = new ADefHelpDeskUserUserGroupQuery("a");
                ADefHelpDeskUserUserGroupCollection uC = new ADefHelpDeskUserUserGroupCollection();
                uQ.SelectAll().Where(uQ.UserID == UserID);
                uC.Load(uQ);
                if (uC.Count > 0)
                {
                    dr.Delete();
                }
            }
            dtU.AcceptChanges();
            storeUser.DataSource = dtU;
            storeUser.DataBind();

            //Select all user that belong to selected service unit
            ADefHelpDeskUsersQuery         user      = new ADefHelpDeskUsersQuery("uu");
            ADefHelpDeskUserUserGroupQuery usergroup = new ADefHelpDeskUserUserGroupQuery("uugg");

            usergroup.Select(usergroup.UserID, usergroup.UserServiceUnitID, user.FirstName.As("UserName"))
            .Where(usergroup.UserServiceUnitID == ServiceUnitID)
            .InnerJoin(user).On(usergroup.UserID == user.Username);
            //ADefHelpDeskUserUserGroupCollection userSelectedSU = new ADefHelpDeskUserUserGroupCollection();
            //userSelectedSU.Query.SelectAll().Where(userSelectedSU.Query.UserServiceUnitID == ServiceUnitID);
            //DataTable dtUSU = userSelectedSU.Query.LoadDataTable();
            DataTable dtUSU = usergroup.LoadDataTable();

            //foreach (DataRow dr in dtUSU.Rows)
            //{

            //}
            storeUserOfServiceUnit.DataSource = dtUSU;
            storeUserOfServiceUnit.DataBind();
        }