private void button22_Click(object sender, EventArgs e) { Typ Typ_Kursor = Current_Cursor_Typ(); int saveRow = dataGridView4.CurrentCell.RowIndex; int saveColumn = dataGridView4.CurrentCell.ColumnIndex; Form_add_Typ form_add_Typ = new Form_add_Typ(1, Typ_Kursor); form_add_Typ.SetDesktopLocation(this.Location.X + this.Size.Width, this.Location.Y); var result = form_add_Typ.ShowDialog(); if (result == DialogResult.OK) { Typ typ = form_add_Typ.ReturnValue; DataClasses1DataContext dc = new DataClasses1DataContext(con); Typ type = dc.Typs.FirstOrDefault(adr => adr.Id.Equals(typ.Id)); Typ save = new Typ(); save.Nazwa = String.Copy(type.Nazwa); save.Opis = String.Copy(type.Opis); type.Nazwa = typ.Nazwa; type.Opis = typ.Opis; try { dc.SubmitChanges(); MONGO.MongoDB.Add_action(Login, "Zmieniono Typ Apartamentu (" + typ.Nazwa + " , " + typ.Opis + ")", DateTime.Now); var selectQuery2 = from a in dc.GetTable <Typ>() select new { a.Id, a.Nazwa, a.Opis }; dataGridView4.DataSource = selectQuery2; } catch (SqlException sqlexception) { type.Nazwa = save.Nazwa; type.Opis = save.Opis; MessageBox.Show("Zmienianie zostało anulowane. \n\n\n" + "\"" + sqlexception.Message + "\"" + "\n Class: " + sqlexception.Class + "\n State: " + sqlexception.State + "\n Number: " + sqlexception.Number); } catch (Exception exception) { type.Nazwa = save.Nazwa; type.Opis = save.Opis; MessageBox.Show("Zmienianie zostało anulowane. \n\n\n" + "\"" + exception.Message + "\""); } } }
private void button20_Click(object sender, EventArgs e) { Typ Typ_Kursor = Current_Cursor_Typ(); Form_add_Typ form_add_Typ = new Form_add_Typ(0, Typ_Kursor); form_add_Typ.SetDesktopLocation(this.Location.X + this.Size.Width, this.Location.Y); var result = form_add_Typ.ShowDialog(); if (result == DialogResult.OK) { Typ typ = form_add_Typ.ReturnValue; DataClasses1DataContext dc = new DataClasses1DataContext(con); dc.Typs.InsertOnSubmit(typ); try { dc.SubmitChanges(); MONGO.MongoDB.Add_action(Login, "Dodano nowy Typ Apartamentu (" + typ.Nazwa + " , " + typ.Opis + ")", DateTime.Now); var selectQuery2 = from a in dc.GetTable <Typ>() select new { a.Id, a.Nazwa, a.Opis }; dataGridView4.DataSource = selectQuery2; } catch (SqlException sqlexception) { MessageBox.Show("Dodawanie zostało anulowane. \n\n\n" + "\"" + sqlexception.Message + "\"" + "\n Class: " + sqlexception.Class + "\n State: " + sqlexception.State + "\n Number: " + sqlexception.Number); } catch (Exception exception) { MessageBox.Show("Dodawania zostało anulowane.\n\n\n" + "\"" + exception.Message + "\"" + "\n\n\n\n\n\n"); } dataGridView4.CurrentCell = dataGridView4[0, dataGridView4.RowCount - 1]; } }