private void addPrdButton_Click(object sender, EventArgs e) { //check this id is already exist at warehouse? string checkId = $"SELECT count(warehouse) as kontrol FROM {mainPage.productType} WHERE id = {int.Parse(txtId.Text)} AND warehouse = {mainPage.store}"; MySqlDataReader reader = database.Reader(checkId); mainpage.checkTotalCapacity(int.Parse(mainPage.store)); mainpage.checkCurrentCapacity(int.Parse(mainPage.store)); try { while (reader.Read()) { if (reader[0].ToString() != "1") { if (mainPage.currentCapacity + int.Parse(txtStock.Text) <= mainPage.totalCapacity) { //if capacity is enough? string query = $"INSERT INTO {mainPage.productType} (id,name,stock,warehouse) " + $"VALUES ('{int.Parse(txtId.Text)}','{txtName.Text}','{int.Parse(txtStock.Text)}','{mainPage.store}')"; database.ExecuteQuery(query); mainpage.updateCapacity(); mainpage.productTable.DataSource = database.ListDatas(mainPage.productType, mainPage.store).Tables[0]; mainpage.draw(); } else { MessageBox.Show("Not enough capacity"); } } else { MessageBox.Show("This Id already exist!"); } } } catch (Exception err) { MessageBox.Show("err" + MessageBox.Show(err.Message) + MessageBoxButtons.OK + MessageBoxIcon.Error); } finally { this.Close(); database.Disconnect(); } }
private void addBtn_Click(object sender, EventArgs e) { mainPage mainpage = new mainPage(); //check this stockroom is already exist? string checkId = $"SELECT count(id) as kontrol FROM stockroom WHERE id = {int.Parse(cmbId.SelectedItem.ToString())} OR name = '{txtName.Text}'"; MySqlDataReader reader = database.Reader(checkId); count(); try { while (reader.Read()) { if (int.Parse(reader[0].ToString()) < 1 && countStockroom < 4) { //if number of warehouse < 4 if (int.Parse(txtCapacity.Text) > 0 && int.Parse(txtCapacity.Text) < 200) { //if capacity under 200 string query = $"INSERT INTO stockroom (id,name,capacity) " + $"VALUES ('{int.Parse(cmbId.SelectedItem.ToString())}','{txtName.Text}','{int.Parse(txtCapacity.Text)}')"; database.ExecuteQuery(query); mainpage.draw(); this.Close(); } else { MessageBox.Show("Capacity must be under 200(max)!"); } } else { MessageBox.Show("This Stockroom already exist or you have reached max Stockroom (4)!"); } } } catch (Exception err) { MessageBox.Show("err" + MessageBox.Show(err.Message) + MessageBoxButtons.OK + MessageBoxIcon.Error); } finally { database.Disconnect(); } }
private void deleteButton_Click(object sender, EventArgs e) { mainPage mainpage = new mainPage(); string query = $"DELETE FROM {mainPage.productType} WHERE id = '{prdTable.SelectedRows[0].Cells[0].Value.ToString()}' AND warehouse = '{mainPage.store}'"; try { //execute query and draw buttons/graphbuttons database.ExecuteQuery(query); prdTable.DataSource = database.ListDatas(mainPage.productType, mainPage.store).Tables[0]; mainpage.draw(); } catch (Exception err) { MessageBox.Show("err" + MessageBox.Show(err.Message) + MessageBoxButtons.OK + MessageBoxIcon.Error); } finally { database.Disconnect(); } }