Example #1
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!";
            }
        }
Example #2
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();
                    }
                }
            }
        }
Example #3
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;
            }
        }