Ejemplo n.º 1
0
 private void FillComboBox2()
 {
     using (PSEntity db = new PSEntity())
     {
         comboBox2.DataSource = db.service_type.ToList();
     }
 }
Ejemplo n.º 2
0
 private void button4_Click_1(object sender, EventArgs e)
 {
     using (PSEntity db = new PSEntity())
     {
         dataGridView2.DataSource = db.service_payments.ToList();
     }
 }
Ejemplo n.º 3
0
 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (PSEntity db = new PSEntity())
     {
         dataGridView2.DataSource = db.service_payments.Where(x => x.service_id == comboBox2.SelectedIndex + 1).ToList();
     }
 }
Ejemplo n.º 4
0
 public static debt_table getDebtRecordById(int id)
 {
     using (PSEntity db = new PSEntity())
     {
         var result = db.debt_table.SingleOrDefault(b => b.id == id);
         return(result);
     }
 }
Ejemplo n.º 5
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (PSEntity db = new PSEntity())
     {
         var tarifQuery = from o in db.service_type
                          select o;
         dataGridView1.DataSource = tarifQuery.ToList();
     }
 }
Ejemplo n.º 6
0
        public static active_debts GetActiveDebt(int debt_id)
        {
            using (PSEntity db = new PSEntity())
            {
                var result = db.active_debts.SingleOrDefault(b => b.debt_id == debt_id);



                return(result);
            }
        }
Ejemplo n.º 7
0
        public static debt_table getDebtRecord(int index, int client_id, int month)
        {
            using (PSEntity db = new PSEntity())
            {
                var debtRecord = db.debt_table.SingleOrDefault(dr => (dr.service_id == index + 1) &&
                                                               (dr.client_id == client_id) &&
                                                               (dr.month_id == month));

                return(debtRecord);
            }
        }
Ejemplo n.º 8
0
        public static service_type getSelectedService(int index)
        {
            using (PSEntity db = new PSEntity())
            {
                var serviceType = from st in db.service_type
                                  where st.service_id == index + 1
                                  select st;

                return(serviceType.FirstOrDefault <service_type>());
            }
        }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
0
        public static virtual_money getVirtualMoneyForService(int index, int client_id)
        {
            using (PSEntity db = new PSEntity())
            {
                var virtualMoney = from vm in db.virtual_money
                                   where (vm.service_id == index + 1) &&
                                   (vm.client_id == client_id)
                                   select vm;

                return(virtualMoney.FirstOrDefault <virtual_money>());
            }
        }
Ejemplo n.º 11
0
        public static metrics_archive GetServiceMetricsArchive(int index, int client_id, int months)
        {
            using (PSEntity db = new PSEntity())
            {
                var selector = from pm in db.metrics_archive
                               where (pm.month_id == months) &&
                               (pm.service_id == index + 1) &&
                               (pm.client_id == client_id)
                               select pm;

                return(selector.FirstOrDefault <metrics_archive>());
            }
        }
Ejemplo n.º 12
0
        public static service_metrcis getSelectedServiceMetrics(int index, int client_id, int month)
        {
            using (PSEntity db = new PSEntity())
            {
                var servicesMetrics = from sc in db.service_metrcis
                                      where (sc.client_id == client_id) &&
                                      (sc.service_id == index + 1) &&
                                      (sc.last_checkup == month)
                                      select sc;

                return(servicesMetrics.FirstOrDefault <service_metrcis>());
            }
        }
Ejemplo n.º 13
0
        public static List <active_debts> getActiveDebtRecods(int client_id)
        {
            using (PSEntity db = new PSEntity())
            {
                var result = db.active_debts.Where(b => b.client_id == client_id).Select(b => new { b.id, b.debt_id, b.client_id }).ToList()
                             .Select(b => new active_debts()
                {
                    id = b.id, client_id = client_id, debt_id = b.debt_id
                }).ToList();


                return(result);
            }
        }
Ejemplo n.º 14
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();
            }
        }
