Пример #1
0
        private void button_leaser_info_Click(object sender, EventArgs e)
        {
            // выбираем строку
            int PK_LeasingContract = -1;

            try
            {
                PK_LeasingContract = Convert.ToInt32(dataGridView_DataSearch.SelectedRows[0].Cells[0].Value);

                if (PK_LeasingContract == -1)
                {
                    throw new Exception();
                }

                RelationshipOrganizationLeasingContract r_leasingContract = null;
                using (OGMContext db = new OGMContext())
                {
                    r_leasingContract = db.relationships_organization_leasing_contract
                                        .Where(r => r.PK_Role == 2 && r.PK_Leasing_Contract == PK_LeasingContract)
                                        .FirstOrDefault();
                }

                if (r_leasingContract == null)
                {
                    throw new Exception();
                }

                new AddOrganizationForm(r_leasingContract.Organization, true).ShowDialog();
            }
            catch
            {
                MessageBox.Show("Не удалось открыть информацию о лизингодателе", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
Пример #2
0
        private void LeasingViewForm_Load(object sender, EventArgs e)
        {
            // заполнение инфы о договоре
            if (contract == null)
            {
                return;
            }

            ///// то, что хранится непосредственно в таблице договора /////

            // номер и дата
            this.label_LeasingContractNumber.Text += " " + contract.contract_number;
            this.textBox_LeasingNum.Text           = contract.contract_number;
            this.textBox_Date.Text    = DateToString.Translate(this.contract.date, "г.");
            this.textBox_DateEnd.Text = DateToString.Translate(this.contract.date_end, "г.");

            // сроки
            this.numericUpDown_DaysForFirstPayment.Value = contract.days_for_first_payment;
            this.numericUpDown_DaysForReport.Value       = contract.days_for_report;
            this.numericUpDown_DaysForForceMajeure.Value = contract.days_for_force_majeure;

            // ответственность
            this.numericUpDown_Penalty.Value    = contract.penalty;
            this.numericUpDown_MaxPenalty.Value = contract.max_penalty;
            this.numericUpDown_PenaltyFee.Value = contract.penalty_fee;

            // об оборудовании
            this.numericUpDown_PeriodOfUse.Text = contract.period_of_use;
            this.textBox_DateDelivery.Text      = DateToString.Translate(this.contract.date_delivery, "г.");
            this.textBox_AddressDelivery.Text   = contract.address_delivery;

            //// организации подгружаем через поиск связей ////
            ///
            RelationshipOrganizationLeasingContract r_lessee = null;
            RelationshipOrganizationLeasingContract r_seller = null;
            RelationshipOrganizationLeasingContract r_leaser = null;

            using (OGMContext db = new OGMContext())
            {
                r_lessee = db.relationships_organization_leasing_contract.Where(r => r.PK_Leasing_Contract == contract.PK_Leasing_Contract && r.PK_Role == 1).FirstOrDefault();
                r_seller = db.relationships_organization_leasing_contract.Where(r => r.PK_Leasing_Contract == contract.PK_Leasing_Contract && r.PK_Role == 3).FirstOrDefault();
                r_leaser = db.relationships_organization_leasing_contract.Where(r => r.PK_Leasing_Contract == contract.PK_Leasing_Contract && r.PK_Role == 2).FirstOrDefault();
            }

            if (r_lessee != null)
            {
                this.lessee = r_lessee.Organization;
                this.textBox_Lessee.Text = lessee.name;
            }
            if (r_seller != null)
            {
                this.seller = r_seller.Organization;
                this.textBox_Seller.Text = seller.name;
            }
            if (r_leaser != null)
            {
                this.leaser = r_leaser.Organization;
                this.textBox_Leaser.Text = leaser.name;
            }

            GenerateTable();
        }
Пример #3
0
        private bool AddLeasing()
        {
            // проверяем поля на заполненность и корректность ввода
            if (checkFields() == false)
            {
                return(false);
            }

            this.button_Add.Enabled = this.button_AddAndClose.Enabled = false;

            // добавляем в бд договор

            LeasingContract leasingContract = new LeasingContract();

            leasingContract.contract_number        = this.textBox_LeasingNum.Text;
            leasingContract.date                   = this.dateTimePicker_DateConclusion.Value.Date;
            leasingContract.date_end               = this.dateTimePicker_DateEnd.Value.Date;
            leasingContract.date_delivery          = this.dateTimePicker_DateConclusion.Value.Date;
            leasingContract.period_of_use          = this.textBox_PeriodOfUse.Text;
            leasingContract.address_delivery       = this.textBox_AddressDelivery.Text;
            leasingContract.days_for_first_payment = (int)this.numericUpDown_DaysForFirstPayment.Value;
            leasingContract.days_for_report        = (int)this.numericUpDown_DaysForReport.Value;
            leasingContract.penalty                = this.numericUpDown_Penalty.Value;
            leasingContract.max_penalty            = this.numericUpDown_MaxPenalty.Value;
            leasingContract.days_for_force_majeure = (int)this.numericUpDown_DaysForForceMajeure.Value;
            leasingContract.penalty_fee            = this.numericUpDown_DaysForForceMajeure.Value;

            Program.db.LeasingContracts.Add(leasingContract);
            Program.db.SaveChanges();

            // после сохранения изменений нам доступен первичный ключ договора
            // создадим второстепенные таблицы - связь между организацией и договором
            RelationshipOrganizationLeasingContract lessee = new RelationshipOrganizationLeasingContract();
            RelationshipOrganizationLeasingContract seller = new RelationshipOrganizationLeasingContract();
            RelationshipOrganizationLeasingContract leaser = new RelationshipOrganizationLeasingContract();

            lessee.PK_Leasing_Contract = seller.PK_Leasing_Contract = leaser.PK_Leasing_Contract = leasingContract.PK_Leasing_Contract;

            lessee.PK_Organization = ((Organization)this.comboBox_lessee.SelectedItem).PK_Organization;
            lessee.PK_Role         = ((Organization)this.comboBox_lessee.SelectedItem).PK_Role;

            seller.PK_Organization = ((Organization)this.comboBox_Seller.SelectedItem).PK_Organization;
            seller.PK_Role         = ((Organization)this.comboBox_Seller.SelectedItem).PK_Role;

            leaser.PK_Organization = ((Organization)this.comboBox_Leaser.SelectedItem).PK_Organization;
            leaser.PK_Role         = ((Organization)this.comboBox_Leaser.SelectedItem).PK_Role;

            Program.db.relationships_organization_leasing_contract.Add(lessee);
            Program.db.relationships_organization_leasing_contract.Add(seller);
            Program.db.relationships_organization_leasing_contract.Add(leaser);
            Program.db.SaveChanges();

            // далее создадим экземпляры оборудования, приобритённого в лизинг
            int count = 1;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                // 3 ячейка - это кол-во оборудования в строке
                int amount = Convert.ToInt32(row.Cells[3].Value);
                // 2 ячейка - это стоимость за ед.
                decimal cost = Convert.ToDecimal(row.Cells[2].Value);

                // 0 ячейка - это пк_группы оборудования
                int pk_group = Convert.ToInt32(row.Cells[0].Value);
                for (int i = 0; i < amount; i++)
                {
                    // создаём новый экземпляр оборудования
                    Equipment equipment = new Equipment();
                    equipment.name               = row.Cells[1].Value.ToString();
                    equipment.inventory_number   = "ЛИЗ-" + leasingContract.contract_number + "-" + count.ToString();
                    equipment.cost               = this.numericUpDown_Cost.Value;
                    equipment.PK_Equipment_Group = pk_group;
                    equipment.serial_number      = " ";
                    equipment.is_debit           = false;
                    equipment.is_leasing         = true;

                    Program.db.Equipments.Add(equipment);

                    count++;
                }

                RowAttachmentSpecification rowAttachmentSpecification = new RowAttachmentSpecification();
                rowAttachmentSpecification.amount              = amount;
                rowAttachmentSpecification.cost                = cost;
                rowAttachmentSpecification.PK_Equipment_Group  = pk_group;
                rowAttachmentSpecification.PK_Leasing_Contract = leasingContract.PK_Leasing_Contract;

                Program.db.RowsAttachmentSpecification.Add(rowAttachmentSpecification);
            }
            Program.db.SaveChanges();


            MessageBox.Show("Договор за номером " + leasingContract.contract_number + " успешно создан!", "Успех!");

            this.button_Add.Enabled = this.button_AddAndClose.Enabled = true;
            return(true);
        }