Exemplo n.º 1
0
        private void BackBut_Click(object sender, EventArgs e)
        {
            if (ChangeProve)
            {
                DialogResult ifb = MessageBox.Show(
                    "Сохранить изменения?",
                    "Сообщение",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Information
                    );
                if (ifb == DialogResult.Yes)
                {
                    dataGridView1.AllowUserToAddRows = false;
                    DataBase DB      = new DataBase();
                    string   command = String.Format("DELETE * FROM participants");
                    DB.SendCommand(command);
                    string[,] OneLine = new string[dataGridView1.Rows.Count, dataGridView1.Columns.Count];
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        for (int b = 1; b < dataGridView1.Columns.Count; b++)
                        {
                            OneLine[i, b] = dataGridView1.Rows[i].Cells[b].Value.ToString();
                            if (OneLine[i, b] == null || OneLine[i, b] == "")
                            {
                                OneLine[i, b] = "Не указано";
                            }
                        }
                        DB.SendCommand(String.Format(
                                           "INSERT INTO participants (fName, Surname, Gender, Birthday, Birthtown, Locations, Sportsclub, Weight)" +
                                           " VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')",
                                           OneLine[i, 1],
                                           OneLine[i, 2],
                                           OneLine[i, 3],
                                           OneLine[i, 4],
                                           OneLine[i, 5],
                                           OneLine[i, 6],
                                           OneLine[i, 7],
                                           OneLine[i, 8]
                                           ));
                    }
                    dataGridView1.AllowUserToAddRows = true;
                }
            }

            this.Hide();
            MenuForm menuForm = new MenuForm();

            menuForm.is_guest = this.is_guest;
            menuForm.Show();
        }
Exemplo n.º 2
0
        private void RegistrationBut_Click(object sender, EventArgs e)
        {
            String    login       = LoginInput.Text;
            String    password    = PasInput.Text;
            String    passwordRep = PasswordRepeatInput.Text;
            Boolean   visible     = false;
            HashClass hash        = new HashClass();

            if (password != passwordRep || password.Length == 0)
            {
                ErrorText2.Visible = true;
                visible            = true;
            }
            else
            {
                ErrorText2.Visible = false;
                visible            = false;
            }
            if (Checked())
            {
                return;
            }

            DataBase db = new DataBase();

            if (visible == false)
            {
                db.SendCommand(String.Format("INSERT INTO users (login, hash) VALUES ('{0}', '{1}')", LoginInput.Text, hash.HashPassword(password)));
                this.Hide();
                MenuForm menuForm = new MenuForm();
                menuForm.is_guest = false;
                menuForm.login    = login;
                menuForm.Show();
            }
        }
Exemplo n.º 3
0
        private void LoginBut_Click(object sender, EventArgs e)
        {
            String    login    = UserInput.Text;
            String    password = PasswordInput.Text;
            HashClass hash     = new HashClass();
            DataBase  db       = new DataBase();
            string    command  = String.Format("SELECT * FROM users WHERE login = '******';", login);

            object[] DBT = db.SendCommand(command);
            if (DBT[0] != null)
            {
                if (DBT[1].ToString() == login && hash.VerifyHashedPassword(DBT[2].ToString(), password))
                {
                    this.Hide();
                    MenuForm menuForm = new MenuForm();
                    menuForm.is_guest = false;
                    menuForm.login    = login;
                    menuForm.Show();
                }
                else
                {
                    ErrorText.Visible = true;
                }
            }
            else
            {
                ErrorText.Visible = true;
            }
        }
Exemplo n.º 4
0
        public Boolean Checked()
        {
            DataBase db = new DataBase();

            object[] DBT = db.SendCommand(String.Format("SELECT * FROM users WHERE login = '******';", LoginInput.Text));


            if (DBT[0] != null)
            {
                if (DBT[1].ToString() == LoginInput.Text)
                {
                    ErrorText3.Visible = true;
                    return(true);
                }
                else
                {
                    ErrorText3.Visible = false;
                    return(false);
                }
            }
            else
            {
                ErrorText3.Visible = false;
                return(false);
            }
        }
