public SymbolDetailForm(SymbolDataSet.LocalizedSymbolRow currentLocalizedSymbolRow) { InitializeComponent(); // Set up the SoundPlayer object. player = new SoundPlayer(); if (currentLocalizedSymbolRow.RowState == DataRowState.Added) { symbolId = 0; this.BindingContext[this.symbolDetailDataSet, SYMBOL].AddNew(); DataRowView rowView = this.BindingContext[this.symbolDetailDataSet, SYMBOL].Current as DataRowView; SymbolDetailDataSet.SymbolRow currentSymbolRow = rowView.Row as SymbolDetailDataSet.SymbolRow; rowView.BeginEdit(); currentSymbolRow.Name = Guid.NewGuid(); currentSymbolRow.CategoryId = currentLocalizedSymbolRow.CategoryId; rowView.EndEdit(); } else { symbolId = currentLocalizedSymbolRow.SymbolId; } this.symbolDetailDataSet.Merge(currentLocalizedSymbolRow.Table.DataSet.Tables[LOCALIZED_CATEGORY]); this.cultureName = Properties.Settings.Default.CultureName; }
private void buttonOk_Click(object sender, EventArgs e) { try { this.BindingContext[this.symbolDetailDataSet, SYMBOL].EndCurrentEdit(); this.BindingContext[this.symbolDetailDataSet, LOCALIZED_SYMBOL_NAME].EndCurrentEdit(); DataRowView view = this.BindingContext[symbolDetailDataSet, SYMBOL].Current as DataRowView; SymbolDetailDataSet.SymbolRow row = view.Row as SymbolDetailDataSet.SymbolRow; if (row.IsImageNull()) { this.DialogResult = DialogResult.None; // Initializes the variables to pass to the MessageBox.Show method. string message = Resources.ImageNotSetMessage; string caption = Resources.ErrorCaption; // Displays the MessageBox. MessageBox.Show(this, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (SymbolDetailDataSet.LocalizedSymbolNameRow localizedNameRow in this.symbolDetailDataSet.LocalizedSymbolName.Rows) { if (localizedNameRow.CultureName == this.cultureName) { if (localizedNameRow.IsNameNull() || localizedNameRow.Name.Trim().Length == 0) { this.DialogResult = DialogResult.None; // Initializes the variables to pass to the MessageBox.Show method. string message = string.Format(Resources.CannotBeEmptyMessage, localizedNameRow.Language); string caption = Resources.ErrorCaption; // Displays the MessageBox. MessageBox.Show(this, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; } } SymbolDetailDataSet changes = (SymbolDetailDataSet)symbolDetailDataSet.GetChanges(); if (changes != null) { SymbolTableAdapter symbolAdapter = new SymbolTableAdapter(); symbolAdapter.Connection.Open(); symbolAdapter.Update(changes); SqlCommand sqlUpdateCommand = new SqlCommand(); sqlUpdateCommand.Connection = symbolAdapter.Connection; sqlUpdateCommand.CommandText = @"UPDATE Resource SET [Text] = @Text " + "WHERE (ResourceId = @ResourceId AND CultureId = @CultureId) "; sqlUpdateCommand.Parameters.Add(new SqlParameter("@Text", System.Data.SqlDbType.NText, 0, "Text")); sqlUpdateCommand.Parameters.Add(new SqlParameter("@ResourceId", System.Data.SqlDbType.UniqueIdentifier, 0, "ResourceId")); sqlUpdateCommand.Parameters.Add(new SqlParameter("@CultureId", System.Data.SqlDbType.Int, 0, "CultureId")); SqlCommand sqlInsertCommand = new SqlCommand(); sqlInsertCommand.Connection = symbolAdapter.Connection; sqlInsertCommand.CommandText = @"INSERT INTO Resource([Text], ResourceId, CultureId) VALUES(@Text, @ResourceId, @CultureId) "; sqlInsertCommand.Parameters.Add(new SqlParameter("@Text", System.Data.SqlDbType.NText, 0, "Text")); sqlInsertCommand.Parameters.Add(new SqlParameter("@ResourceId", System.Data.SqlDbType.UniqueIdentifier, 0, "ResourceId")); sqlInsertCommand.Parameters.Add(new SqlParameter("@CultureId", System.Data.SqlDbType.Int, 0, "CultureId")); Guid resourceId = row.Name; DataRow[] rows = this.symbolDetailDataSet.LocalizedSymbolName.Select("", "", DataViewRowState.ModifiedCurrent); foreach (DataRow modifiedRow in rows) { if (modifiedRow.IsNull("ResourceId")) { sqlInsertCommand.Parameters["@Text"].Value = modifiedRow["Name"]; sqlInsertCommand.Parameters["@ResourceId"].Value = resourceId; sqlInsertCommand.Parameters["@CultureId"].Value = modifiedRow["CultureId"]; sqlInsertCommand.ExecuteNonQuery(); } else { sqlUpdateCommand.Parameters["@Text"].Value = modifiedRow["Name"]; sqlUpdateCommand.Parameters["@ResourceId"].Value = resourceId; sqlUpdateCommand.Parameters["@CultureId"].Value = modifiedRow["CultureId"]; sqlUpdateCommand.ExecuteNonQuery(); } } symbolAdapter.Connection.Close(); } } catch (Exception ex) { ReportError(ex.Message.ToString()); this.DialogResult = DialogResult.Cancel; } }