private void BtInsert_Click(object sender, EventArgs e)
        {
            string TheBill                = "";
            DataClasses1DataContext DC    = new DataClasses1DataContext();
            MonthlyBill             Abill = new MonthlyBill();
            int rowindex = dgMonthly.CurrentRow.Index;

            TheBill = dgMonthly.Rows[rowindex].Cells[0].Value.ToString();

            Abill.BILL = Convert.ToString(dgMonthly.Rows[rowindex].Cells[0].Value);
            Abill.COST = Convert.ToSingle(dgMonthly.Rows[rowindex].Cells[1].Value);
            Abill.Date = Convert.ToString(dgMonthly.Rows[rowindex].Cells[2].Value);
            DC.SubmitChanges();
            DC.MonthlyBills.InsertOnSubmit(Abill);
            DC.SubmitChanges();
            MessageBox.Show("Saved");
            rowindex = 0;
            Refresh();
        }
        private void BtDelete_Click(object sender, EventArgs e)
        {
            string TheBill                = "";
            DataClasses1DataContext DC    = new DataClasses1DataContext();
            MonthlyBill             Abill = new MonthlyBill();
            int rowindex = dgMonthly.CurrentRow.Index;

            TheBill = dgMonthly.Rows[rowindex].Cells[0].Value.ToString();
            var delete = from b in DC.MonthlyBills
                         where b.BILL == TheBill
                         select b;

            DC.MonthlyBills.DeleteAllOnSubmit(delete);
            DC.SubmitChanges();
            rowindex = 0;
            MessageBox.Show("deleted");
            //Refresh();
            formload();
        }
Esempio n. 3
0
 partial void DeleteMonthlyBill(MonthlyBill instance);
Esempio n. 4
0
 partial void UpdateMonthlyBill(MonthlyBill instance);
Esempio n. 5
0
 partial void InsertMonthlyBill(MonthlyBill instance);
        public void BtnSubmit_Click(object sender, EventArgs e)
        {
            MonthlyBills v = new MonthlyBills();

            string TheBill             = "";
            DataClasses1DataContext DC = new DataClasses1DataContext();
            int newmonthlyrows         = DC.MonthlyBills.Count() + 1;
            int dgrowcount             = dgMonthly.RowCount;

            if (newmonthlyrows == dgrowcount)
            {
                MonthlyBill Abill    = new MonthlyBill();
                int         rowindex = dgMonthly.CurrentRow.Index;
                var         update   = from b in DC.MonthlyBills
                                       select b;
                int monthlybillschanged = 0;
                foreach (var row in update)
                {
                    for (int rowz = 0; rowz < dgMonthly.RowCount - 1; rowz++)
                    {
                        TheBill = dgMonthly.Rows[rowz].Cells[0].Value.ToString();
                        if (TheBill == row.BILL)
                        {
                            if (row.COST != Convert.ToSingle(dgMonthly.Rows[rowz].Cells[1].Value) || row.Date != Convert.ToString(dgMonthly.Rows[rowz].Cells[2].Value))
                            {
                                row.COST = Convert.ToSingle(dgMonthly.Rows[rowz].Cells[1].Value);
                                row.Date = Convert.ToString(dgMonthly.Rows[rowz].Cells[2].Value);
                                monthlybillschanged++;
                            }
                        }
                    }
                }
                if (monthlybillschanged > 0)
                {
                    DC.SubmitChanges();
                    MessageBox.Show($"{monthlybillschanged} monthly bill(s) have been updated");
                }
            }
            else if (newmonthlyrows < dgrowcount)
            {
                var         xc       = dgMonthly.Rows[dgrowcount - 1];
                MonthlyBill Abill    = new MonthlyBill();
                int         rowindex = dgMonthly.CurrentRow.Index;
                TheBill    = dgMonthly.Rows[rowindex].Cells[0].Value.ToString();
                Abill.BILL = Convert.ToString(dgMonthly.Rows[rowindex].Cells[0].Value);
                Abill.COST = Convert.ToSingle(dgMonthly.Rows[rowindex].Cells[1].Value);
                Abill.Date = Convert.ToString(dgMonthly.Rows[rowindex].Cells[2].Value);
                DC.MonthlyBills.InsertOnSubmit(Abill);
                DC.SubmitChanges();
                MessageBox.Show($"{Abill.BILL} added to Monthly Bills");
                Refresh();
            }

            else if (newmonthlyrows > dgrowcount)
            {
                int    found      = 0;
                string DeleteBill = "";
                foreach (var fg in DC.MonthlyBills)
                {
                    found = 0;
                    string BillLookup = fg.BILL;
                    foreach (DataGridViewRow dg in dgMonthly.Rows)
                    {
                        string wwww = Convert.ToString(dg.Cells[0].Value);
                        if (BillLookup == wwww)
                        {
                            found = 1;
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    if (found == 0)
                    {
                        DeleteBill = BillLookup;
                        var delete = from b in DC.MonthlyBills
                                     where b.BILL == DeleteBill
                                     select b;

                        DC.MonthlyBills.DeleteAllOnSubmit(delete);
                        DC.SubmitChanges();
                        MessageBox.Show($"deleted {DeleteBill}");
                        Refresh();
                    }
                }
            }
            float KeyBalanceUpdate;
            DataClasses2DataContext KY = new DataClasses2DataContext();
            KeyBalance KeyB            = new KeyBalance();
            int        rowindexKey     = DatagridKeyBalance.CurrentRow.Index;

            KeyBalanceUpdate = float.Parse(DatagridKeyBalance.Rows[0].Cells[0].Value.ToString());
            KeyBalance BB = KY.KeyBalances
                            .Where(c => c.Placeholder == "X")
                            .Single();

            if (BB.KeyBalance1 != KeyBalanceUpdate)
            {
                BB.DateTime    = DateTime.Now;
                BB.KeyBalance1 = KeyBalanceUpdate;
                KY.SubmitChanges();
                MessageBox.Show("Key Balance Updated");
            }
            string WE = "";
            float  amount;
            DataClasses1DataContext w = new DataClasses1DataContext();
            WeeklyBill we             = new WeeklyBill();
            int        windex         = DataGridWeeklyBIlls.CurrentRow.Index;

            WE     = DataGridWeeklyBIlls.Rows[windex].Cells[0].Value.ToString();
            amount = float.Parse(DataGridWeeklyBIlls.Rows[windex].Cells[1].Value.ToString());
            WeeklyBill wb = w.WeeklyBills
                            .Where(c => c.Bill == WE)
                            .Single();

            if (wb.Cost != amount)
            {
                wb.Cost = amount;
                w.SubmitChanges();
                MessageBox.Show("Weekly BIlls Updated");
            }
            decimal bh;
            string  thename;
            DataClasses1DataContext Bringit = new DataClasses1DataContext();
            BringHomePay            BRHOME  = new BringHomePay();
            int bindex = dgBringHome.CurrentRow.Index;

            thename = dgBringHome.Rows[bindex].Cells[0].Value.ToString();
            bh      = Decimal.Parse(dgBringHome.Rows[bindex].Cells[1].Value.ToString());
            BringHomePay brh = Bringit.BringHomePays
                               .Where(c => c.Name == thename)
                               .Single();

            if (brh.Amount != bh)
            {
                brh.Amount = bh;
                Bringit.SubmitChanges();
                MessageBox.Show("Bring Home Amount Changed");
            }
            formload();
        }