Exemplo n.º 5
0
        private void ChangeBut_Click(object sender, EventArgs e)
        {
            String    passOld  = PasOllBox.Text;
            String    passNew  = PasNewBox.Text;
            String    passNew2 = PasNewRepBox.Text;
            Boolean   visible  = false;
            HashClass hash     = new HashClass();
            DataBase  db       = new DataBase();

            if (passNew != passNew2 || passNew.Length == 0)
            {
                ErrorText.Visible = true;
                visible           = true;
            }
            else
            {
                ErrorText.Visible = false;
                visible           = false;
            }
            if (visible == false)
            {
                string   command = String.Format("SELECT * FROM users WHERE login = '******';", login);
                object[] DBT     = db.SendCommand(command);
                if (DBT[0] != null)
                {
                    if (DBT[1].ToString() == login && hash.VerifyHashedPassword(DBT[2].ToString(), passOld))
                    {
                        db.SendCommand(String.Format("UPDATE users SET hash='{0}' WHERE id = {1};", hash.HashPassword(passNew), DBT[0]));
                        this.Hide();
                    }
                    else
                    {
                        ErrorText.Visible = true;
                    }
                }
                else
                {
                    ErrorText.Visible = true;
                }
            }
            else
            {
                ErrorText.Visible = true;
            }
        }
Exemplo n.º 6
0
        private void EditBut_Click(object sender, EventArgs e)
        {
            DataBase DB = new DataBase();

            DB.SendCommand("DELETE * FROM participants");
        }
