void Loading()
 {
     using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
     {
         data_grid.DataSource = db.PRODUCTs.ToList();
     }
 }
 void Loading()
 {
     using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
     {
         bunifuCustomDataGrid1.DataSource = db.PRODUCTs.ToList();
     }
 }
        private void btn_delete_Click(object sender, EventArgs e)
        {
            if (!add)
            {
                using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                {
                    try
                    {
                        int index = bunifuCustomDataGrid1.CurrentRow.Index;
                        index = int.Parse(bunifuCustomDataGrid1.Rows[index].Cells[0].Value.ToString());

                        PRODUCT prdct = db.PRODUCTs.SingleOrDefault(x => x.ID == index);
                        db.PRODUCTs.DeleteOnSubmit(prdct);
                        db.SubmitChanges();
                        notifyIcon1.Visible         = true;
                        notifyIcon1.Icon            = SystemIcons.Exclamation;
                        notifyIcon1.BalloonTipTitle = "Delete Successful";
                        notifyIcon1.BalloonTipText  = "Your product has been deleted in Database!";
                        notifyIcon1.BalloonTipIcon  = ToolTipIcon.Info;
                        notifyIcon1.ShowBalloonTip(1000);
                    }
                    catch
                    {
                        notifyIcon1.Visible         = true;
                        notifyIcon1.Icon            = SystemIcons.Exclamation;
                        notifyIcon1.BalloonTipTitle = "Can't Delete new Product to Database";
                        notifyIcon1.BalloonTipText  = "Check your id is Valid!";
                        notifyIcon1.BalloonTipIcon  = ToolTipIcon.Error;
                        notifyIcon1.ShowBalloonTip(1000);
                    }
                }
                Loading();
                bunifuCustomDataGrid1.DataSource = Loaded_Record(page_number, number_record);
            }
        }
 void Loading()
 {
     using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
     {
         bunifuCustomDataGrid1.DataSource = db.PRODUCTs.ToList();
         txt_bill.Text = (db.BILLs.Count() + 1).ToString();
     }
 }
 public void UC_Dashboard_Load(object sender, EventArgs e)
 {
     using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
     {
         lbl_product.Text  = db.PRODUCTs.Count().ToString();
         lbl_producer.Text = db.GETPRODUCER().Count().ToString();
         lbl_invoice.Text  = db.BILLs.Count().ToString();
     }
 }
        public List <BILL> Loaded_Record(int page, int recordNum)
        {
            List <BILL> resulf = new List <BILL>();

            using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
            {
                resulf = db.BILLs.Skip((page - 1) * recordNum).Take(recordNum).ToList();
            }
            return(resulf);
        }
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            NumericUpDown num         = sender as NumericUpDown;
            int           totalrecord = 0;

            using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
            {
                totalrecord = db.BILLs.Count();
            }
            num.Maximum          = totalrecord / number_record + 1;
            page_number          = (int)num.Value;
            data_grid.DataSource = Loaded_Record(page_number, number_record);
        }
 private void radiobtn_product_CheckedChanged(object sender, EventArgs e)
 {
     dropdown_producer.Enabled = true;
     using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
     {
         dropdown_producer.Clear();
         var temp = db.GETPRODUCER().ToList();
         foreach (var i in temp)
         {
             dropdown_producer.AddItem(i.PRODUCER);
         }
     }
 }
 private void bunifuFlatButton4_Click(object sender, EventArgs e)
 {
     try
     {
         using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
         {
             var rs = db.BILLs.Where(q => q.NAME_PRODUCT.Contains(txt_search.Text)).ToList();
             data_grid.DataSource = rs;
         }
     }
     catch
     {
     }
 }
        private void btn_update_Click(object sender, EventArgs e)
        {
            if (!add)
            {
                using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                {
                    try
                    {
                        PRODUCT prodct = new PRODUCT
                        {
                            ID             = int.Parse(txt_id.Text),
                            NAME           = txt_name.Text,
                            CATEGORY       = txt_category.Text,
                            PRODUCER       = txt_producer.Text,
                            PURCHASE_PRICE = int.Parse(txt_purchase.Text),
                            PRICE          = int.Parse(txt_price.Text),
                            INVENTORY      = int.Parse(txt_inventory.Text),
                        };
                        PRODUCT temp = db.PRODUCTs.SingleOrDefault(x => x.ID == prodct.ID);
                        temp.ID             = int.Parse(txt_id.Text);
                        temp.NAME           = txt_name.Text;
                        temp.CATEGORY       = txt_category.Text;
                        temp.PRODUCER       = txt_producer.Text;
                        temp.PURCHASE_PRICE = int.Parse(txt_purchase.Text);
                        temp.PRICE          = int.Parse(txt_price.Text);
                        temp.INVENTORY      = int.Parse(txt_inventory.Text);

                        db.SubmitChanges();

                        notifyIcon1.Visible         = true;
                        notifyIcon1.Icon            = SystemIcons.Exclamation;
                        notifyIcon1.BalloonTipTitle = "Update Successful!";
                        notifyIcon1.BalloonTipText  = "Your product has been updated in Database!";
                        notifyIcon1.BalloonTipIcon  = ToolTipIcon.Info;
                        notifyIcon1.ShowBalloonTip(1000);
                    }
                    catch
                    {
                        notifyIcon1.Visible         = true;
                        notifyIcon1.Icon            = SystemIcons.Exclamation;
                        notifyIcon1.BalloonTipTitle = "Can't Delete new Product to Database";
                        notifyIcon1.BalloonTipText  = "Check your id is Valid!";
                        notifyIcon1.BalloonTipIcon  = ToolTipIcon.Error;
                        notifyIcon1.ShowBalloonTip(1000);
                    }
                }
                Loading();
                bunifuCustomDataGrid1.DataSource = Loaded_Record(page_number, number_record);
            }
        }
 private void txt_search_KeyPress(object sender, KeyPressEventArgs e)
 {
     try
     {
         using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
         {
             if (e.KeyChar == (char)13)
             {
                 var rs = db.BILLs.Where(q => q.NAME_PRODUCT.Contains(txt_search.Text)).ToList();
                 data_grid.DataSource = rs;
             }
         }
     }
     catch
     {
     }
 }
        private void bunifuFlatButton2_Click(object sender, EventArgs e)
        {
            if (db_excel == null)
            {
                Loading();
                bunifuCustomDataGrid1.DataSource = Loaded_Record(page_number, number_record);
            }
            else
            {
                try
                {
                    int totalrecord;
                    using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                    {
                        totalrecord = db.PRODUCTs.Count();

                        int temp = db.PRODUCTs.OrderByDescending(x => x.ID).First().ID;
                        if (temp <= totalrecord)
                        {
                            temp = totalrecord;
                        }
                        for (int i = 0; i < db_excel.Count; i++)
                        {
                            db_excel[i].ID = db_excel[i].ID + temp;
                            totalrecord    = db.PRODUCTs.Count();
                            db.PRODUCTs.InsertOnSubmit(db_excel[i]);
                            db.SubmitChanges();
                        }


                        bunifuCustomDataGrid1.DataSource = Loaded_Record(page_number, number_record);
                    }
                }
                catch
                {
                    notifyIcon1.Visible         = true;
                    notifyIcon1.Icon            = SystemIcons.Exclamation;
                    notifyIcon1.BalloonTipTitle = "Can't Add new Product to Database";
                    notifyIcon1.BalloonTipText  = "Check your input is Valid!";
                    notifyIcon1.BalloonTipIcon  = ToolTipIcon.Error;
                    notifyIcon1.ShowBalloonTip(1000);
                }
            }
            txt_search.Text = "";
        }
 private void btn_add_Click(object sender, EventArgs e)
 {
     if (add)
     {
         using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
         {
             try
             {
                 PRODUCT prodct = new PRODUCT
                 {
                     ID             = int.Parse(txt_id.Text),
                     NAME           = txt_name.Text,
                     CATEGORY       = txt_category.Text,
                     PRODUCER       = txt_producer.Text,
                     PURCHASE_PRICE = int.Parse(txt_purchase.Text),
                     PRICE          = int.Parse(txt_price.Text),
                     INVENTORY      = int.Parse(txt_inventory.Text),
                 };
                 db.PRODUCTs.InsertOnSubmit(prodct);
                 db.SubmitChanges();
                 notifyIcon1.Visible         = true;
                 notifyIcon1.Icon            = SystemIcons.Exclamation;
                 notifyIcon1.BalloonTipTitle = "Add Successfull!";
                 notifyIcon1.BalloonTipText  = "Your product is added in Database!";
                 notifyIcon1.BalloonTipIcon  = ToolTipIcon.Info;
                 notifyIcon1.ShowBalloonTip(1000);
             }
             catch
             {
                 notifyIcon1.Visible         = true;
                 notifyIcon1.Icon            = SystemIcons.Exclamation;
                 notifyIcon1.BalloonTipTitle = "Can't Add new Product to Database";
                 notifyIcon1.BalloonTipText  = "Check your input is Valid!";
                 notifyIcon1.BalloonTipIcon  = ToolTipIcon.Error;
                 notifyIcon1.ShowBalloonTip(1000);
             }
         }
         Loading();
         bunifuCustomDataGrid1.DataSource = Loaded_Record(page_number, number_record);
     }
 }
 private void btn_printbill_Click(object sender, EventArgs e)
 {
     try
     {
         if (txt_namecustomer.Text != "")
         {
             using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
             {
                 bool type_pay;
                 if (bunifuDropdown1.selectedIndex != 1)
                 {
                     type_pay = false;
                 }
                 else
                 {
                     type_pay = true;
                 }
                 BILL bil = new BILL
                 {
                     ID_BILL       = int.Parse(txt_bill.Text),
                     ID_PRODUCT    = int.Parse(txt_id.Text),
                     NAME_CUSTOMER = txt_namecustomer.Text,
                     NAME_PRODUCT  = txt_name.Text,
                     PRODUCER      = txt_category.Text,
                     PRICE         = int.Parse(txt_price.Text),
                     AMOUNT        = Convert.ToInt32(numericUpDown1.Value),
                     DATE_TIME     = bunifuDatepicker1.Value,
                     ADVANCE       = int.Parse(txt_price.Text),
                     TYPE_PAY      = bunifuDropdown1.selectedValue,
                     TOTAL         = int.Parse(txt_total.Text),
                     TRANGTHAI     = type_pay,
                 };
                 PRODUCT temp = db.PRODUCTs.SingleOrDefault(x => x.ID == bil.ID_PRODUCT);
                 temp.INVENTORY--;
                 if (temp.INVENTORY < 0)
                 {
                     notifyIcon1.Visible         = true;
                     notifyIcon1.Icon            = SystemIcons.Exclamation;
                     notifyIcon1.BalloonTipTitle = "Don't have any product in Inventory";
                     notifyIcon1.BalloonTipText  = "Please choose another Product, this Product is sold out!";
                     notifyIcon1.BalloonTipIcon  = ToolTipIcon.Error;
                     notifyIcon1.ShowBalloonTip(1000);
                 }
                 else
                 {
                     db.BILLs.InsertOnSubmit(bil);
                     db.SubmitChanges();
                     notifyIcon1.Visible         = true;
                     notifyIcon1.Icon            = SystemIcons.Exclamation;
                     notifyIcon1.BalloonTipTitle = "Add Successfull!";
                     notifyIcon1.BalloonTipText  = "Your Bill is added in Database!";
                     notifyIcon1.BalloonTipIcon  = ToolTipIcon.Info;
                     notifyIcon1.ShowBalloonTip(1000);
                     bunifuFlatButton2_Click(sender, e);
                 }
             };
         }
     }
     catch
     {
         notifyIcon1.Visible         = true;
         notifyIcon1.Icon            = SystemIcons.Exclamation;
         notifyIcon1.BalloonTipTitle = "Can't Add new Bill to Database";
         notifyIcon1.BalloonTipText  = "Check your input is Valid!";
         notifyIcon1.BalloonTipIcon  = ToolTipIcon.Error;
         notifyIcon1.ShowBalloonTip(1000);
     }
 }
 private void btn_loadChart_Click(object sender, EventArgs e)
 {
     //Clear Biểu đồ
     foreach (var series in chart1.Series)
     {
         series.Points.Clear();
     }
     //Xử lý đọc doanh số từ NSX
     if (radiobtn_producer.Checked)
     {
         if (radiobtn_time.Checked)
         {
             if (dropdown_type.selectedValue == "Day")
             {
                 using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                 {
                     var temp = db.GETPRODUCERBYDAY(bunifuDatepicker1.Value.Date).ToList();
                     foreach (var i in temp)
                     {
                         chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total);
                     }
                 }
             }
             else if (dropdown_type.selectedValue == "Month")
             {
                 using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                 {
                     var temp = db.GETPRODUCERBYMONTH(bunifuDatepicker1.Value.Date.Month.ToString(), bunifuDatepicker1.Value.Date.Year.ToString()).ToList();
                     foreach (var i in temp)
                     {
                         chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total);
                     }
                 }
             }
             else
             {
                 using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                 {
                     var temp = db.GETPRODUCERBYYEAR(bunifuDatepicker1.Value.Date.Year.ToString()).ToList();
                     foreach (var i in temp)
                     {
                         chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total);
                     }
                 }
             }
         }
         else
         {
             using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
             {
                 var temp = db.GETPRODUCERBY2DAYS(bunifuDatepicker3.Value.Date, bunifuDatepicker2.Value.Date).ToList();
                 foreach (var i in temp)
                 {
                     chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total);
                 }
             }
         }
     }
     //Xử lý đọc sản phẩm từ NSX
     else
     {
         if (radiobtn_time.Checked)
         {
             if (dropdown_type.selectedValue == "Day")
             {
                 using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                 {
                     var temp = db.GETPRODUCTBYDAY(bunifuDatepicker1.Value.Date, dropdown_producer.selectedValue).ToList();
                     foreach (var i in temp)
                     {
                         chart1.Series["Value"].Points.AddXY(i.NAME_PRODUCT, i.Total);
                     }
                 }
             }
             else if (dropdown_type.selectedValue == "Month")
             {
                 using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                 {
                     var temp = db.GETPRODUCTBYMONTH(bunifuDatepicker1.Value.Date.Month.ToString(), bunifuDatepicker1.Value.Date.Year.ToString(), dropdown_producer.selectedValue).ToList();
                     foreach (var i in temp)
                     {
                         chart1.Series["Value"].Points.AddXY(i.NAME_PRODUCT, i.Total);
                     }
                 }
             }
             else
             {
                 using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
                 {
                     var temp = db.GETPRODUCTBYYEAR(bunifuDatepicker1.Value.Date.Year.ToString(), dropdown_producer.selectedValue).ToList();
                     foreach (var i in temp)
                     {
                         chart1.Series["Value"].Points.AddXY(i.NAME_PRODUCT, i.Total);
                     }
                 }
             }
         }
         else
         {
             using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
             {
                 var temp = db.GETPRODUCTBY2DAYS(bunifuDatepicker3.Value.Date, bunifuDatepicker2.Value.Date, dropdown_producer.selectedValue).ToList();
                 foreach (var i in temp)
                 {
                     chart1.Series["Value"].Points.AddXY(i.NAME_PRODUCT, i.Total);
                 }
             }
         }
     }
 }
 private void bunifuImageButton1_Click(object sender, EventArgs e)
 {
     foreach (var series in chart2.Series)
     {
         series.Points.Clear();
     }
     if (radiobtn_time2.Checked)
     {
         if (dropdown_type2.selectedValue == "Day")
         {
             using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
             {
                 int total    = db.BILLs.Where(x => x.DATE_TIME == bunifuDatepicker6.Value.Date).Sum(x => x.PRICE);
                 var temp     = db.GETREVENUEBYDAY(bunifuDatepicker6.Value.Date).ToList();
                 int purchase = 0;
                 foreach (var i in temp)
                 {
                     purchase = purchase + (i.PURCHASE_PRICE * (int)i.Amount);
                 }
                 lstSoBanNgay.Add(new KeyValuePair <DateTime, int>(bunifuDatepicker6.Value.Date, purchase));
                 chart2.Series["SELL"].Points.AddXY(lstSoBanNgay[0].Key.ToString("dd - MM - yy"), total);
                 chart2.Series["PURCHASE"].Points.AddXY(lstSoBanNgay[0].Key.ToString("dd - MM - yy"), lstSoBanNgay[0].Value);
             }
         }
         else if (dropdown_type.selectedValue == "Month")
         {
             using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
             {
                 var temp = db.GETPRODUCERBYMONTH(bunifuDatepicker1.Value.Date.Month.ToString(), bunifuDatepicker1.Value.Date.Year.ToString()).ToList();
                 foreach (var i in temp)
                 {
                     chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total);
                 }
             }
         }
         else
         {
             using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
             {
                 var temp = db.GETPRODUCERBYYEAR(bunifuDatepicker1.Value.Date.Year.ToString()).ToList();
                 foreach (var i in temp)
                 {
                     chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total);
                 }
             }
         }
     }
     else
     {
         using (DataStoreManagementDataContext db = new DataStoreManagementDataContext())
         {
             var temp     = db.GETREVENUEBY2DAY(bunifuDatepicker4.Value.Date, bunifuDatepicker5.Value.Date).ToList();
             int total    = 0;
             int purchase = 0;
             for (var day2 = bunifuDatepicker4.Value.Date; day2 <= bunifuDatepicker5.Value.Date; day2 = day2.AddDays(1))
             {
                 if (db.BILLs.Where(x => x.DATE_TIME == day2.Date).ToList().Count() == 0)
                 {
                     total = 0;
                 }
                 else
                 {
                     total = db.BILLs.Where(x => x.DATE_TIME == day2.Date).Sum(x => x.PRICE);
                     var temp2 = db.GETREVENUEBYDAY(day2.Date).ToList();
                     purchase = 0;
                     foreach (var i in temp2)
                     {
                         purchase = purchase + (i.PURCHASE_PRICE * (int)i.Amount);
                     }
                 }
                 chart2.Series["SELL"].Points.AddXY(day2.Date.ToString("dd - MM - yy"), total);
                 chart2.Series["PURCHASE"].Points.AddXY(day2.Date.ToString("dd - MM - yy"), purchase);
             }
         }
     }
 }