Ejemplo n.º 1
0
        public zayavki()
        {
            InitializeComponent();


            var dbCon = DBConn.Instance();

            dbCon.Connection   = null;
            dbCon.DatabaseName = "570_abp";
            dbCon.Host         = "5.187.7.31";
            if (dbCon.IsConnect())
            {
                string query  = "SELECT num FROM zayvki";
                var    cmd    = new MySqlCommand(query, dbCon.Connection);
                var    reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    allCount = reader.GetInt32(0);
                    allCount++;
                    zayavkaLabel.Text = "Заявка №" + allCount + " от " + thisDay.ToString("d");
                }
            }
            else
            {
                MessageBox.Show("Ошибка связи с сервером");
            }



            dbCon.Close();



            dbCon.Connection   = null;
            dbCon.DatabaseName = "570_abp";
            dbCon.Host         = "5.187.7.31";
            if (dbCon.IsConnect())
            {
                string query  = "SELECT name FROM spisokDronov";
                var    cmd    = new MySqlCommand(query, dbCon.Connection);
                var    reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    droneList.Items.Add(reader.GetValue(0).ToString());
                }
            }
            else
            {
                MessageBox.Show("Ошибка связи с сервером");
            }
        }
Ejemplo n.º 2
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            var dbCon = DBConn.Instance();

            dbCon.Connection   = null;
            dbCon.DatabaseName = "570_abp";
            dbCon.Host         = "5.187.7.31";
            if (dbCon.IsConnect())
            {
                string query = "";
                try
                {
                    if (fio.Text.ToString() != ""
                        // && dataGridView1.Rows[i].Cells[1].Value.ToString() != ""

                        && count.Text != "")
                    {
                        if (droneList.SelectedItem != null)
                        {
                            query = String.Format("INSERT INTO zayvki(fio, drone, count, date_of_zakaz, date_of_change, state, num) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
                                                  fio.Text.ToString(),
                                                  droneList.SelectedItem.ToString(),
                                                  count.Text.ToString(),
                                                  thisDay.ToString("d"),
                                                  thisDay.ToString("d"),
                                                  "Создан",
                                                  allCount.ToString());
                            var cmd = new MySqlCommand(query, dbCon.Connection);
                            cmd.ExecuteNonQuery();

                            MessageBox.Show("Заявка отправлена.");
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Ошибка добавления. Выберите дрон.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Ошибка добавления. Одно из полей не заполнено.");
                    }
                }
                catch (MySqlException ee)
                {
                    MessageBox.Show("MysqlError: " + ee.ToString());
                }
            }
        }
Ejemplo n.º 3
0
        private void PosmotrZv_Load(object sender, EventArgs e)
        {
            var dbCon = DBConn.Instance();

            dbCon.Connection   = null;
            dbCon.DatabaseName = "570_abp";
            dbCon.Host         = "5.187.7.31";
            string query = "";

            if (dbCon.IsConnect())
            {
                query = String.Format("SELECT * FROM zayvki");

                var cmd = new MySqlCommand(query, dbCon.Connection);
                //cmd.ExecuteNonQuery();

                // SqlConnection dataBaseConnection = new SqlConnection(conn);
                var             reader = cmd.ExecuteReader();
                List <string[]> data   = new List <string[]>();
                int             i      = 1;
                while (reader.Read())
                {
                    data.Add(new string[7]);

                    data[data.Count - 1][0] = reader[0].ToString();
                    data[data.Count - 1][1] = reader[1].ToString();
                    data[data.Count - 1][2] = reader[2].ToString();
                    data[data.Count - 1][3] = reader[3].ToString();
                    data[data.Count - 1][4] = reader[4].ToString();
                    data[data.Count - 1][5] = reader[5].ToString();
                    data[data.Count - 1][6] = reader[6].ToString();
                }


                reader.Close();
                dbCon.Close();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                foreach (string[] s in data)
                {
                    dataGridView1.Rows.Add(s);
                }
            }
        }
