ПЗ (1218909), страница 14
Текст из файла (страница 14)
catch { }
}
else
{
//Добавим запись в БД
string sqlText = @"UPDATE minimals SET ID_good=" + ID_goods_listBox.Items[MinimalsGoodcomboBox.SelectedIndex] + ", ID_warehouse=" + ID_warehouse_listBox.Items[MinimalsWarehousecomboBox.SelectedIndex] + ", GoodAmount="+MinimalsResttextBox.Text+" WHERE ID="+ID_MinimalslistBox.Items[Minimals_listView.SelectedIndices[0]];//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySQLCommand.ExecuteNonQuery();
}
catch { }
}
MinimalsGoodcomboBox.Visible = false;
MinimalsGoodlabel.Visible = false;
MinimalsRestlabel.Visible = false;
MinimalsResttextBox.Visible = false;
MinimalsWarehousecomboBox.Visible = false;
MinimalsWarehouselabel.Visible = false;
MinimalsSavebutton.Visible = false;
MinimalsCancelbutton.Visible = false;
FullMinimals();
}
private void FullGoodsComboBox()
{
ID_goods_listBox.Items.Clear();
MinimalsGoodcomboBox.Items.Clear();
DemandData_good_comboBox.Items.Clear();
SaleGoodcomboBox.Items.Clear();
Into_doc_good_comboBox.Items.Clear();
string sqlText = @"SELECT ID_good,GoodName FROM goods";//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySqlDataReader Reader = MySQLCommand.ExecuteReader();
while (Reader.Read())//Построчно перебираем результат запроса
{
ID_goods_listBox.Items.Add(Convert.ToString(Reader.GetInt32(0)));
MinimalsGoodcomboBox.Items.Add(Reader.GetString(1));
DemandData_good_comboBox.Items.Add(Reader.GetString(1));
SaleGoodcomboBox.Items.Add(Reader.GetString(1));
Into_doc_good_comboBox.Items.Add(Reader.GetString(1));
}
}
catch { }
}
private void FullPeopleList()
{
ID_people_listBox.Items.Clear();
People_listBox.Items.Clear();
//Получим запросом содержимое справочника и выведем его в таблицу
string sqlText = "SELECT * FROM persons";//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySqlDataReader Reader = MySQLCommand.ExecuteReader();
while (Reader.Read())//Построчно перебираем результат запроса
{
ID_people_listBox.Items.Add(Convert.ToString(Reader.GetInt32(0)));
People_listBox.Items.Add(Reader.GetString(1));
}
}
catch { }
}
private void FullBrigadeList()
{
if(Brigade_comboBox.SelectedIndex!=-1)
{
BrigadeDatalistBox.Items.Clear();
ID_persons_In_brigadelistBox.Items.Clear();
string sqlText = @"SELECT persons.FIO, group_table.ID_person
FROM
group_table
JOIN persons
ON persons.ID_person = group_table.ID_person
WHERE group_table.ID_group="+ID_group_listBox.Items[Brigade_comboBox.SelectedIndex];//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySqlDataReader Reader = MySQLCommand.ExecuteReader();
while (Reader.Read())//Построчно перебираем результат запроса
{
BrigadeDatalistBox.Items.Add(Reader.GetString(0));
ID_persons_In_brigadelistBox.Items.Add(Convert.ToString(Reader.GetInt32(1)));
}
}
catch { }
}
}
private void FullLocationDataList()
{
if (Brigade_locations_comboBox.SelectedIndex != -1)
{
LocationDatalistBox.Items.Clear();
ID_brigade_in_locationlistBox.Items.Clear();
string sqlText = @"SELECT location_data.ID_group
, groups.GroupName
FROM
location_data
JOIN
groups
ON groups.ID_group = location_data.ID_group
WHERE
location_data.ID_location = " + ID_location_listBox.Items[Brigade_locations_comboBox.SelectedIndex];//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySqlDataReader Reader = MySQLCommand.ExecuteReader();
while (Reader.Read())//Построчно перебираем результат запроса
{
LocationDatalistBox.Items.Add(Reader.GetString(1));
ID_brigade_in_locationlistBox.Items.Add(Convert.ToString(Reader.GetInt32(0)));
}
}
catch { }
}
}
private void Brigade_comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
FullBrigadeList();
}
private void Brigade_locations_comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
FullLocationDataList();
}
private void AddToBrigadebutton_Click(object sender, EventArgs e)
{
if(People_listBox.SelectedIndex!=-1)
{
//Добавим запись в БД
string sqlText = @"INSERT INTO group_table(ID_group,ID_person) VALUES(" + ID_group_listBox.Items[Brigade_comboBox.SelectedIndex] + "," + ID_people_listBox.Items[People_listBox.SelectedIndex] + ")";//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySQLCommand.ExecuteNonQuery();
}
catch { }
FullBrigadeList();
}
}
private void AddToLocationbutton_Click(object sender, EventArgs e)
{
if(Brigade_comboBox.SelectedIndex!=-1)
{
if(Brigade_locations_comboBox.SelectedIndex!=-1)
{
//Добавим запись в БД
string sqlText = @"INSERT INTO location_data(ID_group,ID_location) VALUES(" + ID_group_listBox.Items[Brigade_comboBox.SelectedIndex] + "," + ID_location_listBox.Items[Brigade_locations_comboBox.SelectedIndex] + ")";//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySQLCommand.ExecuteNonQuery();
}
catch { }
FullLocationDataList();
}
}
}
private void DeleteFromBrigadebutton_Click(object sender, EventArgs e)
{
if(BrigadeDatalistBox.SelectedIndex!=-1)
{
string sqlText = @"DELETE FROM group_table WHERE ID_group=" + ID_group_listBox.Items[Brigade_comboBox.SelectedIndex] + " AND ID_person=" + ID_persons_In_brigadelistBox.Items[BrigadeDatalistBox.SelectedIndex];//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySQLCommand.ExecuteNonQuery();
}
catch { }
FullBrigadeList();
}
}
private void DeleteFromLocationbutton_Click(object sender, EventArgs e)
{
if(LocationDatalistBox.SelectedIndex!=-1)
{
string sqlText = @"DELETE FROM location_data WHERE ID_group=" + ID_brigade_in_locationlistBox.Items[LocationDatalistBox.SelectedIndex]+ " AND ID_location=" + ID_location_listBox.Items[Brigade_locations_comboBox.SelectedIndex];//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySQLCommand.ExecuteNonQuery();
}
catch { }
FullLocationDataList();
}
}
private void FullBrigadeComboBox()
{
ID_group_listBox.Items.Clear();
Brigade_comboBox.Items.Clear();
//Получим запросом содержимое справочника и выведем его в таблицу
string sqlText = "SELECT * FROM groups";//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД
MySqlCommand MySQLCommand = new MySqlCommand(sqlText, MySQLConnection);
MySqlDataReader Reader = MySQLCommand.ExecuteReader();
while (Reader.Read())//Построчно перебираем результат запроса
{
ID_group_listBox.Items.Add(Convert.ToString(Reader.GetInt32(0)));
Brigade_comboBox.Items.Add(Reader.GetString(1));
}
}
catch { }
}
private void DemandAddbutton_Click(object sender, EventArgs e)
{
DemandData_listView.Items.Clear();
FullWarehouseCarLocationComboBox();
Demand_Warehouse_comboBox.Visible = true;
DemandDatelabel.Visible = true;
DemanddateTimePicker.Visible = true;
DemandNumberlabel.Visible = true;
DemandNumbertextBox.Visible = true;
DemandSavebutton.Visible = true;
DemandWarehouselabel.Visible = true;
DemandData_listView.Visible = true;
DemandCancelbutton.Visible = true;
DemandDataAddbutton.Visible = true;
DemandDataDeletebutton.Visible = true;
ID_demandData_listBox.Items.Clear();
}
private void DemandCancelbutton_Click(object sender, EventArgs e)
{
Demand_Warehouse_comboBox.Visible = false;
DemandDatelabel.Visible = false;
DemanddateTimePicker.Visible = false;
DemandNumberlabel.Visible = false;
DemandNumbertextBox.Visible = false;
DemandSavebutton.Visible = false;
DemandWarehouselabel.Visible = false;
DemandData_listView.Visible = false;
DemandCancelbutton.Visible = false;
DemandDataAddbutton.Visible = false;
DemandDataDeletebutton.Visible = false;
ID_demandData_listBox.Items.Clear();
}
private void DemandDataAddbutton_Click(object sender, EventArgs e)
{
FullGoodsComboBox();
DemandDataCancelbutton.Visible = true;
DemandDateSavebutton.Visible = true;
DemandAmountlabel.Visible = true;
DemandAmounttextBox.Visible = true;
DemandData_good_comboBox.Visible = true;
Demand_good_label.Visible = true;
}
private void DemandDataCancelbutton_Click(object sender, EventArgs e)
{
DemandDataCancelbutton.Visible = false;
DemandDateSavebutton.Visible = false;
DemandAmountlabel.Visible = false;
DemandAmounttextBox.Visible = false;
DemandData_good_comboBox.Visible = false;
Demand_good_label.Visible = false;
}
private string ConvertStandartToSQL(string DateText)
{
string DayText;//переменная для дней
string MonthText;//переменная для месяца
string YearText;//переменная для года
DayText = DateText.Substring(0, 2);//Выбираем из строки DateText 2 элемента, начиная с 0 и присваиваем их значения переменной "день"
MonthText = DateText.Substring(3, 2);
YearText = DateText.Substring(6, 4);
string NewDate = YearText + "-" + MonthText + "-" + DayText;//собираем строку
return NewDate;//возвращаем полученную строку
}
private void DemandSavebutton_Click(object sender, EventArgs e)
{
//Добавим запись в БД
string sqlText = @"INSERT INTO demands(DocDate,ID_warehouse,DemandState) VALUES('"+ConvertStandartToSQL(DemanddateTimePicker.Value.ToShortDateString())+"'," + ID_warehouse_listBox.Items[Demand_Warehouse_comboBox.SelectedIndex] + ",0)";//Текст SQL запроса
MySqlConnection MySQLConnection = new MySqlConnection(ConnectionString);//Создадим соединение
try
{
MySQLConnection.Open();//Откроем соединение с БД















