示例#1
0
        private void DeleteButtonClick(object sender, EventArgs e)
        {
            using (var context = new ArchiveContext())
            {
                switch (menuItem)
                {
                case MenuItems.Archive:
                    context.Archives.Remove(context.Archives.ToList()[dataGridView.CurrentCell.RowIndex]);
                    break;

                case MenuItems.Delivery:
                    context.Deliveries.Remove(context.Deliveries.ToList()[dataGridView.CurrentCell.RowIndex]);
                    break;

                case MenuItems.Document:
                    context.Documents.Remove(context.Documents.ToList()[dataGridView.CurrentCell.RowIndex]);
                    break;

                case MenuItems.Subscriber:
                    context.Subscribers.Remove(context.Subscribers.ToList()[dataGridView.CurrentCell.RowIndex]);
                    break;
                }
                context.SaveChanges();
                UpdateButtonClick(null, null);
            }
        }
 private void ButtonClick(object sender, EventArgs e)
 {
     try
     {
         Subscriber subscriber = new Subscriber();
         if (fullnameTextBox.Text.Length > 0 && departmentTextBox.Text.Length > 0 && phoneTextBox.Text.Length > 0)
         {
             subscriber.Department = departmentTextBox.Text;
             subscriber.FullName   = fullnameTextBox.Text;
             subscriber.Phone      = phoneTextBox.Text;
             using (var context = new ArchiveContext())
             {
                 context.Subscribers.Add(subscriber);
                 context.SaveChanges();
             }
             Close();
             return;
         }
         throw new Exception("Данные введены неверно!");
     }
     catch (Exception exception)
     {
         MessageBox.Show("Ошибка!\r\r" + exception.Message);
     }
 }
        private void ButtonClick(object sender, EventArgs e)
        {
            try
            {
                Delivery delivery = new Delivery();

                using (var context = new ArchiveContext())
                {
                    if (subscribersComboBox.SelectedItem != null)
                    {
                        foreach (var subscriber in _subscribers)
                        {
                            if (subscriber.FullName == subscribersComboBox.Text)
                            {
                                delivery.Subscriber = context.Subscribers.Where(subs => subs.FullName == subscriber.FullName).ToList()[0];
                            }
                        }

                        foreach (var document in _documents)
                        {
                            if (document.Name == documentComboBox.Text)
                            {
                                delivery.Document = context.Documents.Where(doc => doc.Name == document.Name).ToList()[0];
                            }
                        }

                        delivery.GettingDate = DateTime.Parse(gettingDateTimePicker.Text);


                        // Вычитание из количества документов
                        int index = -1;
                        foreach (var document in _documents)
                        {
                            if (document.Name == documentComboBox.Name)
                            {
                                break;
                            }
                            index++;
                        }

                        context.Documents.ToList()[index].Amount--;

                        context.Archives.Where(arch => arch.Cell == delivery.Document.Cell).ToList()[0].Fullness = context.Documents.ToList()[index].Amount;


                        context.Deliveries.Add(delivery);
                        context.SaveChanges();
                        Close();
                        return;
                    }
                }
                throw new Exception("Данные введены неверно!");
            }
            catch (Exception exception)
            {
                MessageBox.Show("Ошибка.\r\r" + exception.Message);
            }
        }
 private void ButtonClick(object sender, EventArgs e)
 {
     if (int.TryParse(cellTextBox.Text, out int cell) &&
         int.TryParse(shelfTextBox.Text, out int shelf) &&
         int.TryParse(rackTextBox.Text, out int rack) &&
         cell > 0 && shelf > 0 && rack > 0)
     {
         Archive archive = new Archive
         {
             Cell     = cell,
             Shelf    = shelf,
             Rack     = rack,
             Fullness = 0
         };
         using (var context = new ArchiveContext())
         {
             foreach (var item in context.Archives.ToList())
             {
                 if (!(item.Rack == archive.Rack && item.Shelf == archive.Shelf && item.Cell == archive.Cell))
                 {
                     context.Archives.Add(archive);
                     context.SaveChanges();
                     Close();
                     return;
                 }
                 MessageBox.Show("Данное раположение уже занято!");
                 return;
             }
             // Если context пуст, тогда forech не сработает, в этом случае сробатывает эта команда
             context.Archives.Add(archive);
             context.SaveChanges();
             Close();
             return;
         }
     }
     MessageBox.Show("Данные введены не верно!");
 }