Ejemplo n.º 15
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();
            }
        }
Ejemplo n.º 16
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 = "";
            }
        }
Ejemplo n.º 17
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();
            }
        }
Ejemplo n.º 18
0
 private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (chart1.Series[0].Points != null)
     {
         chart1.Series[0].Points.Clear();
     }
     using (PSEntity db = new PSEntity())
     {
         var dataCChart = db.metrics_archive.Where(x => x.service_id == comboBox2.SelectedIndex + 1 && x.client_id == user.client_id).ToList();
         dataGridView1.DataSource = dataCChart;
         foreach (var item in dataCChart)
         {
             chart1.Series[0].Points.Add((double)item.usage);
         }
     }
 }
Ejemplo n.º 19
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();
            }
        }
Ejemplo n.º 20
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();
            }
        }
Ejemplo n.º 21
0
        private void FillDataGrid3()
        {
            using (PSEntity db = new PSEntity())
            {
                var data = (from a in db.active_debts
                            join b in db.debt_table.Where(b => b.client_id == user.client_id) on a.debt_id equals b.id
                            join c in db.service_type on b.service_id equals c.service_id
                            join d in db.months_2020_table on b.month_id equals d.month_id
                            select new ActiveDebtsView
                {
                    Debt_id = b.id,
                    Client_id = (int)b.client_id,
                    Service_id = c.name,
                    Debt = (decimal)b.debt,
                    Month_id = d.name
                }).ToList();


                dataGridView3.DataSource = data;
            }
        }
Ejemplo n.º 22
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();
            }
        }
Ejemplo n.º 23
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();
            }
        }
Ejemplo n.º 24
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            //sumbit
            using (PSEntity db = new PSEntity())
            {
                var clients    = db.client_acc_table;
                var clientInfo = db.clients_table;
                var workerInfo = db.worker_table;
                var workers    = db.staff_acc_table;

                foreach (client_acc_table item in clients)
                {
                    if (LoginText.Text.Trim() == item.username && PasswordText.Text.Trim() == item.password)
                    {
                        foreach (clients_table cli3nt in clientInfo)
                        {
                            if (item.client_id == cli3nt.client_id)
                            {
                                client = cli3nt;
                            }
                        }

                        MessageService.SuccsesfulLogin();

                        MainFormClient mainFormClient = new MainFormClient(client);
                        this.Hide();
                        mainFormClient.Show();
                    }
                }

                foreach (staff_acc_table item in workers)
                {
                    if (LoginText.Text.Trim() == item.username && PasswordText.Text.Trim() == item.password)
                    {
                        foreach (worker_table work3r in workerInfo)
                        {
                            if (work3r.worker_id == item.worker_id)
                            {
                                switch (item.role_id)
                                {
                                case 1:
                                {
                                    MessageService.SuccsesfulLogin();
                                    this.Hide();
                                    MainFormDir MainFormEconom = new MainFormDir(work3r);
                                    MainFormEconom.Show();
                                    break;
                                }

                                case 2:
                                {
                                    MessageService.SuccsesfulLogin();
                                    this.Hide();
                                    MainFormEconom MainFormEconom = new MainFormEconom(work3r);
                                    MainFormEconom.Show();
                                    break;
                                }

                                case 3:
                                {
                                    MessageService.SuccsesfulLogin();
                                    this.Hide();
                                    MainFormHH MainFormEconom = new MainFormHH(work3r);
                                    MainFormEconom.Show();
                                    break;
                                }

                                case 4:
                                {
                                    MessageService.SuccsesfulLogin();
                                    this.Hide();
                                    MainFormAcc mainForm = new MainFormAcc(work3r);
                                    this.Hide();
                                    mainForm.Show();
                                    break;
                                }
                                }
                            }
                        }
                    }
                }

                if (client == null && worker == null)
                {
                    MessageService.FailedLogin();
                    Login.Text = PasswordText.Text = "";
                }
            }
        }