private void button_OK_StationForm_Click(object sender, EventArgs e) { try { string FillStation = "exec [dbo].[FillStation] " + textBox_Add_Code_StationForm.Text.Trim() + "," + textBox_Add_Code6_StationForm.Text.Trim() + "," + textBox_Add_Name_StationForm.Text.Trim() + "','" + User_AID + "'"; string SelectDubl = "select * from d__Station where Code = " + textBox_Add_Code_StationForm.Text.Trim(); DataTable dt = new DataTable(); dt = DbConnection.DBConnect(SelectDubl); if (dt.Rows.Count == 0) { DbConnection.DBConnect(FillStation); this.Close(); MessageBox.Show("Запись добавлена!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); StationForm main = this.Owner as StationForm; main.btn_refsh_station_form_Click_1(null, null); } else { MessageBox.Show("Станция с кодом: " + textBox_Add_Code_StationForm.Text.Trim() + " имеется в справочнике", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (SqlException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exp) { MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_Updt_OK_StationForm_Click(object sender, EventArgs e) { try { string Updt_CurrentStation = "update d__Station " + "set Name = '" + textBox_Updt_Name_StationForm.Text.Trim() + "', Code = " + Convert.ToInt32(textBox_Updt_Code_StationForm.Text.Trim()) + ", Code6 = " + Convert.ToInt32(textBox_Updt_Code6_StationForm.Text.Trim()) + " " + "where ID = " + selectStationID; DataTable dtbl = new DataTable(); dtbl = DbConnection.DBConnect(Updt_CurrentStation); this.Close(); MessageBox.Show("Станция изменена!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); StationForm main = this.Owner as StationForm; main.btn_refsh_station_form_Click_1(null, null); } catch (SqlException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exp) { MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }