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);
     }
 }
Esempio n. 2
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
            {
                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);
            }
        }
 public AddDeliveryForm()
 {
     InitializeComponent();
     using (var context = new ArchiveContext())
     {
         foreach (var subscriber in context.Subscribers.ToList())
         {
             _subscribers.Add(subscriber);
             subscribersComboBox.Items.Add(subscriber.FullName);
         }
         foreach (var document in context.Documents.ToList())
         {
             if (document.Amount > 0)
             {
                 _documents.Add(document);
                 documentComboBox.Items.Add(document.Name);
             }
         }
     }
 }
Esempio n. 5
0
        private void FindEmptyCellButtonClick(object sender, EventArgs e)
        {
            string     result = "Пустые ячейки:\r";
            List <int> cells  = new List <int>();

            using (var context = new ArchiveContext())
            {
                foreach (var archive in context.Archives.ToList())
                {
                    if (archive.Fullness == 0)
                    {
                        cells.Add(archive.Cell);
                    }
                }
            }
            foreach (var cell in cells)
            {
                result += cell + "\r";
            }
            MessageBox.Show(result);
        }
Esempio n. 6
0
 private void FindCellButtonClick(object sender, EventArgs e)
 {
     try
     {
         string documentName = documentNameTextBox.Text;
         using (var context = new ArchiveContext())
         {
             foreach (var document in context.Documents.ToList())
             {
                 if (document.Name == documentName && document.Amount > 0)
                 {
                     MessageBox.Show($"Документ найден. Он находится в ячейке номер {document.Cell}");
                     return;
                 }
             }
             MessageBox.Show("Документ не найден.");
         }
     }
     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("Данные введены не верно!");
 }
Esempio n. 8
0
        private void UpdateButtonClick(object sender, EventArgs e)
        {
            try
            {
                using (var context = new ArchiveContext())
                {
                    dynamic data;
                    switch (menuItem)
                    {
                    case MenuItems.Archive:
                        data = context.Archives.ToList();

                        dataGridView.Columns.Clear();
                        dataGridView.Columns.Add("rackColumn", "Стелаж");
                        dataGridView.Columns.Add("shelfColumn", "Полка");
                        dataGridView.Columns.Add("cellColumn", "Ячейка");
                        dataGridView.Columns.Add("fullnessColumn", "Заполненость");
                        foreach (var archive in data as List <Archive> )
                        {
                            dataGridView.Rows.Add(new object[] { archive.Rack, archive.Shelf, archive.Cell, archive.Fullness });
                        }
                        break;

                    case MenuItems.Delivery:
                        data = context.Deliveries.ToList();

                        dataGridView.Columns.Clear();
                        dataGridView.Columns.Add("documentNameColumn", "Документ");
                        dataGridView.Columns.Add("gettingDateColumn", "Дата выдачи");
                        dataGridView.Columns.Add("subscriverNameColumn", "Абонент");
                        foreach (var delivery in data as List <Delivery> )
                        {
                            dataGridView.Rows.Add(new object[] { delivery.Document.Name, delivery.GettingDate.ToString("dd.MM.yyyy"), delivery.Subscriber.FullName });
                        }

                        break;

                    case MenuItems.Document:
                        data = context.Documents.ToList();

                        dataGridView.Columns.Clear();
                        dataGridView.Columns.Add("numberDocumentColumn", "Номер");
                        dataGridView.Columns.Add("documentNameColumn", "Название");
                        dataGridView.Columns.Add("documentThemeColumn", "Тема");
                        dataGridView.Columns.Add("documentCellColumn", "Ячейка");
                        dataGridView.Columns.Add("amountDocumentColumn", "Количество");
                        dataGridView.Columns.Add("resDateColumn", "Дата поступления");
                        foreach (var document in data as List <Document> )
                        {
                            if (document.Amount > 0)
                            {
                                dataGridView.Rows.Add(new object[] { document.Number, document.Name, document.Theme, document.Cell, document.Amount, document.ReceiptDate.ToString("dd.MM.yyyy") });
                            }
                        }

                        break;

                    case MenuItems.Subscriber:
                        data = context.Subscribers.ToList();

                        dataGridView.Columns.Clear();
                        dataGridView.Columns.Add("fullNameColumn", "ФИО");
                        dataGridView.Columns.Add("departmentColumn", "Отдел");
                        dataGridView.Columns.Add("phoneColumn", "Номер телефона");
                        foreach (var subscriber in data as List <Subscriber> )
                        {
                            dataGridView.Rows.Add(new object[] { subscriber.FullName, subscriber.Department, subscriber.Phone });
                        }
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show($"ERROR: {exception.Message}");
            }
        }
Esempio n. 9
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);
            }
        }