Ejemplo n.º 1
0
        public CategoryDetailForm(SymbolDataSet.LocalizedCategoryRow currentLocalizedCategoryRow)
        {
            InitializeComponent();

            // Set up the SoundPlayer object.
            player = new SoundPlayer();

            if (currentLocalizedCategoryRow.RowState == DataRowState.Added)
            {
                categoryId = 0;

                this.BindingContext[this.categoryDetailDataSet, CATEGORY].AddNew();
                DataRowView rowView = this.BindingContext[this.categoryDetailDataSet, CATEGORY].Current as DataRowView;
                CategoryDetailDataSet.CategoryRow currentCategoryRow = rowView.Row as CategoryDetailDataSet.CategoryRow;

                rowView.BeginEdit();
                currentCategoryRow.Name     = Guid.NewGuid();
                currentCategoryRow.IsActive = true;
                rowView.EndEdit();
            }
            else
            {
                categoryId = currentLocalizedCategoryRow.CategoryId;
            }

            this.categoryDetailDataSet.Merge(currentLocalizedCategoryRow.Table.DataSet.Tables[LOCALIZED_CATEGORY]);

            this.cultureName = Properties.Settings.Default.CultureName;
        }
Ejemplo n.º 2
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            try
            {
                this.BindingContext[this.categoryDetailDataSet, CATEGORY].EndCurrentEdit();
                this.BindingContext[this.categoryDetailDataSet, LOCALIZED_CATEGORY_NAME].EndCurrentEdit();

                DataRowView view = this.BindingContext[categoryDetailDataSet, CATEGORY].Current as DataRowView;
                CategoryDetailDataSet.CategoryRow row = view.Row as CategoryDetailDataSet.CategoryRow;

                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 (CategoryDetailDataSet.LocalizedCategoryNameRow localizedNameRow in this.categoryDetailDataSet.LocalizedCategoryName.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;
                    }
                }

                CategoryDetailDataSet changes = (CategoryDetailDataSet)categoryDetailDataSet.GetChanges();
                if (changes != null)
                {
                    CategoryTableAdapter categoryAdapter = new CategoryTableAdapter();
                    categoryAdapter.Connection.Open();
                    categoryAdapter.Update(changes);

                    SqlCommand sqlUpdateCommand = new SqlCommand();
                    sqlUpdateCommand.Connection  = categoryAdapter.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  = categoryAdapter.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.categoryDetailDataSet.LocalizedCategoryName.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();
                        }
                    }

                    categoryAdapter.Connection.Close();
                }
            }
            catch (Exception ex)
            {
                ReportError(ex.Message.ToString());
                this.DialogResult = DialogResult.Cancel;
            }
        }