private void button1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("Enter sql query"); } else if (String.IsNullOrEmpty(textBox2.Text)) { MessageBox.Show("Enter name database"); } else { DataTable dataTable = ConnectionClass.ReturnTable(textBox2.Text, textBox1.Text); Form4 form4 = new Form4(dataTable); form4.Show(); } }
private void button2_Click(object sender, EventArgs e) { bool flagConStr = false, flagLogin = false; if (radioButton1.Checked) { if (String.IsNullOrEmpty(comboBox1.Text)) { MessageBox.Show("ERROR - select an available connection from the list"); } else { ConnectionClass.severStr = comboBox1.Text; flagConStr = true; } } if (radioButton2.Checked) { if (String.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("ERROR - Enter connection point"); } else { if (ConnectionClass.Scan(textBox1.Text)) { ConnectionClass.severStr = textBox1.Text; flagConStr = true; } else { MessageBox.Show("ERROR - Invalid character found in connection string"); } } } if (radioButton3.Checked) { ConnectionClass.winAuthentication = true; flagLogin = true; } else { ConnectionClass.winAuthentication = false; } if (radioButton4.Checked) { if (String.IsNullOrEmpty(textBox2.Text) || String.IsNullOrEmpty(textBox3.Text)) { MessageBox.Show("ERROR - the string 'Name' and / or 'Password' is empty"); } else { if (ConnectionClass.Scan(textBox2.Text) && ConnectionClass.Scan(textBox3.Text)) { ConnectionClass.loginUser = textBox2.Text; ConnectionClass.password = textBox3.Text; flagLogin = true; } else { MessageBox.Show("ERROR LOGIN - Invalid character found in connection string"); } } } if (flagConStr && flagLogin) { this.Hide(); Form2 form2 = new Form2(); form2.ShowDialog(); } }
public void SaveToServer() { ConnectionClass.UpdateDataTable(NameDB, NameTable, ObjectTable); }
public void UpdateDT() { ObjectTable.Clear(); ObjectTable = ConnectionClass.FillDataTable(NameDB, NameTable); }
private static void FillShopDB() { string[] name_mas = new string[] { "Лысый", "Валера", "Огурчик Рик", "Бильба", "Ариец", "Дзенька", "Баклан", "Роман", "Пельмень", "Плет" }; string[] surname_mas = new string[] { "Гомик", "Звездный час", "Сычуанський", "Бегинса", "Эталонный", "Тупой", "Аркадиевич", "ЛуДший", "Пузякович", "Бойс" }; string[] products = new string[] { "Устройство для щекотания очка", "ЭлектроДрын", "Надувной Жигуль", "Квантовый памятник кедру", "Летающая тарeлка", "Бомж Петрович", "Охладитель траханья", "Бластер Петровича", "Пикачу", "Болт" }; Random random = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < 10; i++) { string numberPhone = String.Format("+380{0}", random.Next(950000000, 959999999)); string login = String.Format("{0}_{1}", surname_mas[i], random.Next(0, 1000)); string passvord = String.Format("{0}{1}{2}", random.Next(0, 100), name_mas[i], random.Next(100, 1000)); string sqlExpression = String.Format("INSERT INTO Customers(Name,Surname,NumberPhone,Login,Password) VALUES ('{0}','{1}','{2}','{3}','{4}')", name_mas[i], surname_mas[i], numberPhone, login, passvord); ConnectionClass.Execute("ShopDB_test_task", sqlExpression); sqlExpression = String.Format("INSERT INTO Products(NameProduct,Description,Price) VALUES ('{0}','lorem ipsum...',{1})", products[i], random.Next(50, 1000)); ConnectionClass.Execute("ShopDB_test_task", sqlExpression); } DataTable user = new DataTable(); DataTable shop = new DataTable(); DataTable order = new DataTable(); user = ConnectionClass.ReturnTable("ShopDB_test_task", "SELECT Id_Customer FROM Customers"); shop = ConnectionClass.ReturnTable("ShopDB_test_task", "SELECT * FROM Products"); for (int t = 0; t < 10; t++) { for (int i = 0; i < 10; i++) { List <int> idProd = new List <int>(); int Q = random.Next(1, 4); for (int j = 0; j < Q; j++) { int W = random.Next(0, shop.Rows.Count - 1); idProd.Add(Convert.ToInt32(shop.Rows[W]["Id_Product"])); } int sum = 0; foreach (int id in idProd) { for (int y = 0; y < 10; y++) { if (Convert.ToInt32(shop.Rows[y]["Id_Product"]) == id) { sum += Convert.ToInt32(shop.Rows[y]["Price"]); } } } ConnectionClass.Execute("ShopDB_test_task", String.Format("INSERT INTO Orders(Date,Customer,Delivery_City,Delivery_Address,Cost,Status)" + " VALUES('{0}',{1},'random city','random address',{2},'in processing')", DateTime.Now, Convert.ToInt32(user.Rows[i]["Id_Customer"]), sum)); order = ConnectionClass.ReturnTable("ShopDB_test_task", "SELECT Id_Order FROM Orders"); int idOrder = Convert.ToInt32(order.Rows[order.Rows.Count - 1]["Id_Order"]); foreach (int id in idProd) { ConnectionClass.Execute("ShopDB_test_task", String.Format("INSERT INTO OrdersProducts(ID_Order,ID_Product) VALUES({0},{1})", idOrder, id)); } //idProd.Clear(); //sum = 0; } } }