Exemplo n.º 1
0
        public DebitViewForm(ActDebit actDebit)
        {
            InitializeComponent();

            this.DoubleBuffered = true;
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            // сохраняем текущий акт списания в переменную формы
            ActDebit = actDebit;

            // выводим лейбл формы
            label_ActDebitNum.Text = "Акт списания оборудования №" + ActDebit.act_number;


            // выбрать все строки акта списания из БД
            debitEquipments = ActDebit.GetDebitEquipments();

            UpdateTable();
            textBox_ActNumber.Text       = ActDebit.act_number;
            dateTimePicker_ActDate.Value = ActDebit.date;
            textBox_ActTotalPrice.Text   = ActDebitTotalCost.ToString();

            comboBox_Organization.DataSource    = Program.db.Organizations.Where(b => b.PK_Role == 1).ToList();
            comboBox_Organization.SelectedIndex = -1;
            comboBox_Organization.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        }
Exemplo n.º 2
0
        private bool AddActDebit()
        {
            try {
                // проверка на заполнение
                if (String.IsNullOrWhiteSpace(textBox_ActNumber.Text))
                {
                    MessageBox.Show("Номер акта не указан!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(false);
                }

                if (dataGridView_Debit.Rows.Count < 1)
                {
                    MessageBox.Show("Не выбрано оборудование для списания!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(false);
                }

                ActDebit actDebit = new ActDebit {
                    act_number = textBox_ActNumber.Text,
                    date       = dateTimePicker_DateDebit.Value.Date
                };

                Program.db.ActDebits.Add(actDebit);
                Program.db.SaveChanges();

                int PK = actDebit.PK_Aсt_Debit;

                List <DebitEquipment> debits = new List <DebitEquipment>();

                foreach (DataGridViewRow row in dataGridView_Debit.Rows)
                {
                    debits.Add(new DebitEquipment {
                        inventory_number   = row.Cells[4].Value.ToString(),
                        PK_Reason_Debit    = ((ReasonDebit)row.Cells[7].Value).PK_Reason_Debit,
                        PK_Aсt_Debit       = PK,
                        PK_Equipment_Group = ((EquipmentGroup)row.Cells[2].Value).PK_Equipment_Group,
                        name = row.Cells[5].Value.ToString(),
                        cost = (decimal)row.Cells[6].Value
                    });

                    Program.db.Equipments.Find(Convert.ToInt32(row.Cells[3].Value)).is_debit = true;
                }

                Program.db.DebitEquipments.AddRange(debits);
                Program.db.SaveChanges();

                MessageBox.Show("Акт списания оборудования № " + actDebit.act_number + " успешно создан!", "Успех!");
                return(true);
            }
            catch (Exception e) {
                MessageBox.Show(e.Message);
                return(false);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        private void dataGridView_DataSearch_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }

            // если нажали на ссылку в 4 столбце
            if (e.ColumnIndex == 4)
            {
                // берем первичный ключ акта в скрытом столбце (столбец 1)
                int      PK_ActDebit = Convert.ToInt32(dataGridView_DataSearch[1, e.RowIndex].Value);
                ActDebit actDebit    = Program.db.ActDebits.Find(PK_ActDebit);
                if (actDebit != null)
                {
                    new DebitViewForm(actDebit).ShowDialog();
                }
            }
        }