Пример #1
0
        protected void GVUsers_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowIndex == editRowIndex)
                {
                    CroscoStopCardEntities stopCardEntities = new CroscoStopCardEntities();

                    var result = stopCardEntities.Users.Select(x => new { x.UserID, x.UserRole, x.OJ }).Where(x => x.UserID == EditUserID);

                    DropDownList oj = e.Row.FindControl("ddlOJ") as DropDownList;
                    if (oj != null)
                    {
                        oj.SelectedValue = result.Select(x => x.OJ).FirstOrDefault();
                        if (((string)Session["UserRole"] == "Admin") || ((string)Session["UserRole"] == "LocalAdmin") || ((string)Session["UserRole"] == "Manager"))
                        {
                            oj.Enabled = false;
                        }
                    }

                    DropDownList role = e.Row.FindControl("ddlUserRole") as DropDownList;
                    if (role != null)
                    {
                        role.SelectedValue = result.Select(x => x.UserRole).FirstOrDefault();
                        if (((string)Session["UserRole"] == "Admin") || ((string)Session["UserRole"] == "LocalAdmin") || ((string)Session["UserRole"] == "Manager"))
                        {
                            role.Enabled = false;
                        }
                    }
                }
            }
        }
Пример #2
0
        protected void btnUpdatePass_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(tbxNewPass.Text) && !string.IsNullOrWhiteSpace(tbxConfirmNewPass.Text))
            {
                Regex regPass = new Regex(@"^.*(?=.{8,50})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!.@#$%^&+=]).*$");

                if (tbxNewPass.Text.ToLower().Contains("user") || tbxNewPass.Text == "User.123")
                {
                    lblNewPassError.Text = "Password shouldn't contain 'user'. Please change your Password!!!";
                }
                else if (!regPass.IsMatch(tbxNewPass.Text))
                {
                    lblNewPassError.Text = "Password must satisfy this conditions: minimum 8 characters long A-Z, 1 uppercase, 1 lowercase character, 1 number and 1 special character (!.@#$%^&+=)";
                }
                else if (tbxNewPass.Text != tbxConfirmNewPass.Text)
                {
                    lblNewPassError.Text = "Your password and password confirmation do not match!";
                }
                else
                {
                    using (var SCDB = new CroscoStopCardEntities())
                    {
                        string username = (string)Session["UserName"];
                        var    result   = SCDB.Users.SingleOrDefault(b => b.UserName == username);

                        if (result != null)
                        {
                            Session["UserName"]    = null;
                            Session["NewPassword"] = null;

                            result.Lozinka = PasswordHash.CreateHash(tbxNewPass.Text);
                            SCDB.SaveChanges();

                            if (result.UserRole == "Admin" || result.UserRole == "LocalAdmin" || result.UserRole == "Manager" || result.UserRole == "MasterAdmin")
                            {
                                Session["UserRole"] = result.UserRole;
                            }
                            else
                            {
                                Session["user"] = result.UserName;
                            }

                            Session["userID"] = result.UserID;
                            Response.Redirect("StopQueryPage.aspx");
                        }
                    }
                }
            }
            else
            {
                lblNewPassError.Text = "Password and password confirmation are required!";
            }
        }
Пример #3
0
        protected void GVUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            CroscoStopCardEntities stopCardEntities = new CroscoStopCardEntities();

            var result = stopCardEntities.Users.Select(x => new { x.UserID, x.Lozinka }).Where(x => x.UserID == EditUserID);

            TextBox tbxPassEdit = GVUsers.Rows[e.RowIndex].FindControl("tbxPassEdit") as TextBox;

            if (tbxPassEdit.Text != result.Select(x => x.Lozinka).FirstOrDefault())
            {
                e.NewValues.Remove("Lozinka");
                e.NewValues.Add("Lozinka", PasswordHash.CreateHash(tbxPassEdit.Text));
            }
            e.NewValues.Add("UserRole", ((DropDownList)GVUsers.Rows[e.RowIndex].FindControl("ddlUserRole")).SelectedValue);
            e.NewValues.Add("OJ", ((DropDownList)GVUsers.Rows[e.RowIndex].FindControl("ddlOJ")).SelectedValue);
        }
