示例#1
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (GlobalInfo.currentUser.Rule.LevelAccess != "менеджер")
                {
                    MessageBox.Show("У вас недостатньо прав, щоб здійснити дану операцію!");
                    return;
                }
                var newShopForm = new NewShopForm();

                do
                {
                    DialogResult result = newShopForm.ShowDialog(this);
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (newShopForm.CityTextBox.Text.Trim() == "" ||
                        newShopForm.CountryTextBox.Text.Trim() == "" ||
                        newShopForm.StreetTextBox.Text.Trim() == "" ||
                        newShopForm.NumOfStreetTextBox.Text.Trim() == "")
                    {
                        MessageBox.Show("Усі поля повинні бути заповнені!");
                        continue;
                    }
                    else
                    {
                        break;
                    }
                } while (true);

                Location newLocation = new Location();
                newLocation.Country     = newShopForm.CountryTextBox.Text;
                newLocation.City        = newShopForm.CityTextBox.Text;
                newLocation.Street      = newShopForm.StreetTextBox.Text;
                newLocation.NumOfStreet = newShopForm.NumOfStreetTextBox.Text;

                db.data.Locations.Add(newLocation);
                db.data.SaveChanges();

                Store newStore = new Store();
                newStore.TotalProductCost = 0;
                newStore.ObjectId         = db.data.Locations.Max(l => l.ObjectId);

                db.data.Stores.Add(newStore);
                db.data.SaveChanges();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Some error occured: " + exception.Message + " - " + exception.Source);
                throw;
            }
        }
示例#2
0
        private void AlertBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (GlobalInfo.currentUser.Rule.LevelAccess != "менеджер")
                {
                    MessageBox.Show("У вас недостатньо прав, щоб здійснити дану операцію!");
                    return;
                }

                if (dataGridView1.SelectedRows.Count > 0)
                {
                    int  index     = dataGridView1.SelectedRows[0].Index;
                    int  id        = 0;
                    bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);

                    if (!converted)
                    {
                        return;
                    }

                    Location newLocation = db.data.Locations.Find(id);
                    var      newShopForm = new NewShopForm();

                    newShopForm.CountryTextBox.Text     = newLocation.Country;
                    newShopForm.CityTextBox.Text        = newLocation.City;
                    newShopForm.StreetTextBox.Text      = newLocation.Street;
                    newShopForm.NumOfStreetTextBox.Text = newLocation.NumOfStreet;

                    do
                    {
                        DialogResult result = newShopForm.ShowDialog(this);
                        if (result == DialogResult.Cancel)
                        {
                            return;
                        }

                        if (newShopForm.CityTextBox.Text.Trim() == "" ||
                            newShopForm.CountryTextBox.Text.Trim() == "" ||
                            newShopForm.StreetTextBox.Text.Trim() == "" ||
                            newShopForm.NumOfStreetTextBox.Text.Trim() == "")
                        {
                            MessageBox.Show("Усі поля повинні бути заповнені!");
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    } while (true);

                    newLocation.Country     = newShopForm.CountryTextBox.Text;
                    newLocation.City        = newShopForm.CityTextBox.Text;
                    newLocation.Street      = newShopForm.StreetTextBox.Text;
                    newLocation.NumOfStreet = newShopForm.NumOfStreetTextBox.Text;

                    db.data.Entry(newLocation).State = EntityState.Modified;
                    db.data.SaveChanges();
                    dataGridView1.Refresh();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Some error occured: " + exception.Message + " - " + exception.Source);
                throw;
            }
        }