示例#5
0
        private void DataGridViewCellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                switch (menuItem)
                {
                case MenuItems.Archive:
                    switch (dataGridView.CurrentCell.ColumnIndex)
                    {
                    case 0:
                        using (var context = new ArchiveContext())
                        {
                            // Rack
                            if (int.TryParse(dataGridView.CurrentCell.Value.ToString(), out int rack) &&
                                rack > 0 && rack != (context.Archives.ToList())[dataGridView.CurrentCell.RowIndex].Rack)
                            {
                                context.Archives.ToList()[dataGridView.CurrentCell.RowIndex].Rack = rack;
                                context.SaveChanges();
                            }
                            break;
                        }

                    case 1:
                        // Shelf
                        using (var context = new ArchiveContext())
                        {
                            if (int.TryParse(dataGridView.CurrentCell.Value.ToString(), out int shelf) &&
                                shelf > 0 && shelf != (context.Archives.ToList())[dataGridView.CurrentCell.RowIndex].Shelf)
                            {
                                context.Archives.ToList()[dataGridView.CurrentCell.RowIndex].Shelf = shelf;
                                context.SaveChanges();
                            }
                            break;
                        }

                    case 2:
                        //Cell
                        using (var context = new ArchiveContext())
                        {
                            if (int.TryParse(dataGridView.CurrentCell.Value.ToString(), out int cell) &&
                                cell > 0 && cell != (context.Archives.ToList())[dataGridView.CurrentCell.RowIndex].Cell)
                            {
                                context.Archives.ToList()[dataGridView.CurrentCell.RowIndex].Cell = cell;
                                context.SaveChanges();
                            }
                            break;
                        }

                    case 3:
                        //Fullness
                        using (var context = new ArchiveContext())
                        {
                            if (int.TryParse(dataGridView.CurrentCell.Value.ToString(), out int fullness) &&
                                fullness >= 0 && fullness <= 100 && fullness != (context.Archives.ToList())[dataGridView.CurrentCell.RowIndex].Fullness)
                            {
                                context.Archives.ToList()[dataGridView.CurrentCell.RowIndex].Fullness = fullness;
                                context.SaveChanges();
                            }
                            break;
                        }
                    }
                    break;

                case MenuItems.Delivery:
                    switch (dataGridView.CurrentCell.ColumnIndex)
                    {
                    case 0:
                        using (var context = new ArchiveContext())
                        {
                            context.Deliveries.ToList()[dataGridView.CurrentCell.RowIndex].Document.Name = dataGridView.CurrentCell.Value.ToString();
                            context.SaveChanges();
                        }
                        break;

                    case 1:
                        using (var context = new ArchiveContext())
                        {
                            MessageBox.Show("Значение даты выдачи изменять нельзя!");
                            break;
                        }

                    case 2:
                        using (var context = new ArchiveContext())
                        {
                            context.Deliveries.ToList()[dataGridView.CurrentCell.RowIndex].Subscriber.FullName = dataGridView.CurrentCell.Value.ToString();
                            context.SaveChanges();
                        }
                        break;
                    }
                    break;

                case MenuItems.Document:
                    switch (dataGridView.CurrentCell.ColumnIndex)
                    {
                    case 0:
                        using (var context = new ArchiveContext())
                        {
                            // Number
                            if (int.TryParse(dataGridView.CurrentCell.Value.ToString(), out int number) &&
                                number > 0 && number != (context.Documents.ToList())[dataGridView.CurrentCell.RowIndex].Number)
                            {
                                context.Documents.ToList()[dataGridView.CurrentCell.RowIndex].Number = number;
                                context.SaveChanges();
                            }
                            break;
                        }

                    case 1:
                        // Name
                        using (var context = new ArchiveContext())
                        {
                            context.Documents.ToList()[dataGridView.CurrentCell.RowIndex].Name = dataGridView.CurrentCell.Value.ToString();
                            context.SaveChanges();
                        }
                        break;

                    case 2:
                        // Theme
                        using (var context = new ArchiveContext())
                        {
                            context.Documents.ToList()[dataGridView.CurrentCell.RowIndex].Theme = dataGridView.CurrentCell.Value.ToString();
                            context.SaveChanges();
                        }
                        break;

                    case 3:
                        using (var context = new ArchiveContext())
                        {
                            // Cell
                            if (int.TryParse(dataGridView.CurrentCell.Value.ToString(), out int cell) &&
                                cell > 0 && cell != (context.Documents.ToList())[dataGridView.CurrentCell.RowIndex].Cell)
                            {
                                context.Documents.ToList()[dataGridView.CurrentCell.RowIndex].Cell = cell;
                                context.SaveChanges();
                            }
                            break;
                        }

                    case 4:
                        using (var context = new ArchiveContext())
                        {
                            // Amount
                            if (int.TryParse(dataGridView.CurrentCell.Value.ToString(), out int amount) &&
                                amount > 0 && amount != (context.Documents.ToList())[dataGridView.CurrentCell.RowIndex].Amount)
                            {
                                context.Documents.ToList()[dataGridView.CurrentCell.RowIndex].Amount = amount;
                                context.SaveChanges();
                            }
                            break;
                        }

                    case 5:
                        using (var context = new ArchiveContext())
                        {
                            MessageBox.Show("Значение даты изменять нельзя!");
                            UpdateButtonClick(null, null);
                            break;
                        }
                    }
                    break;

                case MenuItems.Subscriber:
                    switch (dataGridView.CurrentCell.ColumnIndex)
                    {
                    case 0:
                        // FullName
                        using (var context = new ArchiveContext())
                        {
                            context.Subscribers.ToList()[dataGridView.CurrentCell.RowIndex].FullName = dataGridView.CurrentCell.Value.ToString();
                            context.SaveChanges();
                        }
                        break;

                    case 1:
                        // Department
                        using (var context = new ArchiveContext())
                        {
                            context.Subscribers.ToList()[dataGridView.CurrentCell.RowIndex].Department = dataGridView.CurrentCell.Value.ToString();
                            context.SaveChanges();
                        }
                        break;

                    case 2:
                        // Phone
                        using (var context = new ArchiveContext())
                        {
                            context.Subscribers.ToList()[dataGridView.CurrentCell.RowIndex].Phone = dataGridView.CurrentCell.Value.ToString();
                            context.SaveChanges();
                        }
                        break;
                    }
                    break;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Возникла ошибка.");
            }

            UpdateButtonClick(null, null);
        }
        private void ButtonClick(object sender, EventArgs e)
        {
            try
            {
                Document document = new Document();
                if (int.TryParse(numberTextBox.Text, out int number) && number > 0 &&
                    nameTextBox.Text.Length > 0 &&
                    themeTextBox.Text.Length > 0 &&
                    int.TryParse(cellTextBox.Text, out int cell) && cell > 0 &&
                    int.TryParse(amountTextBox.Text, out int amount) && amount > 0 &&
                    DateTime.TryParse(receiptDatePicker.Text, out DateTime receiptDate))
                {
                    using (var context = new ArchiveContext())
                    {
                        bool isCellCreated = false;
                        foreach (var archive in context.Archives)
                        {
                            if (archive.Cell == cell)
                            {
                                isCellCreated = true;
                            }
                        }
                        if (!isCellCreated)
                        {
                            MessageBox.Show("Данной ячейки не существует!");
                            return;
                        }
                        foreach (var item in context.Documents.ToList())
                        {
                            if (item.Number == number)
                            {
                                MessageBox.Show("Данный номер документа уже занят!");
                                return;
                            }
                            if (item.Name == nameTextBox.Text)
                            {
                                MessageBox.Show("Данное имя файла уже занято!");
                                return;
                            }
                            if (item.Cell == cell && item.Amount > 0)
                            {
                                MessageBox.Show("Данная ячейка уже занята!");
                                return;
                            }
                        }

                        document.Number = number;
                        document.Name   = nameTextBox.Text;
                        document.Theme  = themeTextBox.Text;
                        document.Cell   = cell;
                        context.Archives.Where(archive => archive.Cell == cell).ToList()[0].Fullness = amount;
                        document.Amount      = amount;
                        document.ReceiptDate = receiptDate;

                        context.Documents.Add(document);
                        context.SaveChanges();
                    }

                    Close();
                    return;
                }
                throw new Exception("Данные введены неверно!");
            }
            catch (Exception exception)
            {
                MessageBox.Show("Возникла ошибка!\r\r" + exception.Message);
            }
        }