Ejemplo n.º 4
0
        private void LoadData()
        {
            var dbCon = DBConn.Instance();

            dbCon.Connection   = null;
            dbCon.DatabaseName = "570_abp";
            dbCon.Host         = "5.187.7.31";
            string query = "";

            if (dbCon.IsConnect())
            {
                query = String.Format("SELECT name,SUM(count) FROM priem WHERE `date`='{0}' GROUP BY name", dateTimePicker1.Value.ToString("d"));

                var cmd = new MySqlCommand(query, dbCon.Connection);
                //cmd.ExecuteNonQuery();

                // SqlConnection dataBaseConnection = new SqlConnection(conn);
                var             reader = cmd.ExecuteReader();
                List <string[]> data   = new List <string[]>();
                int             i      = 1;
                while (reader.Read())
                {
                    data.Add(new string[3]);

                    data[data.Count - 1][0] = (i++).ToString();
                    data[data.Count - 1][1] = reader[0].ToString();
                    data[data.Count - 1][2] = reader[1].ToString();
                }


                reader.Close();
                dbCon.Close();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                foreach (string[] s in data)
                {
                    dataGridViewOst.Rows.Add(s);
                }
            }
        }
Ejemplo n.º 5
0
 public Form2()
 {
     var dbCon = DBConn.Instance();
     dbCon.Connection = null;
     dbCon.DatabaseName = "570_abp";
     dbCon.Host = "5.187.7.31";
     InitializeComponent();
     if (dbCon.IsConnect())
     {
         string query = "SELECT num_post FROM priem";
         var cmd = new MySqlCommand(query, dbCon.Connection);
         var reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             allCount = reader.GetInt32(0);
             label1.Text = "Поступление комплектующих № " + reader.GetString(0) + " от " + thisDay.ToString("d");
         }
     }
     else {
         MessageBox.Show("Ошибка связи с сервером");
     }
     
     dbCon.Close();
 }
Ejemplo n.º 6
0
        public void OpenExcel(string path, int textbox)
        {
            Microsoft.Office.Interop.Excel.Application xlApp       = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook    xlWorkbook  = xlApp.Workbooks.Open(path);
            Microsoft.Office.Interop.Excel._Worksheet  xlWorksheet = xlWorkbook.Sheets[1];
            Microsoft.Office.Interop.Excel.Range       xlRange     = xlWorksheet.UsedRange;
            int rowCount = xlRange.Rows.Count;
            int colCount = xlRange.Columns.Count;
            var dbCon    = DBConn.Instance();

            dbCon.DatabaseName = "570_abp";
            dbCon.Host         = "5.187.7.31";
            string query = "";

            if (dbCon.IsConnect())
            {
                if (textbox == 1)
                {
                    try
                    {
                        for (int i = 2; i <= rowCount; i++)
                        {
                            query = String.Format("INSERT INTO parts(name, category) VALUES('{0}','{1}')", xlRange.Cells[i, 2].Value2.ToString(), xlRange.Cells[i, 3].Value2.ToString());
                            var cmd = new MySqlCommand(query, dbCon.Connection);
                            cmd.ExecuteNonQuery();

                            /* for (int j = 1; j <= colCount; j++)
                             * {
                             *
                             *  if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
                             *      MessageBox.Show(xlRange.Cells[i, j].Value2.ToString());
                             * }*/
                        }
                    }
                    catch (MySqlException err)
                    {
                        MessageBox.Show("MysqlError: " + err.ToString());
                    }
                    textBoxDron.Text = "Данные успешно добавились";
                }
                if (textbox == 0)
                {
                    for (int i = 2; i <= rowCount; i++)
                    {
                        try
                        {
                            int num;
                            if (Int32.TryParse(xlRange.Cells[i, 3].Value2.ToString(), out num))
                            {
                                query = String.Format("INSERT INTO spisokDronov(name, cost) VALUES('{0}','{1}')", xlRange.Cells[i, 2].Value2.ToString(), xlRange.Cells[i, 3].Value2.ToString());
                                var cmd = new MySqlCommand(query, dbCon.Connection);
                                cmd.ExecuteNonQuery();
                            }
                        }
                        catch (MySqlException err)
                        {
                            MessageBox.Show("MysqlError: " + err.ToString());
                            return;
                        }

                        /* for (int j = 1; j <= colCount; j++)
                         * {
                         *
                         *  if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
                         *      MessageBox.Show(xlRange.Cells[i, j].Value2.ToString());
                         * }*/
                    }
                    textBoxDron.Text = "Данные успешно добавились";
                }
                if (textbox == 2)
                {
                    for (int i = 2; i <= rowCount; i++)
                    {
                        try
                        {
                            int num;
                            if (Int32.TryParse(xlRange.Cells[i, 4].Value2.ToString(), out num))
                            {
                                query = String.Format("INSERT INTO technologicalMap(dron, detail, count) VALUES('{0}','{1}','{2}')", xlRange.Cells[i, 2].Value2.ToString(), xlRange.Cells[i, 3].Value2.ToString(), xlRange.Cells[i, 4].Value2.ToString());

                                var cmd = new MySqlCommand(query, dbCon.Connection);
                                cmd.ExecuteNonQuery();
                            }
                        }
                        catch (MySqlException err)
                        {
                            MessageBox.Show("MysqlError: " + err.ToString());
                            return;
                        }

                        /* for (int j = 1; j <= colCount; j++)
                         * {
                         *
                         *  if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
                         *      MessageBox.Show(xlRange.Cells[i, j].Value2.ToString());
                         * }*/
                    }
                    textBoxDron.Text = "Данные успешно добавились";
                }
            }
            else
            {
                MessageBox.Show("Ошибка связи с сервером");
            }
            dbCon.Close();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            xlWorkbook.Close();
        }
