Example #1
0
        private void yt_Button9_Click(object sender, EventArgs e)
        {
            string query_id = "";
            int    max_id   = 0;

            if (textBox1.Text != String.Empty)
            {
                if (textBox1.Text != String.Empty)
                {
                    try
                    {
                        conn.Close();
                        conn.Open();
                        //выбираем последний номер сохраненной записи о пересылке из бд и сохраняем
                        string query = "SELECT max(number) as MaxN " +
                                       "from documents;";
                        using (var reader = new MySqlCommand(query, conn).ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                if (!reader.IsDBNull(reader.GetOrdinal("MaxN")))
                                {
                                    MaxNumber = int.Parse(reader["MaxN"].ToString()) + 1;
                                }
                            }
                        }
                        //выбираем последний номер файла из бд и сохраняем
                        query = "SELECT max(id) as MaxD" +
                                " from document_file;";
                        using (var reader = new MySqlCommand(query, conn).ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                if (!reader.IsDBNull(reader.GetOrdinal("MaxD")))
                                {
                                    MaxIdF = int.Parse(reader["MaxD"].ToString()) + 1;
                                }
                            }
                        }
                        //загружаем файлы на сервер и в бд
                        for (int i = 0; i < listBox1.Items.Count; i++)
                        {
                            //try
                            // {
                            string s = listBox3.Items[i].ToString();
                            string f = "\\\\" + IP_SERVER + "\\Программа\\" +
                                       DEPARTMENT + "\\" + LAST_NAME + " " +
                                       FIRST_NAME + " " + MIDDLE_NAME + "\\" +
                                       DateTime.Today.ToString("d");
                            if (!Directory.Exists(f))
                            {
                                Directory.CreateDirectory(f);
                            }
                            f = f + "\\" + Path.GetFileName(s);
                            File.Copy(s, f, true);
                            string q = "INSERT INTO `document_file`" +
                                       "    (`id` ,`path`, `file`)" +
                                       "    VALUES (" + MaxIdF + ",'" + f.Replace("\\", "\\\\") + "','" + Path.GetFileName(s) + "');";
                            MySqlCommand command = new MySqlCommand(q, conn);
                            // выполняем запрос
                            command.ExecuteNonQuery();
                            IdFile.Add(MaxIdF);//записываем все номера в массив (( номера файлов))
                            MaxIdF += 1;
                            //MessageBox.Show( "ок");

                            /* }
                             * catch(Exception ex)
                             * {
                             *   MessageBox.Show(ex.Message,"ошибка");
                             * }*/
                        }
                        try
                        {
                            //выбираем все id получателей
                            if (IdlistBox.Items.Count != 0)
                            {
                                for (int i = 0; i < IdlistBox.Items.Count; i++)
                                {
                                    string words = IdlistBox.Items[i].ToString();
                                    query = "SELECT id,E_MAIL From users where id = " +
                                            words + ";";
                                    using (var reader = new MySqlCommand(query, conn).ExecuteReader())
                                    {
                                        if (reader.Read())
                                        {
                                            Id_s.Add(reader["id"].ToString());
                                            e_mail.Add(reader["E_MAIL"].ToString());
                                        }
                                    }
                                    //IdRecipient[i] = id_send;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Ошибка пользователя, Документ не добавлен!");
                        }
                        try
                        {
                            if (DepcomboBox.Items.Count != 0)
                            {
                                for (int i = 0; i < NameDeplistBox.Items.Count; i++)
                                {
                                    string words  = listBox4.Items[i].ToString();
                                    string query1 = "select id,E_MAIL from users " +
                                                    "where Dep_id=" +
                                                    words + ";";
                                    using (var reader = new MySqlCommand(query1, conn).ExecuteReader())
                                    {
                                        while (reader.Read())
                                        {
                                            Id_s.Add(reader["id"].ToString());
                                            e_mail.Add(reader["E_MAIL"].ToString());
                                            //MessageBox.Show(reader["E_Mail"].ToString(), "мыло");
                                        }
                                    }
                                }
                            }
                        }

                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Ошибка при добавлении департаментов, Документ не добавлен!");
                        }
                        try
                        {
                            for (int i = 0; i < Id_s.Count; i++)
                            {
                                if (checkBox1.Checked) //если стоит флажок на сроке подписания
                                {
                                    string q = "INSERT INTO `documents`" +
                                               "    ( `number`,`namedoc`, " +
                                               "`id_sender`, `id_recipient`,`date`,`from_date`,`comments`," +
                                               "`document_type`,`origin`,`sign`,`incom_number`)" +
                                               "    VALUES" +
                                               "           (" + MaxNumber + ",'" + textBox1.Text + "'," +
                                               ID + "," +
                                               Id_s[i] + ",'" +
                                               dateTimePicker1.Value.ToString("s") + ",'" +
                                               richTextBox1.Text + "','" +
                                               typeComboBox1.Text + "','Оригинал','" + comboBox1.Text +
                                               "','" + MaxNumber + "');";

                                    MySqlCommand command = new MySqlCommand(q, conn);
                                    // выполняем запрос
                                    command.ExecuteNonQuery();
                                    query_id = "SELECT max(id_document) as MaxIID" +
                                               " from documents;";
                                    using (var reader = new MySqlCommand(query_id, conn).ExecuteReader())
                                    {
                                        if (reader.Read())
                                        {
                                            if (!reader.IsDBNull(reader.GetOrdinal("MaxIID")))
                                            {
                                                max_id = int.Parse(reader["MaxIID"].ToString());
                                            }
                                        }
                                    }
                                    string query1 = "INSERT INTO `coments`" +
                                                    "    (`Id_doc` ,`number`,`Statuscol`, `usercol`)" +
                                                    "    VALUES (" + max_id + "," + MaxNumber
                                                    + ",'документ добавлен'," + ID + ");";
                                    MySqlCommand command1            = new MySqlCommand(query1, conn);
                                    int          UspeshnoeIzmenenie1 = command1.ExecuteNonQuery();
                                    try
                                    {
                                        SendMail.SEND_MAIlTORECIP(e_mail[i], textBox1.Text);
                                    }
                                    catch { }
                                }
                                else
                                {
                                    //MessageBox.Show(id_send.ToString(), "id");
                                    string q = "INSERT INTO `documents`" +
                                               "    ( `number`,`namedoc`, " +
                                               "`id_sender`, `id_recipient`,`comments`," +
                                               "`document_type`,`origin`,`sign`,`incom_number`)" +
                                               "    VALUES" +
                                               "           (" + MaxNumber + ",'" +
                                               textBox1.Text + "'," +
                                               ID + "," + Id_s[i] + ",'" + richTextBox1.Text +
                                               "','" + typeComboBox1.Text +
                                               "','Оригинал','" + comboBox1.Text +
                                               "','" + MaxNumber + "');";
                                    MySqlCommand command = new MySqlCommand(q, conn);
                                    // выполняем запрос
                                    command.ExecuteNonQuery();
                                    query_id = "SELECT max(id_document) as MaxIID" +
                                               " from documents;";
                                    using (var reader = new MySqlCommand(query_id, conn).ExecuteReader())
                                    {
                                        if (reader.Read())
                                        {
                                            if (!reader.IsDBNull(reader.GetOrdinal("MaxIID")))
                                            {
                                                max_id = int.Parse(reader["MaxIID"].ToString());
                                            }
                                        }
                                    }
                                    string query1 = "INSERT INTO `coments`" +
                                                    "    (`Id_doc` ,`number`,`Statuscol`, `usercol`)" +
                                                    "    VALUES (" + max_id + "," + MaxNumber
                                                    + ",'документ добавлен'," + ID + ");";
                                    MySqlCommand command1            = new MySqlCommand(query1, conn);
                                    int          UspeshnoeIzmenenie1 = command1.ExecuteNonQuery();
                                    try
                                    {
                                        SendMail.SEND_MAIlTORECIP(e_mail[i], textBox1.Text);
                                    }
                                    catch { }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Ошибка при добавлении, Документ не добавлен!");
                        }
                        // MessageBox.Show(id_send.ToString(), "id_______hgkv");


                        foreach (int i in IdFile)
                        {
                            string q = "INSERT INTO `all_one`" +
                                       "    (`id_doc`, `id_file`)" + "    VALUES ("
                                       + MaxNumber + "," + i + ");";
                            MySqlCommand command = new MySqlCommand(q, conn);
                            // выполняем запрос
                            command.ExecuteNonQuery();
                        }
                        conn.Close();
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Ошибка, Документ не добавлен!");
                    }
                }
                else
                {
                    MessageBox.Show("Заполните номер", "");
                }
            }
            else
            {
                MessageBox.Show("Заполните исходящий номер", "");
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                ID = "24";
            }

            conn.Close();
            conn.Open();
            string later = "Select namedoc,number,incom_number,out_number,comments, date_added,date," +
                           "to_date,from_date,status,document_type " +
                           "from documents where id_document=" + ID_Doc + ";";
            string out_number    = "";
            string namedoc       = "";
            string comments      = "";
            string date_added    = "";
            string date          = "";
            string status        = "";
            string document_type = "";
            string number        = "";
            string incom_number  = "";
            string q             = "";
            string to_date       = "";
            string from_date     = "";

            // try
            // {
            using (var reader = new MySqlCommand(later, conn).ExecuteReader())
            {
                if (reader.Read())
                {
                    namedoc    = reader["namedoc"].ToString();
                    out_number = reader["out_number"].ToString();
                    comments   = reader["comments"].ToString();
                    date       = reader["date"].ToString();
                    //MessageBox.Show(date, "ДАТАЭ");
                    date_added    = reader["date_added"].ToString();
                    status        = reader["status"].ToString();
                    document_type = reader["document_type"].ToString();
                    number        = reader["number"].ToString();
                    incom_number  = reader["incom_number"].ToString();
                    to_date       = reader["to_date"].ToString();
                    from_date     = reader["from_date"].ToString();
                }
            }
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                string words = ids.Items[i].ToString();
                string query = "SELECT id,E_MAIL From users where id = " +
                               words + ";";
                int    id_send = 0;
                string e_mail  = "";
                using (var reader = new MySqlCommand(query, conn).ExecuteReader())
                {
                    if (reader.Read())
                    {
                        id_send = int.Parse(reader["id"].ToString());
                        e_mail  = reader["E_MAIL"].ToString();
                    }
                }

                if (!String.IsNullOrEmpty(from_date))
                {
                    DateTime from_dateDate = DateTime.Parse(from_date);
                    if (!String.IsNullOrEmpty(to_date))
                    {
                        DateTime to_dateDate = DateTime.Parse(to_date);

                        if (!String.IsNullOrEmpty(date))
                        {
                            DateTime enteredDate = DateTime.Parse(date);

                            q = "INSERT INTO `documents`" +
                                " ( `number`,`incom_number`,`out_number`, `id_sender`, " +
                                "`id_recipient`,`date`,`comments`,`document_type`," +
                                "`from_date`,`to_date`,`namedoc`,`origin`)" +
                                " VALUES" +
                                "(" + number + ",'" + incom_number + "','" + out_number + "'," +
                                ID + "," + id_send + ",'" +
                                enteredDate.ToString("s") + "','" + comments + "','" +
                                document_type +
                                "','" + from_dateDate.ToString("s") + "','" +
                                to_dateDate.ToString("s") + "','" + namedoc + "','Пересланный');";
                        }
                        else
                        {
                            q = "INSERT INTO `documents`" +
                                " ( `number`,`incom_number`,`out_number`, `id_sender`, " +
                                "`id_recipient`,`comments`,`document_type`," +
                                "`from_date`,`to_date`,`namedoc`,`origin`)" +
                                " VALUES" +
                                "(" + number + ",'" + incom_number + "','" + out_number + "'," +
                                ID + "," + id_send + ",'" + comments + "','" +
                                document_type + "','" + from_dateDate.ToString("s") + "','" +
                                to_dateDate.ToString("s") + "','" + namedoc + "','Пересланный');";
                        }
                    }
                    else
                    {
                        q = "INSERT INTO `documents`" +
                            " ( `number`,`incom_number`,`out_number`, `id_sender`, " +
                            "`id_recipient`,`comments`,`document_type`," +
                            "`from_date`,`namedoc`,`origin`)" +
                            " VALUES" +
                            "(" + number + ",'" + incom_number + "','" + out_number + "'," +
                            ID + "," + id_send + ",'" + comments + "','" +
                            document_type + "','" + from_dateDate.ToString("s") + "','" + namedoc +
                            "','Пересланный');";
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(date))
                    {
                        DateTime enteredDate = DateTime.Parse(date);

                        q = "INSERT INTO `documents`" +
                            " ( `number`,`incom_number`,`out_number`, `id_sender`, " +
                            "`id_recipient`,`date`,`comments`,`document_type`" +
                            ",`namedoc`,`origin`)" +
                            " VALUES" +
                            "(" + number + ",'" + incom_number + "','" + out_number + "'," +
                            ID + "," + id_send + ",'" +
                            enteredDate.ToString("s") + "','" + comments + "','" +
                            document_type +
                            "','" + namedoc + "','Пересланный');";
                    }
                    else
                    {
                        q = "INSERT INTO `documents`" +
                            " ( `number`,`incom_number`,`out_number`, `id_sender`, " +
                            "`id_recipient`,`comments`,`document_type`," +
                            "`namedoc`,`origin`)" +
                            " VALUES" +
                            "(" + number + ",'" + incom_number + "','" + out_number + "'," +
                            ID + "," + id_send + ",'" + comments + "','" +
                            document_type + "','" + namedoc + "','Пересланный');";
                    }
                }


                try
                {
                    SendMail.SEND_MAIlTORECIP(e_mail, out_number);
                }
                catch { }
                MySqlCommand command = new MySqlCommand(q, conn);
                // выполняем запрос
                command.ExecuteNonQuery();

                string query1 = "INSERT INTO `coments`" +
                                "    (`Id_doc`,`number`,`forward`, `usercol`,`recipcol`)" +
                                "    VALUES (" + ID_Doc + "," + number
                                + ",'пересылка'," + ID + "," + id_send + "); ";
                MySqlCommand command1 = new MySqlCommand(query1, conn);
                // выполняем запрос
                int UspeshnoeIzmenenie1 = command1.ExecuteNonQuery();
            }
            for (int i = 0; i < listBox2.Items.Count; i++)
            {
                string words = ido.Items[i].ToString();
                string query = "SELECT id,E_MAIL From users where dep_id = " +
                               words + ";";
                List <int>    id_send = new List <int>();
                List <string> e_mail  = new List <string>();
                using (var reader = new MySqlCommand(query, conn).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        id_send.Add(int.Parse(reader["id"].ToString()));
                        e_mail.Add(reader["E_MAIL"].ToString());
                    }
                }
                for (int j = 0; j < id_send.Count(); j++)
                {
                    if (!String.IsNullOrEmpty(date))
                    {
                        DateTime enteredDate = DateTime.Parse(date);
                        q = "INSERT INTO `documents`" +
                            " ( `number`,`out_number`, `id_sender`, `id_recipient`,`date`,`comments`,`document_type`)" +
                            " VALUES" +
                            "(" + number + ",'" + out_number + "'," +
                            ID + "," + id_send[j] + ",'" +
                            enteredDate.ToString("s") + "','" + comments + "','" +
                            document_type + "');";
                    }
                    else
                    {
                        q = "INSERT INTO `documents`" +
                            " ( `number`,`out_number`, `id_sender`, `id_recipient`,`comments`,`document_type`)" +
                            " VALUES" +
                            "(" + number + ",'" + out_number + "'," +
                            ID + "," + id_send[j] + ",'" + comments + "','" +
                            document_type + "');";
                    }
                    SendMail.SEND_MAIlTORECIP(e_mail[j], out_number);
                    MySqlCommand command = new MySqlCommand(q, conn);
                    command.ExecuteNonQuery();
                }
            }
            conn.Close();

            /* }
             * catch(Exception ex)
             * {
             *  MessageBox.Show(ex.Message, "Ошибка отправки");
             * }*/
            this.Close();
        }