Пример #4
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            CroscoStopCardEntities stopCardEntities = new CroscoStopCardEntities();

            var loginResult = stopCardEntities.Users.Select(x => new { x.UserID, x.UserName, x.Lozinka, x.UserRole, x.OJ, x.SubOJ, x.SubOJDva, x.FirstName, x.LastName }).Where(x => x.UserName == tbxUsername.Value.Trim());

            if (loginResult.Count() > 0)
            {
                if (loginResult.Select(x => x.UserRole).FirstOrDefault() == "MasterAdmin")
                {
                    if (PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                    {
                        Session["UserRole"]  = loginResult.Select(x => x.UserRole).FirstOrDefault();
                        Session["userID"]    = loginResult.Select(x => x.UserID).FirstOrDefault();
                        Session["UserName"]  = loginResult.Select(x => x.UserName).FirstOrDefault();
                        Session["OJ"]        = loginResult.Select(x => x.OJ).FirstOrDefault();
                        Session["SubOJ"]     = loginResult.Select(x => x.SubOJ).FirstOrDefault();
                        Session["SubOJDva"]  = loginResult.Select(x => x.SubOJDva).FirstOrDefault();
                        Session["FirstName"] = loginResult.Select(x => x.FirstName).FirstOrDefault();
                        Session["LastName"]  = loginResult.Select(x => x.LastName).FirstOrDefault();
                        Response.Redirect("AdminPage.aspx");
                    }
                    else
                    {
                        lblError.Visible = true;
                    }
                }
                else if (loginResult.Select(x => x.UserRole).FirstOrDefault() == "Admin")
                {
                    if (tbxPassword.Value == "User.123" && PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                    {
                        Session["UserName"]    = loginResult.Select(x => x.UserName).FirstOrDefault();
                        Session["NewPassword"] = true;
                    }
                    else if (PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                    {
                        Session["UserRole"] = loginResult.Select(x => x.UserRole).FirstOrDefault();
                        //Session["OJ"] = loginResult.Select(x => x.OJ).FirstOrDefault();
                        Session["userID"]    = loginResult.Select(x => x.UserID).FirstOrDefault();
                        Session["UserName"]  = loginResult.Select(x => x.UserName).FirstOrDefault();
                        Session["OJ"]        = loginResult.Select(x => x.OJ).FirstOrDefault();
                        Session["SubOJ"]     = loginResult.Select(x => x.SubOJ).FirstOrDefault();
                        Session["SubOJDva"]  = loginResult.Select(x => x.SubOJDva).FirstOrDefault();
                        Session["FirstName"] = loginResult.Select(x => x.FirstName).FirstOrDefault();
                        Session["LastName"]  = loginResult.Select(x => x.LastName).FirstOrDefault();
                        Response.Redirect("AdminPage.aspx");
                    }
                    else
                    {
                        lblError.Visible = true;
                    }
                }
                else if (loginResult.Select(x => x.UserRole).FirstOrDefault() == "LocalAdmin")
                {
                    if (tbxPassword.Value == "User.123" && PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                    {
                        Session["UserName"]    = loginResult.Select(x => x.UserName).FirstOrDefault();
                        Session["NewPassword"] = true;
                    }
                    else if (PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                    {
                        Session["UserRole"] = loginResult.Select(x => x.UserRole).FirstOrDefault();
                        //Session["OJ"] = loginResult.Select(x => x.OJ).FirstOrDefault();
                        Session["userID"]    = loginResult.Select(x => x.UserID).FirstOrDefault();
                        Session["UserName"]  = loginResult.Select(x => x.UserName).FirstOrDefault();
                        Session["OJ"]        = loginResult.Select(x => x.OJ).FirstOrDefault();
                        Session["SubOJ"]     = loginResult.Select(x => x.SubOJ).FirstOrDefault();
                        Session["SubOJDva"]  = loginResult.Select(x => x.SubOJDva).FirstOrDefault();
                        Session["FirstName"] = loginResult.Select(x => x.FirstName).FirstOrDefault();
                        Session["LastName"]  = loginResult.Select(x => x.LastName).FirstOrDefault();
                        Response.Redirect("AdminPage.aspx");
                    }
                    else
                    {
                        lblError.Visible = true;
                    }
                }
                else if (loginResult.Select(x => x.UserRole).FirstOrDefault() == "Manager")
                {
                    if (tbxPassword.Value == "User.123" && PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                    {
                        Session["UserName"]    = loginResult.Select(x => x.UserName).FirstOrDefault();
                        Session["NewPassword"] = true;
                    }
                    else if (PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                    {
                        Session["UserRole"] = loginResult.Select(x => x.UserRole).FirstOrDefault();
                        //Session["OJ"] = loginResult.Select(x => x.OJ).FirstOrDefault();
                        Session["userID"]    = loginResult.Select(x => x.UserID).FirstOrDefault();
                        Session["UserName"]  = loginResult.Select(x => x.UserName).FirstOrDefault();
                        Session["OJ"]        = loginResult.Select(x => x.OJ).FirstOrDefault();
                        Session["SubOJ"]     = loginResult.Select(x => x.SubOJ).FirstOrDefault();
                        Session["SubOJDva"]  = loginResult.Select(x => x.SubOJDva).FirstOrDefault();
                        Session["FirstName"] = loginResult.Select(x => x.FirstName).FirstOrDefault();
                        Session["LastName"]  = loginResult.Select(x => x.LastName).FirstOrDefault();
                        Response.Redirect("AdminPage.aspx");
                    }
                    else
                    {
                        lblError.Visible = true;
                    }
                }
                else if (tbxPassword.Value == "User.123" && PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                {
                    Session["UserName"]    = loginResult.Select(x => x.UserName).FirstOrDefault();
                    Session["NewPassword"] = true;
                }
                else if (PasswordHash.ValidatePassword(tbxPassword.Value, loginResult.Select(x => x.Lozinka).FirstOrDefault()))
                {
                    Session["user"]        = loginResult.Select(x => x.UserName).FirstOrDefault();
                    Session["userID"]      = loginResult.Select(x => x.UserID).FirstOrDefault();
                    Session["OJ"]          = loginResult.Select(x => x.OJ).FirstOrDefault();
                    Session["SubOJ"]       = loginResult.Select(x => x.SubOJ).FirstOrDefault();
                    Session["SubOJDva"]    = loginResult.Select(x => x.SubOJDva).FirstOrDefault();
                    Session["FirstName"]   = loginResult.Select(x => x.FirstName).FirstOrDefault();
                    Session["LastName"]    = loginResult.Select(x => x.LastName).FirstOrDefault();
                    Session["NewPassword"] = null;
                    Response.Redirect("StopQueryPage.aspx");
                }
                else
                {
                    lblError.Visible = true;
                }
            }
            else
            {
                lblError.Visible = true;
            }
        }
Пример #5
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            StopCard stopCard = new StopCard();

            if (rbSig.Checked)
            {
                if (string.IsNullOrWhiteSpace(tbxRadnje.Text) || string.IsNullOrWhiteSpace(tbxOpis.Text))
                {
                    lblError.Text    = "Opis sukladnosti/nesukladnosti i Korektivne radnje su obavezna polja";
                    lblError.Visible = true;
                }
                else
                {
                    using (CroscoStopCardEntities SCDB = new CroscoStopCardEntities())
                    {
                        DateTime dateCreated = DateTime.Parse(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
                        stopCard.UserID           = (int)Session["userID"];
                        stopCard.DateCreated      = dateCreated;
                        stopCard.SigNesigPostupak = true;
                        stopCard.DatumOtvaranja   = clnOpen.SelectedDate;
                        stopCard.OpisSukNesuk     = tbxOpis.Text;
                        if (!string.IsNullOrWhiteSpace(tbxAnaliza.Text))
                        {
                            stopCard.AnalizaUzorka = tbxAnaliza.Text;
                        }
                        stopCard.KorektivneRadnje = tbxRadnje.Text;
                        stopCard.RokZaRjes        = clnDeadline.SelectedDate;
                        if (!string.IsNullOrWhiteSpace(tbxOsoba.Text))
                        {
                            stopCard.OdgovornaOsoba = tbxOsoba.Text;
                        }
                        stopCard.CardStatus = CardStatus(ddlStatus);
                        if (!string.IsNullOrWhiteSpace(tbxComment.Text))
                        {
                            stopCard.Komentar = tbxComment.Text;
                        }
                        if (clnClose.Enabled)
                        {
                            stopCard.DatumZatvaranja = clnClose.SelectedDate;
                        }

                        SCDB.StopCards.Add(stopCard);
                        SCDB.SaveChanges();
                    }
                }
            }
            else
            {
                if (!IsValidSubmit(GetCBXDict))
                {
                    lblError.Text    = "Please select at least one 'Sub-element of observation'";
                    lblError.Visible = true;
                }
                else if (string.IsNullOrWhiteSpace(tbxRadnje.Text) || string.IsNullOrWhiteSpace(tbxOpis.Text))
                {
                    lblError.Text    = "Opis sukladnosti/nesukladnosti i Korektivne radnje su obavezna polja";
                    lblError.Visible = true;
                }
                else
                {
                    using (CroscoStopCardEntities SCDB = new CroscoStopCardEntities())
                    {
                        stopCard.UserID            = (int)Session["userID"];
                        stopCard.DateCreated       = DateTime.Parse(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());
                        stopCard.SigNesigPostupak  = false;
                        stopCard.NesigRadnjaUvijet = ddlNesigurnaRadUvt.SelectedValue;
                        stopCard.ElementProm       = GetAllChecked(GetCBXDict)[0];

                        string podelementProm = string.Empty;
                        for (int i = 1; i < GetAllChecked(GetCBXDict).Count; i++)
                        {
                            if (i == GetAllChecked(GetCBXDict).Count - 1)
                            {
                                podelementProm += GetAllChecked(GetCBXDict).ElementAt(i);
                            }
                            else
                            {
                                podelementProm += GetAllChecked(GetCBXDict).ElementAt(i) + "_";
                            }
                        }

                        stopCard.PodelementProm = podelementProm;
                        stopCard.DatumOtvaranja = clnOpen.SelectedDate;
                        stopCard.OpisSukNesuk   = tbxOpis.Text;
                        if (!string.IsNullOrWhiteSpace(tbxAnaliza.Text))
                        {
                            stopCard.AnalizaUzorka = tbxAnaliza.Text;
                        }
                        stopCard.KorektivneRadnje = tbxRadnje.Text;
                        stopCard.RokZaRjes        = clnDeadline.SelectedDate;
                        if (!string.IsNullOrWhiteSpace(tbxOsoba.Text))
                        {
                            stopCard.OdgovornaOsoba = tbxOsoba.Text;
                        }
                        stopCard.CardStatus = CardStatus(ddlStatus);
                        if (!string.IsNullOrWhiteSpace(tbxComment.Text))
                        {
                            stopCard.Komentar = tbxComment.Text;
                        }
                        if (clnClose.Enabled)
                        {
                            stopCard.DatumZatvaranja = clnClose.SelectedDate;
                        }

                        SCDB.StopCards.Add(stopCard);
                        SCDB.SaveChanges();
                    }
                }
            }
        }
Пример #6
0
        protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            TextBox tbxLN         = DetailsView1.FindControl("tbxLN") as TextBox;
            TextBox tbxMB         = DetailsView1.FindControl("tbxMB") as TextBox;
            TextBox tbxPassInsert = DetailsView1.FindControl("tbxPassInsert") as TextBox;
            int     checkMB       = 0;

            Regex regPass  = new Regex(@"^.*(?=.{8,50})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!.@#$%^&+=]).*$");
            Regex regEmail = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");

            string Username = tbxLN.Text.ToLower() + "." + tbxMB.Text;

            using (var SCDB = new CroscoStopCardEntities())
            {
                var listUsers = SCDB.Users.Select(x => x.UserName.ToLower()).ToArray();

                if (listUsers.Contains(Username))
                {
                    GetErrorText     = "This Username: (" + Username + ") already exist!";
                    lblError.Text    = GetErrorText;
                    lblError.Visible = true;
                    e.Cancel         = true;
                }
            }

            if (string.IsNullOrWhiteSpace(((TextBox)DetailsView1.FindControl("tbxFN")).Text))
            {
                error.AppendLine("First Name is Required");
                valid = false;
            }
            if (string.IsNullOrWhiteSpace(tbxLN.Text))
            {
                error.AppendLine("Last Name is Required");
                valid = false;
            }
            if (string.IsNullOrWhiteSpace(tbxPassInsert.Text))
            {
                error.AppendLine("Password is Required");
                valid = false;
            }
            if (string.IsNullOrWhiteSpace(tbxMB.Text))
            {
                error.AppendLine("Matični Broj is Required");
                valid = false;
            }

            if (!int.TryParse(tbxMB.Text, out checkMB))
            {
                error.AppendLine("Matični Broj must be a number!");
                valid = false;
            }
            else
            {
                using (var SCDB = new CroscoStopCardEntities())
                {
                    var listMB = SCDB.Users.Select(x => x.MaticniBroj).ToArray();

                    if (listMB.Contains(checkMB))
                    {
                        GetErrorText     = "There are already user with this Matični Broj: (" + checkMB + ")!";
                        lblError.Text    = GetErrorText;
                        lblError.Visible = true;
                        e.Cancel         = true;
                    }
                }
            }

            if (!regPass.IsMatch(tbxPassInsert.Text))
            {
                error.AppendLine("Password must satisfy this conditions: minimum 8 characters long A-Z, 1 uppercase, 1 lowercase character, 1 number and 1 special character (!.@#$%^&+=)");
                valid = false;
            }

            TextBox tbxEmail = DetailsView1.FindControl("tbxMail") as TextBox;

            if (!string.IsNullOrEmpty(tbxEmail.Text))
            {
                if (!regEmail.IsMatch(tbxEmail.Text))
                {
                    error.AppendLine("Entered Email address is not valid!");
                    valid = false;
                }
            }

            if (!valid)
            {
                GetErrorText     = error.ToString();
                lblError.Text    = GetErrorText;
                lblError.Visible = true;
                e.Cancel         = true;
            }

            e.Values.Remove("Lozinka");
            e.Values.Remove("UserName");
            e.Values.Add("Lozinka", PasswordHash.CreateHash(tbxPassInsert.Text));
            e.Values.Add("UserName", Username);
            e.Values.Add("UserRole", ((DropDownList)DetailsView1.FindControl("ddlUserRole")).SelectedValue);
            e.Values.Add("OJ", ((DropDownList)DetailsView1.FindControl("ddlOJ")).SelectedValue);
        }
Пример #7
0
        private DataTable GenerateTableUsers(string role)
        {
            using (var SCDB = new CroscoStopCardEntities())
            {
                DataTable dt = new DataTable();
                for (int i = 0; i < 10; i++)
                {
                    DataColumn column = null;
                    switch (i)
                    {
                    case 0:
                        column = new DataColumn("FirstName");
                        break;

                    case 1:
                        column = new DataColumn("LastName");
                        break;

                    case 2:
                        column = new DataColumn("UserName");
                        break;

                    case 3:
                        column = new DataColumn("Lozinka");
                        break;

                    case 4:
                        column = new DataColumn("MaticniBroj");
                        break;

                    case 5:
                        column = new DataColumn("OJ");
                        break;

                    case 6:
                        column = new DataColumn("SubOJ");
                        break;

                    case 7:
                        column = new DataColumn("SubOJDva");
                        break;

                    case 8:
                        column = new DataColumn("Email");
                        break;

                    case 9:
                        column = new DataColumn("UserRole");
                        break;

                    default:
                        break;
                    }
                    dt.Columns.Add(column);
                }

                (from rec in SCDB.Users.AsEnumerable()
                 select new
                {
                    firstName = rec.FirstName,
                    lastName = rec.LastName,
                    userName = rec.UserName,
                    password = rec.Lozinka,
                    maticniBr = rec.MaticniBroj,
                    oj = rec.OJ,
                    subOJ = rec.SubOJ,
                    subOJDva = rec.SubOJDva,
                    email = rec.Email,
                    userRole = rec.UserRole
                }).Aggregate(dt, (user, r) =>
                {
                    dt.Rows.Add(r.firstName, r.lastName, r.userName, r.password, r.maticniBr, r.oj, r.subOJ, r.subOJDva, r.email, r.userRole);
                    return(user);
                });
                return(dt);
            }
        }
Пример #8
0
        protected void btnImportUsers_Click(object sender, EventArgs e)
        {
            if (fuExcel.FileName != string.Empty)
            {
                if (fuExcel.FileName.ToLower().EndsWith(".xls") || fuExcel.FileName.ToLower().EndsWith(".xlsx"))
                {
                    fuExcel.SaveAs(Server.MapPath("~/TempFiles/") + fuExcel.FileName);

                    string filePath = Server.MapPath("~/TempFiles/") + fuExcel.FileName;

                    IWorkbook workbook;
                    if (fuExcel.FileName.ToLower().EndsWith(".xls"))
                    {
                        using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                            workbook = new HSSFWorkbook(stream);
                    }
                    else
                    {
                        using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                            workbook = new XSSFWorkbook(stream);
                    }

                    ISheet    sheet = workbook.GetSheetAt(0);
                    DataTable dt    = new DataTable(sheet.SheetName);

                    IRow headerRow = sheet.GetRow(0);
                    foreach (ICell headerCell in headerRow)
                    {
                        dt.Columns.Add(headerCell.ToString());
                    }

                    int rowIndex = 0;
                    foreach (IRow row in sheet)
                    {
                        if (rowIndex++ == 0)
                        {
                            continue;
                        }
                        DataRow dataRow = dt.NewRow();
                        dataRow.ItemArray = row.Cells.Select(c => c.ToString()).ToArray();
                        dt.Rows.Add(dataRow);
                    }

                    using (var SCDB = new CroscoStopCardEntities())
                    {
                        //int lastID = SCDB.Users.OrderByDescending(u => u.UserID).FirstOrDefault().UserID;
                        var listUsers = SCDB.Users.Select(x => x.UserName).ToArray();

                        for (int i = 0; i < dt.Rows.Count - 1; i++)
                        {
                            DataRow dr = dt.Rows[i];

                            if (listUsers.Contains(dr["UserName"].ToString()))
                            {
                                continue;
                            }

                            try
                            {
                                if ((string)Session["UserRole"] == "Admin")
                                {
                                    SCDB.Users.Add(new User()
                                    {
                                        FirstName   = dr["FirstName"].ToString(),
                                        LastName    = dr["LastName"].ToString(),
                                        UserName    = dr["UserName"].ToString(),
                                        Lozinka     = PasswordHash.CreateHash(dr["Lozinka"].ToString()),
                                        MaticniBroj = Convert.ToInt32(dr["MaticniBroj"]),
                                        OJ          = (string)Session["OJ"],
                                        SubOJ       = dr["SubOJ"].ToString(),
                                        SubOJDva    = dr["SubOJDva"].ToString(),
                                        Email       = dr["Email"].ToString(),
                                        UserRole    = "User"
                                    });
                                }
                                else
                                {
                                    SCDB.Users.Add(new User()
                                    {
                                        //UserID = ++lastID,
                                        FirstName   = dr["FirstName"].ToString(),
                                        LastName    = dr["LastName"].ToString(),
                                        UserName    = dr["UserName"].ToString(),
                                        Lozinka     = PasswordHash.CreateHash(dr["Lozinka"].ToString()),
                                        MaticniBroj = Convert.ToInt32(dr["MaticniBroj"]),
                                        OJ          = dr["OJ"].ToString(),
                                        SubOJ       = dr["SubOJ"].ToString(),
                                        SubOJDva    = dr["SubOJDva"].ToString(),
                                        Email       = dr["Email"].ToString(),
                                        UserRole    = dr["UserRole"].ToString()
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                GetErrorText     = ex.Message;
                                lblError.Text    = GetErrorText;
                                lblError.Visible = true;
                            }
                        }
                        try
                        {
                            SCDB.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            GetErrorText     = ex.Message;
                            lblError.Text    = GetErrorText;
                            lblError.Visible = true;
                        }
                    }
                    File.Delete(filePath);

                    Response.Redirect("AdminPage.aspx");
                }
                else
                {
                    GetErrorText     = "Please choose an .xls or .xlsx file!";
                    lblError.Text    = GetErrorText;
                    lblError.Visible = true;
                }
            }
            else
            {
                GetErrorText     = "Please upload .xls or .xlsx file first!";
                lblError.Text    = GetErrorText;
                lblError.Visible = true;
            }
        }