Ejemplo n.º 7
0
 private void uploadB_Click(object sender, EventArgs e)
 {
     var dbCon = DBConn.Instance();
     dbCon.Connection = null;
     dbCon.DatabaseName = "570_abp";
     dbCon.Host = "5.187.7.31";
     if (dbCon.IsConnect())
     {
         allCount++;
         string query = "";
         try
         {
             for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
             {
                  if (dataGridView1.Rows[i].Cells[0].Value.ToString() != "" 
                    // && dataGridView1.Rows[i].Cells[1].Value.ToString() != ""
                     && dataGridView1.Rows[i].Cells[2].Value.ToString() != ""
                     && nameTBox.Text!="")
                  {
                     if ((Regex.IsMatch(dataGridView1.Rows[i].Cells[0].Value.ToString(), "\\bАКБ\\b") || Regex.IsMatch(dataGridView1.Rows[i].Cells[0].Value.ToString(), "\\bакб\\b")) && dataGridView1.Rows[i].Cells[1].Value.ToString() != "")
                     {
                         query = String.Format("INSERT INTO priem(name, serial,count,employee,date,num_post) VALUES('{0}','{1}','{2}','{3}','{4}','{5}')",
                             dataGridView1.Rows[i].Cells[0].Value.ToString(),
                             dataGridView1.Rows[i].Cells[1].Value.ToString(),
                             dataGridView1.Rows[i].Cells[2].Value.ToString(),
                             nameTBox.Text.ToString(),
                             thisDay.ToString("d"),
                             allCount.ToString());
                         var cmd = new MySqlCommand(query, dbCon.Connection);
                         cmd.ExecuteNonQuery();
                     } else if (!(Regex.IsMatch(dataGridView1.Rows[i].Cells[0].Value.ToString(), "\\bАКБ\\b"))){
                         query = String.Format("INSERT INTO priem(name,count,employee,date,num_post) VALUES('{0}','{1}','{2}','{3}','{4}')",
                             dataGridView1.Rows[i].Cells[0].Value.ToString(),
                             dataGridView1.Rows[i].Cells[2].Value.ToString(),
                             nameTBox.Text.ToString(),
                             thisDay.ToString("d"),
                             allCount.ToString());
                         var cmd = new MySqlCommand(query, dbCon.Connection);
                         cmd.ExecuteNonQuery();
                     }
                  }
                  else
                  {
                      MessageBox.Show("Ошибка добавления");
                  }
                 //for(int j = 0; j < 3; j++)
                 //  {
                 //  if (dataGridView1.Rows[i].Cells[j].Value != null)
                 // }
             }
         }catch(MySqlException ee)
         {
             MessageBox.Show("MysqlError: " + ee.ToString());
         }
     }
     else
     {
         MessageBox.Show("Ошибка с сервером");
     }
     dbCon.Close();
 }