Ejemplo n.º 1
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();
 }