private void Save_Click(object sender, EventArgs e) { var sfd = new SaveFileDialog() { Filter = "Файлы заказов|*.dw" }; var result = sfd.ShowDialog(this); if (result == DialogResult.OK) { var dto = GetModelFromUI(); DeliverySerializer.WriteToFile(sfd.FileName, dto); } }
private void Save_Click(object sender, EventArgs e) { SqlConnection sqlcon = new SqlConnection(connection); if (dtbl.Rows.Count == 0 && type != "admin") { var sfd = new SaveFileDialog() { Filter = "Файлы заказов|*.dw", InitialDirectory = Application.StartupPath }; var result = sfd.ShowDialog(this); SqlCommand com = new SqlCommand("INSERT INTO Orders (Name,PlacesAmount,TotalPrice, State, Filepath, UserId) VALUES (@Name,@PlacesAmount,@TotalPrice,@State,@Filepath,@UserId)", sqlcon); com.Parameters.AddWithValue("Name", FullNameBox.Text); com.Parameters.AddWithValue("PlacesAmount", listBox1.Items.Count); com.Parameters.AddWithValue("TotalPrice", CostUD.Value); if (StateBox.SelectedItem == null) { StateBox.SelectedItem = "принят к обработке"; } com.Parameters.AddWithValue("State", StateBox.SelectedItem.ToString()); com.Parameters.AddWithValue("Filepath", sfd.FileName); com.Parameters.AddWithValue("UserId", id); sqlcon.Open(); com.ExecuteNonQuery(); if (result == DialogResult.OK) { var dto = GetModelFromUI(); DeliverySerializer.WriteToFile(sfd.FileName, dto); Close(); } } else { SqlCommand com = new SqlCommand("UPDATE Orders SET State = N'" + StateBox.SelectedItem.ToString() + "', Filepath = N'" + DeliverySerializer.newPath + "' WHERE Id = '" + orderId + "'", sqlcon); sqlcon.Open(); com.ExecuteNonQuery(); var dto = GetModelFromUI(); DeliverySerializer.WriteToFile(DeliverySerializer.newPath, dto); Close(); } }