Ejemplo n.º 1
0
        public IndexModel(ILogger <IndexModel> logger, IHostEnvironment environment)
        {
            Connected    = true;
            _logger      = logger;
            _environment = environment;
            IsUploaded   = false;

            if (!System.IO.File.Exists("config.txt"))
            {
                _logger.LogError("Brak pliku konfiguracyjnego.");
                return;
            }
            else
            {
                _logger.LogInformation($"Korzystanie z pliku konfiguracyjengo.");
            }
            foreach (string item in System.IO.File.ReadAllLines(@"config.txt"))
            {
                if (!item.Contains("="))
                {
                    continue;
                }
                string[] line = item.Split("=");
                config.Add(line[0], line[1]);
            }
            try
            {
                string conn_str = "server=" + config.GetValueOrDefault("server") + ";port=" + config.GetValueOrDefault("port") + ";database=" + config.GetValueOrDefault("database") + ";uid=" + config.GetValueOrDefault("login") + ";pwd=" + config.GetValueOrDefault("password");
                conn = new MySqlConnection(conn_str);
                string conn_str_in = "server=" + config.GetValueOrDefault("server") + ";port=" + config.GetValueOrDefault("port") + ";database=" + config.GetValueOrDefault("database_err") + ";uid=" + config.GetValueOrDefault("login") + ";pwd=" + config.GetValueOrDefault("password");
                conn_in = new MySqlConnection(conn_str_in);
                //conn = new MySqlConnection("server=localhost;port=3306;database=plan;uid=root;pwd=pass5431");
                //conn_in = new MySqlConnection("server=localhost;port=3306;database=err_tmp;uid=root;pwd=pass5431");
                conn.Open();
                conn_in.Open();
                //foreach (string item in GetSQLElements("przedmioty")) if (item != "") Modules.Add(item);
                foreach (string item in GetSQLElements("grupy"))
                {
                    if (item != "")
                    {
                        Groups.Add(item);
                    }
                }
                foreach (string item in GetSQLElements("prowadzacy"))
                {
                    if (item != "")
                    {
                        Lecturer.Add(item);
                    }
                }
                //foreach (string item in GetSQLElements("sale")) if (item != "") Rooms.Add(item);
                conn.Close();
            }
            catch (MySqlException e)
            {
                Console.WriteLine();
                Console.WriteLine(e);
                Console.WriteLine();
                Connected = false;
                Redirect("Index");
            }
        }
Ejemplo n.º 2
0
        protected void dgLecturer_ItemCommand(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Lecturer lecturer = new Lecturer();

            if (e.CommandName == "AddLecturer")
            {
                TextBox txtTempLecturerID = (TextBox)e.Item.Cells[0].FindControl("txtLecturerIDNew");
                TextBox txtTempName       = (TextBox)e.Item.Cells[1].FindControl("txtNameNew");
                TextBox txtTempPhoneNo    = (TextBox)e.Item.Cells[2].FindControl("txtPhoneNew");
                Regex   lecregex          = new Regex(@"^\d{1,5}$");                      //only support up to 5 integer
                Match   checklec          = lecregex.Match(txtTempLecturerID.Text);
                Regex   nameRegex         = new Regex(@"[a-zA-Z ]{1,30}$");               //Only allow a-z,A-Z and space
                Match   checkname         = nameRegex.Match(txtTempName.Text);

                //Validation for name (No digit allowed and only up to 30 characters)
                Regex phoneRegex = new Regex(@"^(01)[0-9]*[0-9]{8,9}$");
                Match checkPhone = phoneRegex.Match(txtTempPhoneNo.Text);

                if (txtTempName.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the lecturer name!', 'error')</script>'");
                }
                else if (!checklec.Success)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'The Lecturer ID is not allowed. Please Lecturer ID is only up to 5 digit number.', 'error')</script>'");
                }
                else if (!checkname.Success)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'The Lecturer Name is not allowed. Lecturer name is only support character, space and up to 30 character only.', 'error')</script>'");
                }
                else if (txtTempLecturerID.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the lecturer ID!', 'error')</script>'");
                }
                else if (!checkPhone.Success)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'The phone number is not allowed. Phone number must start with 01 and is only support 7 or 8 digits', 'error')</script>'");
                }
                else
                {
                    if (lecturer.Add(txtTempLecturerID.Text, txtTempName.Text, txtTempPhoneNo.Text) == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Cannot have same duplicate lecturer ID!', 'error')</script>'");
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Added!', text: 'This " + txtTempName.Text + " (" + txtTempLecturerID.Text + ") lecturer is added successfully, Your password is (holdDoc1)', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'manageLecturer.aspx'; }});</script>'");
                    }
                }
            }

            else if (e.CommandName == "DeleteLecturer")
            {
                Label rowLecturerID = (Label)e.Item.Cells[0].FindControl("lblLecturerID");

                if (lecturer.DeleteLecturer(rowLecturerID.Text) == false)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Delete this lecturer record unsuccessfully', 'error')</script>'");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Deleted!', text: 'Deleted this lecturer record successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'manageLecturer.aspx'; }});</script>'");
                }
            }
            else if (e.CommandName == "ResetPassword")
            {
                Label rowLecturerID = (Label)e.Item.Cells[0].FindControl("lblLecturerID");

                if (lecturer.ResetPassword(rowLecturerID.Text) == false)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Reset Password unsuccessfully', 'error')</script>'");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Reset!', text: 'Reset Password successfully! Your password is (holdDoc1)', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'manageLecturer.aspx'; }});</script>'");
                }
            }
        }