Exemplo n.º 1
0
        public ActionResult UpdatePageAccess(List <PA_Users> PA_userpage)
        {
            foreach (PA_Users u in PA_userpage)
            {
                db.M_PA_UserDuplicateRemover();
                PA_Users userp = new PA_Users();
                userp = (from c in db.PA_Users where c.PageID == u.PageID && c.UserName == u.UserName select c).FirstOrDefault();
                if (userp != null)
                {
                    userp.PageAccess      = u.PageAccess;
                    db.Entry(userp).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    userp            = new PA_Users();
                    userp.UserName   = u.UserName;
                    userp.PageID     = u.PageID;
                    userp.PageAccess = u.PageAccess;
                    db.PA_Users.Add(userp);
                    db.SaveChanges();
                }
            }

            LoginController a = new LoginController();

            a.RefreshPageAccess(PA_userpage[0].UserName, user.Section);
            return(Json(new { msg = "Success" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult UpdatePageAccess(List <PA_Users> PA_userpage)
        {
            foreach (PA_Users u in PA_userpage)
            {
                PA_Users   userp  = new PA_Users();
                SqlCommand cmdSql = new SqlCommand();
                cmdSql.Connection     = conn;
                cmdSql.CommandTimeout = 0;
                cmdSql.CommandText    = "SELECT * FROM PA_Users WHERE EmployeeNo = '" + u.EmployeeNo + "' AND PageID = '" + u.PageID + "'";

                conn.Open();

                using (SqlDataReader rdr = cmdSql.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        userp.ID         = Convert.ToInt64(rdr["ID"]);
                        userp.PageID     = Convert.ToInt32(rdr["PageID"]);
                        userp.PageAccess = Convert.ToBoolean(rdr["PageAccess"]);
                        userp.EmployeeNo = rdr["EmployeeNo"].ToString();
                    }
                }
                if (userp.EmployeeNo != null)
                {
                    cmdSql.CommandText = "UPDATE PA_Users SET PageAccess = '" + u.PageAccess + "' WHERE EmployeeNo = '" + u.EmployeeNo + "' AND PageID = '" + u.PageID + "'";
                    cmdSql.ExecuteNonQuery();
                }
                else
                {
                    cmdSql.CommandText = "INSERT INTO [dbo].[PA_Users]" +
                                         "           ([PageID]" +
                                         "           ,[PageAccess]" +
                                         "           ,[EmployeeNo])" +
                                         "VALUES" +
                                         "     ('" + u.PageID + "'," +
                                         "     '" + u.PageAccess + "'," +
                                         "     '" + u.EmployeeNo + "')";
                    cmdSql.ExecuteNonQuery();
                }

                conn.Close();
            }

            LoginController a = new LoginController();

            a.RefreshPageAccess(PA_userpage[0].EmployeeNo);
            return(Json(new { msg = "Success" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public void PageAccessGiver(string UserName)
        {
            List <PA_Pages> pagelist = new List <PA_Pages>();

            pagelist = (from c in db.PA_Pages select c).ToList();

            foreach (PA_Pages page in pagelist)
            {
                PA_Users user = new PA_Users();
                user.PageID     = page.ID;
                user.PageAccess = true;
                user.UserName   = UserName;
                db.PA_Users.Add(user);
                db.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public ActionResult UploadPageAccess()
        {
            int theX = 0, theY = 0;

            try
            {
                var    postedFile = Request.Files[0] as HttpPostedFileBase;
                string filePath   = string.Empty;
                if (postedFile != null)
                {
                    string path = Server.MapPath("~/Uploads/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    filePath = path + Path.GetFileName(postedFile.FileName);
                    string extension = Path.GetExtension(postedFile.FileName);
                    postedFile.SaveAs(filePath);
                    string conString = string.Empty;
                    switch (extension.ToLower())
                    {
                    case ".xls":     //Excel 97-03.
                        conString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
                        break;

                    case ".xlsx":     //Excel 07 and above.
                        conString = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
                        break;
                    }
                    conString = string.Format(conString, filePath);

                    using (OleDbConnection connExcel = new OleDbConnection(conString))
                    {
                        using (OleDbCommand cmdExcel = new OleDbCommand())
                        {
                            using (OleDbDataAdapter odaExcel = new OleDbDataAdapter())
                            {
                                DataTable dt = new DataTable();
                                cmdExcel.Connection = connExcel;
                                string sheetName = "Modules";
                                try
                                {
                                    connExcel.Open();
                                }
                                catch (Exception err)
                                {
                                    Error_Logs error = new Error_Logs();
                                    error.PageModule = "Master - Users";
                                    error.ErrorLog   = err.Message;
                                    error.DateLog    = DateTime.Now;
                                    error.Username   = user.UserName;
                                    db.Error_Logs.Add(error);
                                    db.SaveChanges();
                                }

                                string qry = "SELECT EmployeeNo," +
                                             "Employee," +
                                             "TimeKeepingFormat," +
                                             "SectionApprover," +
                                             "CostCenter," +
                                             "LineTeam," +
                                             "Schedule," +
                                             "Users," +
                                             "ErrorLogs," +
                                             "OTForm," +
                                             "OTFormRequest," +
                                             "ChangeScheduleForm," +
                                             "ChangeScheduleRequest," +
                                             "DTRCorrection," +
                                             "DTRCorrectionRequest," +
                                             "ManPowerMonitoring," +
                                             "AttendanceSummary," +
                                             "RequestSummary";

                                cmdExcel.CommandText   = qry + " FROM [" + sheetName + "$]";//ung * is column name, ung sheetname ay settings
                                odaExcel.SelectCommand = cmdExcel;
                                odaExcel.Fill(dt);
                                connExcel.Close();
                                for (int x = 0; x < dt.Rows.Count; x++)
                                {
                                    theX = x;
                                    List <bool> result = new List <bool>();
                                    try
                                    {
                                        string EmployeeNo            = dt.Rows[x]["EmployeeNo"].ToString();
                                        bool   Employee              = (dt.Rows[x]["Employee"].ToString() == "1")?true:false; result.Add(Employee);
                                        bool   TimeKeepingFormat     = (dt.Rows[x]["TimeKeepingFormat"].ToString() == "1") ? true : false; result.Add(TimeKeepingFormat);
                                        bool   SectionApprover       = (dt.Rows[x]["SectionApprover"].ToString() == "1") ? true : false; result.Add(SectionApprover);
                                        bool   CostCenter            = (dt.Rows[x]["CostCenter"].ToString() == "1") ? true : false; result.Add(CostCenter);
                                        bool   LineTeam              = (dt.Rows[x]["LineTeam"].ToString() == "1") ? true : false; result.Add(LineTeam);
                                        bool   Schedule              = (dt.Rows[x]["Schedule"].ToString() == "1") ? true : false; result.Add(Schedule);
                                        bool   Users                 = (dt.Rows[x]["Users"].ToString() == "1") ? true : false; result.Add(Users);
                                        bool   ErrorLogs             = (dt.Rows[x]["ErrorLogs"].ToString() == "1") ? true : false; result.Add(ErrorLogs);
                                        bool   OTForm                = (dt.Rows[x]["OTForm"].ToString() == "1") ? true : false; result.Add(OTForm);
                                        bool   OTFormRequest         = (dt.Rows[x]["OTFormRequest"].ToString() == "1") ? true : false; result.Add(OTFormRequest);
                                        bool   ChangeScheduleForm    = (dt.Rows[x]["ChangeScheduleForm"].ToString() == "1") ? true : false; result.Add(ChangeScheduleForm);
                                        bool   ChangeScheduleRequest = (dt.Rows[x]["ChangeScheduleRequest"].ToString() == "1") ? true : false; result.Add(ChangeScheduleRequest);
                                        bool   DTRCorrection         = (dt.Rows[x]["DTRCorrection"].ToString() == "1") ? true : false; result.Add(DTRCorrection);
                                        bool   DTRCorrectionRequest  = (dt.Rows[x]["DTRCorrectionRequest"].ToString() == "1") ? true : false; result.Add(DTRCorrectionRequest);
                                        bool   OTSummary             = (dt.Rows[x]["RequestSummary"].ToString() == "1") ? true : false; result.Add(OTSummary);
                                        bool   ManPowerMonitoring    = (dt.Rows[x]["ManPowerMonitoring"].ToString() == "1") ? true : false; result.Add(ManPowerMonitoring);
                                        bool   AttendanceSummary     = (dt.Rows[x]["AttendanceSummary"].ToString() == "1") ? true : false; result.Add(AttendanceSummary);



                                        string[] Pages = { "Employee",
                                                           "FormatorTemplate",
                                                           "Section",
                                                           "CostCenter",
                                                           "Process",
                                                           "Schedule",
                                                           "Users",
                                                           "ErrorLogs",
                                                           "OT",
                                                           "Approval_OT",
                                                           "ChangeSchedule",
                                                           "ApproverChangeSchedule",
                                                           "DTR",
                                                           "ApproverDTR",
                                                           "OTSummary",
                                                           "MPMonitoring",
                                                           "WorkTimeSummary" };
                                        for (int y = 0; y < 17; y++)
                                        {
                                            theY = y;
                                            string   currentpage = Pages[y];
                                            long     pageid      = (from c in db.PA_Pages where c.PageIndex == currentpage select c.ID).FirstOrDefault();
                                            PA_Users employee    = (from c in db.PA_Users
                                                                    where c.UserName == EmployeeNo &&
                                                                    c.PageID == pageid
                                                                    select c).FirstOrDefault();

                                            if (employee == null)
                                            {
                                                employee            = new PA_Users();
                                                employee.PageAccess = result[y];
                                                employee.PageID     = pageid;
                                                employee.UserName   = EmployeeNo;

                                                db.PA_Users.Add(employee);
                                                db.SaveChanges();
                                            }
                                            else
                                            {
                                                employee.PageAccess      = result[y];
                                                db.Entry(employee).State = EntityState.Modified;
                                                db.SaveChanges();
                                            }
                                        }
                                    }
                                    catch (Exception err)
                                    {
                                        int        theXX = theX;
                                        int        theYY = theY;
                                        Error_Logs error = new Error_Logs();
                                        error.PageModule = "Master - Employee";
                                        error.ErrorLog   = err.Message;
                                        error.DateLog    = DateTime.Now;
                                        error.Username   = user.UserName;
                                        db.Error_Logs.Add(error);
                                        db.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Error_Logs error = new Error_Logs();
                error.PageModule = "Master - Employee";
                error.ErrorLog   = err.Message;
                error.DateLog    = DateTime.Now;
                error.Username   = user.UserName;
                db.Error_Logs.Add(error);
                db.SaveChanges();
                return(Json(new { result = "failed" }, JsonRequestBehavior.AllowGet));
            }
            LoginController a = new LoginController();

            a.RefreshPageAccess(user.UserName, user.Section);
            return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet));
        }