Exemplo n.º 7
0
        private void ImportBut_Click(object sender, EventArgs e)
        {
            OpenFileDialog OPF = new OpenFileDialog();
            DataBase       DB  = new DataBase();

            OPF.Filter = "Файлы txt|*.txt|Файлы csv|*.csv|Файлы xlsx|*.xlsx|Все файлы|*.*";
            if (OPF.ShowDialog() == DialogResult.OK)
            {
                string[] FileLines = File.ReadAllLines(OPF.FileName);
                string[] OneLine   = new string[8];
                switch (OPF.FileName.Split('.')[1])
                {
                case "txt":
                    for (int i = 0; i < FileLines.Length; i++)
                    {
                        if (FileLines[i] == "" || FileLines[i] == null)
                        {
                            continue;
                        }
                        FileLines[i] = FileLines[i].Replace("\'", "`");
                        string[] RowsF = FileLines[i].Split(new char[] { ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);
                        OneLine[0] = RowsF[0].Trim();
                        OneLine[1] = RowsF[1].Trim();
                        OneLine[2] = RowsF[2].Trim();
                        OneLine[3] = RowsF[3].Trim();
                        OneLine[4] = RowsF[4].Trim();
                        int LastI = RowsF[RowsF.Length - 1].LastIndexOf(' ');
                        OneLine[7] = RowsF[RowsF.Length - 1].Substring(LastI, RowsF[RowsF.Length - 1].Length - LastI).Trim();
                        if (RowsF.Length == 7)
                        {
                            OneLine[6] = RowsF[6].Substring(0, LastI).Trim();
                            OneLine[5] = RowsF[5].Trim();
                        }
                        else
                        {
                            OneLine[5] = RowsF[5].Substring(0, LastI).Trim();
                        }
                        for (int b = 0; b < OneLine.Length; b++)
                        {
                            if (OneLine[b] == null || OneLine[b] == "")
                            {
                                OneLine[b] = "Не указано";
                            }
                        }
                        // fName   Surname Gender  Birthday Birthtown   Locations Sportsclub  Weight
                        DB.SendCommand(String.Format(
                                           "INSERT INTO participants (fName, Surname, Gender, Birthday, Birthtown, Locations, Sportsclub, Weight)" +
                                           " VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')",
                                           OneLine[0],
                                           OneLine[1],
                                           OneLine[2],
                                           OneLine[3],
                                           OneLine[4],
                                           OneLine[5],
                                           OneLine[6],
                                           OneLine[7]
                                           ));
                    }
                    break;

                case "csv":
                    for (int i = 0; i < FileLines.Length; i++)
                    {
                        if (FileLines[i] == "" || FileLines[i] == null)
                        {
                            continue;
                        }
                        FileLines[i] = FileLines[i].Replace("\'", "`");
                        string[] RowsF = FileLines[i].Split(new char[] { ',', ';', ':' });
                        if (RowsF.Length == 9)
                        {
                            continue;
                        }
                        OneLine[0] = RowsF[2].Trim();
                        OneLine[1] = RowsF[1].Trim();
                        OneLine[2] = RowsF[3].Trim();
                        OneLine[3] = RowsF[4].Trim();
                        OneLine[4] = RowsF[5].Trim();
                        OneLine[5] = RowsF[6].Trim() + RowsF[7].Trim();
                        OneLine[6] = RowsF[8].Trim();
                        OneLine[7] = RowsF[9].Trim();
                        for (int b = 0; b < OneLine.Length; b++)
                        {
                            if (OneLine[b] == null || OneLine[b] == "")
                            {
                                OneLine[b] = "Не указано";
                            }
                        }
                        DB.SendCommand(String.Format(
                                           "INSERT INTO participants (fName, Surname, Gender, Birthday, Birthtown, Locations, Sportsclub, Weight)" +
                                           " VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')",
                                           OneLine[0],
                                           OneLine[1],
                                           OneLine[2],
                                           OneLine[3],
                                           OneLine[4],
                                           OneLine[5],
                                           OneLine[6],
                                           OneLine[7]
                                           ));
                    }
                    break;

                case "xlsx":
                    DB.Excel(OPF.FileName);
                    break;
                }
                EqualDGV();
            }
        }
Exemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            DataBase DB = new DataBase();
            DataSet  bd = DB.DGView("SELECT * FROM participants;");

            for (int i = 0; i < 4; i++)
            {
                string command = String.Format("DROP TABLE Group{0}", i + 1);
                DB.SendCommand(command);
            }
            object[,] BDTable = new object[bd.Tables[0].Rows.Count, bd.Tables[0].Columns.Count];
            foreach (DataTable dt in bd.Tables)
            {
                int i = 0;
                foreach (DataRow row in dt.Rows)
                {
                    int b     = 0;
                    var cells = row.ItemArray;
                    foreach (object cell in cells)
                    {
                        BDTable[i, b] = cell;
                        ++b;
                    }
                    ++i;
                }
            }
            object[,] GroupM   = sort(BDTable, "m");
            object[,] GroupF   = sort(BDTable, "f");
            object[][,] SLFSLM = new object[][, ] {
                sort(GroupF, "8", dateTimePicker1.Value.Date),
                sort(GroupF, "10", dateTimePicker1.Value.Date),
                sort(GroupM, "8", dateTimePicker1.Value.Date),
                sort(GroupM, "10", dateTimePicker1.Value.Date)
            };
            object[][][,] HL = new object[4][][, ];
            for (int i = 0; i < SLFSLM.Length; i++)
            {
                if (SLFSLM[i].GetLength(0) != 0)
                {
                    HL[i] = MinMax(SLFSLM[i]);
                }
            }
            for (int i = 0; i < HL.Length; i++)
            {
                if (HL[i] != null)
                {
                    int count = 0;
                    for (int b = 0; b < HL[i].Length; b++)
                    {
                        if (HL[i][b].GetLength(0) > 1)
                        {
                            ++count;
                        }
                    }
                    object[][,] temp = new object[count][, ];
                    count            = 0;
                    for (int b = 0; b < HL[i].Length; b++)
                    {
                        if (HL[i][b].GetLength(0) > 1)
                        {
                            temp[count] = HL[i][b];
                            ++count;
                        }
                    }
                    HL[i] = temp;
                }
            }
            for (int i = 0; i < HL.Length; i++)
            {
                string command = String.Format("CREATE TABLE Group{0} (idLg INT NOT NULL, idSg INT NOT NULL);", i + 1);
                //string command = String.Format("DROP TABLE Group{0}", i + 1);
                DB.SendCommand(command);
                if (HL[i] != null)
                {
                    for (int b = 0; b < HL[i].Length; b++)
                    {
                        for (int c = 0; c < HL[i][b].GetLength(0); c++)
                        {
                            command = String.Format("INSERT INTO Group{0} VALUES('{1}', '{2}');", i + 1, b, HL[i][b][c, 0]);
                            DB.SendCommand(command);
                        }
                    }
                }
            }
            this.Hide();
            TatamiForm tatamiForm = new TatamiForm();

            tatamiForm.Show();
        }