public LeasingViewForm(LeasingContract leasingContract = null) { InitializeComponent(); this.DoubleBuffered = true; SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // удаляю стрелочки для numeric numericUpDown_DaysForFirstPayment.Controls.RemoveAt(0); numericUpDown_DaysForForceMajeure.Controls.RemoveAt(0); numericUpDown_DaysForReport.Controls.RemoveAt(0); numericUpDown_MaxPenalty.Controls.RemoveAt(0); numericUpDown_Penalty.Controls.RemoveAt(0); numericUpDown_PenaltyFee.Controls.RemoveAt(0); numericUpDown_PeriodOfUse.Controls.RemoveAt(0); // устанавливаю цвет для readonly полей this.textBox_AddressDelivery.BackColor = this.textBox_LeasingNum.BackColor = Color.White; this.textBox_AddressDelivery.ForeColor = this.textBox_LeasingNum.ForeColor = Color.Black; this.textBox_Date.BackColor = this.textBox_DateEnd.BackColor = this.textBox_DateDelivery.BackColor = Color.White; this.textBox_Date.ForeColor = this.textBox_DateEnd.ForeColor = this.textBox_DateDelivery.ForeColor = Color.Black; numericUpDown_DaysForFirstPayment.BackColor = Color.White; numericUpDown_DaysForForceMajeure.BackColor = Color.White; numericUpDown_DaysForReport.BackColor = Color.White; numericUpDown_MaxPenalty.BackColor = Color.White; numericUpDown_Penalty.BackColor = Color.White; numericUpDown_PenaltyFee.BackColor = Color.White; numericUpDown_PeriodOfUse.BackColor = Color.White; textBox_Leaser.BackColor = Color.White; textBox_Lessee.BackColor = Color.White; textBox_Seller.BackColor = Color.White; numericUpDown_DaysForFirstPayment.ForeColor = Color.Black; numericUpDown_DaysForForceMajeure.ForeColor = Color.Black; numericUpDown_DaysForReport.ForeColor = Color.Black; numericUpDown_MaxPenalty.ForeColor = Color.Black; numericUpDown_Penalty.ForeColor = Color.Black; numericUpDown_PenaltyFee.ForeColor = Color.Black; numericUpDown_PeriodOfUse.ForeColor = Color.Black; textBox_Leaser.ForeColor = Color.Black; textBox_Lessee.ForeColor = Color.Black; textBox_Seller.ForeColor = Color.Black; // сохраняю ссылку на договор contract = leasingContract; }
private void button_show_act_contract_Click(object sender, EventArgs e) { try { int PK_Equipment = Convert.ToInt32(this.dataGridView.SelectedRows[0].Cells[0].Value); Equipment equipment = null; using (OGMContext db = new OGMContext()) { equipment = db.Equipments.Find(PK_Equipment); } if (equipment == null) { throw new Exception(); } if (this.button_show_act_contract.Text == "Перейти к акту") { ActDebit actDebit = null; using (OGMContext db = new OGMContext()) { actDebit = db.ActDebits.Find(equipment.PK_Debit); } if (actDebit == null) { throw new Exception(); } new DebitViewForm(actDebit).ShowDialog(); } else if (this.button_show_act_contract.Text == "Перейти к договору") { LeasingContract leasingContract = null; using (OGMContext db = new OGMContext()) { leasingContract = db.LeasingContracts.Find(equipment.PK_Leasing); } if (leasingContract == null) { throw new Exception(); } new LeasingViewForm(leasingContract).ShowDialog(); } } catch { MessageBox.Show("Не удалось перейти к документу", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void dataGridView_DataSearch_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } if (e.ColumnIndex == 5) { int PK_Leasing_Contract = Convert.ToInt32(this.dataGridView_DataSearch.Rows[e.RowIndex].Cells[0].Value); LeasingContract leasingContract = Program.db.LeasingContracts.Find(PK_Leasing_Contract); if (leasingContract != null) { new LeasingViewForm(leasingContract).ShowDialog(); } } }
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); }