Exemplo n.º 1
0
        public static void AbovePay(int index, int client_id, decimal insertedMoney, decimal change, int month, int state)
        {
            using (PSEntity db = new PSEntity())
            {
                CreatePaymentEntry(index, client_id, insertedMoney);

                switch (state)
                {
                case (int)MoneyStates.NODEBTNOVIRTUALMONEY:
                {
                    MessageBox.Show("проходи");
                    CreateVirtualMoneyEntry(index, client_id, Math.Abs(change));
                    break;
                }


                case (int)MoneyStates.NOVIRTUALMONEY:
                {
                    CreateVirtualMoneyEntry(index, client_id, Math.Abs(change));
                    db.Entry(DebtHandler.GetActiveDebt(DebtHandler.getDebtRecord(index, client_id, month - 1).id)).State = EntityState.Deleted;
                    break;
                }

                case (int)MoneyStates.NODEBTMONEY:
                {
                    var result = db.virtual_money.SingleOrDefault(b => b.client_id == client_id && b.service_id == index + 1);
                    result.money = change;
                    db.SaveChanges();
                    break;
                }

                case (int)MoneyStates.ALLMONEYPRESENT:
                {
                    var result = db.virtual_money.SingleOrDefault(b => b.client_id == client_id && b.service_id == index + 1);
                    result.money = change;
                    db.SaveChanges();

                    db.Entry(DebtHandler.GetActiveDebt(DebtHandler.getDebtRecord(index, client_id, month - 1).id)).State = EntityState.Deleted;


                    break;
                }
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void BelowPay(int index, int client_id, decimal insertedMoney, decimal virtualMoney, decimal debtMoney, int state, decimal totalFee, int month)
        {
            using (PSEntity db = new PSEntity())
            {
                CreatePaymentEntry(index, client_id, insertedMoney);

                switch (state)
                {
                case (int)MoneyStates.NODEBTNOVIRTUALMONEY:
                {
                    MessageBox.Show("проходи");
                    CreateDebtEntry(index, client_id, month, Math.Abs(totalFee - insertedMoney));
                    CreateActiveDebtEntry(DebtHandler.getDebtRecord(index, client_id, month).id, client_id);
                    break;
                }

                case (int)MoneyStates.NOVIRTUALMONEY:
                {
                    CreateDebtEntry(index, client_id, month, Math.Abs(totalFee - insertedMoney - debtMoney));

                    var result = db.active_debts.SingleOrDefault(b => b.id == DebtHandler.getDebtRecord(index, client_id, month - 1).id);

                    result.debt_id = DebtHandler.getDebtRecord(index, client_id, month).id;

                    break;
                }

                case (int)MoneyStates.NODEBTMONEY:
                {
                    db.Entry(getVirtualMoneyForService(index, client_id)).State = EntityState.Deleted;

                    CreateDebtEntry(index, client_id, month, Math.Abs(totalFee - insertedMoney - virtualMoney));

                    CreateActiveDebtEntry(DebtHandler.getDebtRecord(index, client_id, month).id, client_id);
                    break;
                }

                case (int)MoneyStates.ALLMONEYPRESENT:
                {
                    db.Entry(getVirtualMoneyForService(index, client_id)).State = EntityState.Deleted;

                    CreateDebtEntry(index, client_id, month, Math.Abs(totalFee - insertedMoney - debtMoney));

                    var result = db.active_debts.SingleOrDefault(b => b.id == DebtHandler.getDebtRecord(index, client_id, month - 1).id);

                    result.debt_id = DebtHandler.getDebtRecord(index, client_id, month).id;

                    break;
                }
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public static void CreateActiveDebtEntry(int debt_id, int client_id)
        {
            using (PSEntity db = new PSEntity())
            {
                db.active_debts.Add(new active_debts
                {
                    id        = db.active_debts.Count() + 1,
                    client_id = client_id,
                    debt_id   = debt_id
                });

                db.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public static void CreateVirtualMoneyEntry(int index, int client_id, decimal change)
        {
            using (PSEntity db = new PSEntity())
            {
                db.virtual_money.Add(new virtual_money
                {
                    id         = db.service_payments.Count() + 1,
                    client_id  = client_id,
                    service_id = index + 1,
                    money      = change
                });

                db.SaveChanges();
            }
        }
Exemplo n.º 5
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            using (PSEntity db = new PSEntity())
            {
                var clientUserBase = db.client_acc_table;
                var clientDataBase = db.clients_table;


                if (newPassword.Text.Trim() != newPasswordAgain.Text.Trim())
                {
                    MessageService.PasswordMatch();
                    newLogin.Text = newPassword.Text = newPasswordAgain.Text = "";
                }
                else
                {
                    foreach (clients_table item in clientDataBase)
                    {
                        if (Int32.Parse(id.Text.Trim()) == item.client_id)
                        {
                            foreach (client_acc_table userX in clientUserBase)
                            {
                                if (newLogin.Text.Trim() != userX.username)
                                {
                                    db.client_acc_table.Add(new client_acc_table
                                    {
                                        id        = db.client_acc_table.Count() + 1,
                                        username  = newLogin.Text.Trim(),
                                        password  = newPassword.Text.Trim(),
                                        client_id = Int32.Parse(id.Text.Trim())
                                    });
                                    MessageService.SuccsesfulRegister();
                                }
                                else
                                {
                                    MessageService.NameIsNotVacant();
                                }
                            }
                        }
                        else
                        {
                            MessageService.FailedClientIdSearch();
                        }
                    }
                }
                db.SaveChanges();
                id.Text = newLogin.Text = newPassword.Text = newPasswordAgain.Text = "";
            }
        }
Exemplo n.º 6
0
        public static void CreateDebtEntry(int index, int client_id, int month, decimal money)
        {
            using (PSEntity db = new PSEntity())
            {
                db.debt_table.Add(new debt_table
                {
                    id         = db.debt_table.Count() + 1,
                    client_id  = client_id,
                    service_id = index + 1,
                    debt       = money,
                    month_id   = month
                });

                db.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public static void CreatePaymentEntry(int index, int client_id, decimal insertedMoney)
        {
            using (PSEntity db = new PSEntity())
            {
                db.service_payments.Add(new service_payments
                {
                    id         = db.service_payments.Count() + 1,
                    client_id  = client_id,
                    service_id = index + 1,
                    usage      = 100,
                    date       = Misc.GetTodayMonth(),
                    price      = insertedMoney
                });

                db.SaveChanges();
            }
        }
Exemplo n.º 8
0
        public static void CreateServiceMetrics(int index, int client_id, int currMonth)
        {
            metrics_archive prevStateSelector = GetServiceMetricsArchive(index, client_id, currMonth - 1);

            metrics_archive currStateSelector = GetServiceMetricsArchive(index, client_id, currMonth);

            using (PSEntity db = new PSEntity())
            {
                db.service_metrcis.Add(new service_metrcis
                {
                    id           = db.service_metrcis.Count() + 1,
                    service_id   = index + 1,
                    client_id    = client_id,
                    prev_month   = prevStateSelector.usage,
                    curr_month   = currStateSelector.usage,
                    last_checkup = currMonth
                });

                db.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public static void OrdinaryPay(int index, int client_id, decimal insertedMoney, int month, int state)
        {
            using (PSEntity db = new PSEntity())
            {
                CreatePaymentEntry(index, client_id, insertedMoney);

                switch (state)
                {
                case (int)MoneyStates.NODEBTNOVIRTUALMONEY:
                {
                    MessageBox.Show("проходи");
                    break;
                }

                case (int)MoneyStates.NOVIRTUALMONEY:
                {
                    db.Entry(DebtHandler.GetActiveDebt(DebtHandler.getDebtRecord(index, client_id, month - 1).id)).State = EntityState.Deleted;

                    break;
                }

                case (int)MoneyStates.NODEBTMONEY:
                {
                    db.Entry(getVirtualMoneyForService(index, client_id)).State = EntityState.Deleted;
                    break;
                }

                case (int)MoneyStates.ALLMONEYPRESENT:
                {
                    db.Entry(getVirtualMoneyForService(index, client_id)).State = EntityState.Deleted;
                    db.Entry(DebtHandler.GetActiveDebt(DebtHandler.getDebtRecord(index, client_id, month - 1).id)).State = EntityState.Deleted;

                    break;
                }
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 10
0
        private void button14_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("Are you sure?", "Sample text",
                                         MessageBoxButtons.YesNo,
                                         MessageBoxIcon.Question);

            // If the no button was pressed ...
            if (result == DialogResult.Yes)
            {
                foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)

                {
                    int delId        = (int)item.Cells[0].Value;
                    var deleteRecord = db.worker_table.First(b => b.worker_id == delId);    // get the record. will throw exception if not found.
                    db.worker_table.Remove(deleteRecord);

                    db.SaveChanges();

                    dataGridView1.DataSource = db.worker_table.ToList();
                }
            }
        }
Exemplo n.º 11
0
 private void button4_Click_3(object sender, EventArgs e)
 {
     db.SaveChanges();
     MessageService.SuccsesfulChange();
 }