private void resetDataGridView()
 {
     for (int i = 0; i < list.Count;)
     {
         using (var db = new PetStoreEntities())
         {
             string id = list[i];
             if (id.StartsWith("PTS"))
             {
                 db.PetToys.Find(id).pt_amount += int.Parse(dataGridView1.Rows[i].Cells["Quantity"].Value.ToString());
                 list.RemoveAt(i);
             }
             else if (id.StartsWith("PFD"))
             {
                 db.PetFoods.Find(id).pf_amount += int.Parse(dataGridView1.Rows[i].Cells["Quantity"].Value.ToString());
                 list.RemoveAt(i);
             }
             else if (id.StartsWith("PAS"))
             {
                 db.PetAccessories.Find(id).pa_amount += int.Parse(dataGridView1.Rows[i].Cells["Quantity"].Value.ToString());
                 list.RemoveAt(i);
             }
             else if (id.StartsWith("PMD"))
             {
                 db.PetMedicines.Find(id).pm_amount += int.Parse(dataGridView1.Rows[i].Cells["Quantity"].Value.ToString());
                 list.RemoveAt(i);
             }
         }
     }
     resetTable();
     checkDelete();
 }
Beispiel #2
0
        /// <summary>
        /// Show enter quantity form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bbiAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            int index = -1;

            try
            {
                index = grvProduct.CurrentRow.Index;
            }
            catch (Exception)
            {
                index = -1;
            }
            if (index != -1)
            {
                int    remain = 0;
                string id     = grvProduct.CurrentRow.Cells["ID"].Value.ToString();
                if (!id.StartsWith("PET"))
                {
                    remain = int.Parse(grvProduct.CurrentRow.Cells["Remain"].Value.ToString());
                }
                EnterQuantity eq = new EnterQuantity(id, remain);
                eq.ShowDialog(this);
                qty = int.Parse(eq.txtQuantity.Text);
                if (qty != 0)
                {
                    eq.Dispose();
                    using (var db = new PetStoreEntities())
                    {
                        switch (bliProduct.ItemIndex)
                        {
                        case 1:
                            db.PetToys.Find(id).pt_amount -= qty;
                            db.SaveChanges();
                            break;

                        case 2:
                            db.PetFoods.Find(id).pf_amount -= qty;
                            db.SaveChanges();
                            break;

                        case 3:
                            db.PetAccessories.Find(id).pa_amount -= qty;
                            db.SaveChanges();
                            break;

                        case 4:
                            db.PetMedicines.Find(id).pm_amount -= qty;
                            db.SaveChanges();
                            break;

                        default:
                            break;
                        }
                    }
                    status = grvProduct.CurrentRow.Index;
                    this.Hide();
                }
            }
        }
        private void btnReset_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var db = new PetStoreEntities();
            var g  = db.Gifts.Find(txt_gID.Text);

            txt_gName.Text           = g.g_name;
            txt_gImage.Text          = "";
            txt_gStatus.SelectedItem = g.g_status;
        }
Beispiel #4
0
        private void btnReset_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var db = new PetStoreEntities();
            var u  = db.Users.Find(int.Parse(txt_uID.Text));

            txt_uName.Text    = u.u_name;
            txt_uGender.Text  = u.u_gender;
            txt_uMail.Text    = u.u_email;
            txt_uPhone.Text   = u.u_phone;
            txt_uAddress.Text = u.u_address;
        }
Beispiel #5
0
        /// <summary>
        /// Reset data on textbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReset_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var db = new PetStoreEntities();
            var p  = db.Pets.Find(te_PID.Text);

            te_PName.Text           = p.p_name;
            te_PImage.Text          = "";
            te_POriginPrice.Text    = p.p_prices + "";
            te_PSalePrice.Text      = p.p_salePrice + "";
            te_PStatus.SelectedItem = p.p_status;
            te_PDescription.Text    = p.p_description;
        }
Beispiel #6
0
        private void btnReset_ItemClick(object sender, ItemClickEventArgs e)
        {
            var db = new PetStoreEntities();
            var pf = db.PetFoods.Find(te_FoodID.Text);

            te_FoodName.Text           = pf.pf_name;
            te_FoodImage.Text          = "";
            te_FoodPrice.Text          = pf.pf_prices + "";
            te_FoodSalePrice.Text      = pf.pf_salePrice + "";
            te_FoodStatus.SelectedItem = pf.pf_status;
            te_FoodAmount.Text         = pf.pf_amount + "";
        }
Beispiel #7
0
        /// <summary>
        /// Get index, delete item, and return quantity
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bbiDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            int index = -1;

            try
            {
                index = dataGridView1.CurrentRow.Index;
            }
            catch (Exception)
            {
                index = -1;
            }
            if (index != -1)
            {
                using (var db = new PetStoreEntities())
                {
                    string id = list[index];
                    if (id.StartsWith("PTS"))
                    {
                        db.PetToys.Find(id).pt_amount += int.Parse(dataGridView1.CurrentRow.Cells["Quantity"].Value.ToString());
                        db.SaveChanges();
                        list.RemoveAt(index);
                    }
                    else if (id.StartsWith("PFD"))
                    {
                        db.PetFoods.Find(id).pf_amount += int.Parse(dataGridView1.CurrentRow.Cells["Quantity"].Value.ToString());
                        db.SaveChanges();
                        list.RemoveAt(index);
                    }
                    else if (id.StartsWith("PAS"))
                    {
                        db.PetAccessories.Find(id).pa_amount += int.Parse(dataGridView1.CurrentRow.Cells["Quantity"].Value.ToString());
                        db.SaveChanges();
                        list.RemoveAt(index);
                    }
                    else if (id.StartsWith("PMD"))
                    {
                        db.PetMedicines.Find(id).pm_amount += int.Parse(dataGridView1.CurrentRow.Cells["Quantity"].Value.ToString());
                        db.SaveChanges();
                        list.RemoveAt(index);
                    }
                    else
                    {
                        list.RemoveAt(index);
                    }
                }
                total -= (int.Parse(table.Rows[index]["Price"].ToString()) * int.Parse(table.Rows[index]["Quantity"].ToString()));
                table.Rows[index].Delete();
                dataGridView1.DataSource = table;
                lblTotalPrice.Text       = "Total: " + total;
            }
        }
 private void bbiCancel_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (selectedID != -1)
     {
         using (var db = new PetStoreEntities())
         {
             var u = db.Bills.Find(selectedID);
             u.b_status = "Inactive";
             db.SaveChanges();
         }
         load();
     }
 }
        private void load()
        {
            UserModel um = new UserModel();

            using (var db = new PetStoreEntities())
            {
                DataTable table = new DataTable();
                table.Columns.Add("ID", typeof(int));
                table.Columns.Add("Order Date", typeof(DateTime));
                table.Columns.Add("Guest", typeof(string));
                table.Columns.Add("Address", typeof(string));

                var list = db.Bills.Where(x => x.b_status == "Processing");
                foreach (var b in list)
                {
                    table.Rows.Add(b.b_id, b.b_purchaseDate, um.getUName(b.u_id), b.b_address);
                }
                grvOrder.DataSource = table;
            }
        }
        private void bbiDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            int index = -1;

            try
            {
                index = dataGridView1.CurrentRow.Index;
            }
            catch (Exception)
            {
                index = -1;
            }
            if (index != -1)
            {
                using (var db = new PetStoreEntities())
                {
                    string id = list[index];
                    if (id.StartsWith("PTS"))
                    {
                        db.PetToys.Find(id).pt_amount += int.Parse(dataGridView1.CurrentRow.Cells["Quantity"].Value.ToString());
                        list.RemoveAt(index);
                    }
                    else if (id.StartsWith("PFD"))
                    {
                        db.PetFoods.Find(id).pf_amount += int.Parse(dataGridView1.CurrentRow.Cells["Quantity"].Value.ToString());
                        list.RemoveAt(index);
                    }
                    else if (id.StartsWith("PAS"))
                    {
                        db.PetAccessories.Find(id).pa_amount += int.Parse(dataGridView1.CurrentRow.Cells["Quantity"].Value.ToString());
                        list.RemoveAt(index);
                    }
                    else if (id.StartsWith("PMD"))
                    {
                        db.PetMedicines.Find(id).pm_amount += int.Parse(dataGridView1.CurrentRow.Cells["Quantity"].Value.ToString());
                        list.RemoveAt(index);
                    }
                }
            }
        }
Beispiel #11
0
 private void btnViewDetail_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (IDSelected != "")
     {
         DetailPetFoodForm vdf = new DetailPetFoodForm();
         PetFoodModel      pfm = new PetFoodModel();
         PetFood           f   = pfm.getPetFood(IDSelected);
         var Db       = new PetStoreEntities();
         var typeFood = Db.Types.Find(f.t_id);
         //set data to detail form
         vdf.te_pfID.Text        = f.pf_id;
         vdf.te_pfName.Text      = f.pf_name;
         vdf.te_pfPriceSale.Text = f.pf_salePrice.ToString();
         vdf.te_pfAmount.Text    = f.pf_amount.ToString();
         vdf.te_Type.Text        = typeFood.t_name;
         if (f.pf_status == "Active")
         {
             vdf.te_pfStatus.ForeColor = Color.Green;
         }
         else
         {
             vdf.te_pfStatus.ForeColor = Color.Red;
         }
         vdf.te_pfStatus.Text   = f.pf_status;
         vdf.te_pfPrice.Enabled = false;
         vdf.lblTitle.Text      = f.pf_name;
         //get image
         String projectPath = Path.GetFullPath(Path.Combine(Application.StartupPath, "..\\.."));
         String pathImage   = projectPath + "\\img\\" + f.pf_image;
         Image  img         = Image.FromFile(pathImage);
         //set image to picture box
         vdf.ptbImage.Image = pfm.ResizeImage(img, 440, 440);
         vdf.ShowDialog();
     }
     else
     {
         MessageBox.Show("Please choose a food to view detail !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Beispiel #12
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="user"></param>
        public rbbSell(string user)
        {
            InitializeComponent();

            username = user;
            //get username from staff
            using (var db = new PetStoreEntities())
            {
                var     list = db.Accounts;
                Account ac   = null;
                foreach (var a in list)
                {
                    if (a.ac_userName == user)
                    {
                        ac = a;
                        break;
                    }
                }
                var uList = db.Users;
                foreach (var uItem in uList)
                {
                    if (uItem.ac_id == ac.ac_id)
                    {
                        u = uItem;
                        break;
                    }
                }
            }
            //Display gift combobox
            foreach (var gift in this.petStoreDataSet1.Gift)
            {
                cbbGift.SelectedText = gift.g_name;
                break;
            }
            //Init data grid view
            resetTable();
        }
 private void bbiPrint_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (txtGuest.Text.Equals(""))
     {
         MessageBox.Show("Please input guest name!", "Message");
     }
     else if (txtAddress.Text.Equals(""))
     {
         MessageBox.Show("Please input address!", "Message");
     }
     else
     {
         int         id;
         GridControl gc = new GridControl();
         gc.DataSource = dataGridView1.DataSource;
         BillReport report = new BillReport();
         report.Parameters["pGuest"].Value   = txtGuest.Text;
         report.Parameters["pAddress"].Value = txtAddress.Text;
         report.Parameters["pDate"].Value    = System.DateTime.Now;
         report.Parameters["pTotal"].Value   = total;
         report.Parameters["pGift"].Value    = cbbGift.Text;
         using (var db = new PetStoreEntities())
         {
             var bill = new Bill();
             bill.b_purchaseDate = System.DateTime.Now;
             bill.b_address      = txtAddress.Text;
             bill.b_total        = total;
             bill.u_id           = 24;
             bill.g_id           = cbbGift.SelectedValue.ToString();
             bill.b_status       = "Active";
             db.Bills.Add(bill);
             db.SaveChanges();
         }
         using (var db = new PetStoreEntities())
         {
             var bill = from s in db.Bills orderby s.b_id descending select s;
             id = 0;
             foreach (var b in bill)
             {
                 id = b.b_id;
                 break;
             }
             int index = 0;
             foreach (var bd in list)
             {
                 var billDetail = new BillDetail();
                 billDetail.b_id = id;
                 if (bd.StartsWith("PET"))
                 {
                     billDetail.p_id = bd;
                 }
                 else if (bd.StartsWith("PTS"))
                 {
                     billDetail.pt_id = bd;
                 }
                 else if (bd.StartsWith("PFD"))
                 {
                     billDetail.pf_id = bd;
                 }
                 else if (bd.StartsWith("PAS"))
                 {
                     billDetail.pa_id = bd;
                 }
                 else if (bd.StartsWith("PMD"))
                 {
                     billDetail.pm_id = bd;
                 }
                 int qty = int.Parse(dataGridView1.Rows[index].Cells["Quantity"].Value.ToString());
                 for (int i = 0; i < qty; i++)
                 {
                     db.BillDetails.Add(billDetail);
                     db.SaveChanges();
                 }
                 index++;
             }
         }
         report.Parameters["pID"].Value = id;
         report.GridControl             = gc;
         ReportPrintTool printTool = new ReportPrintTool(report);
         printTool.AutoShowParametersPanel = true;
         printTool.ShowPreviewDialog();
         resetTable();
     }
 }
        private void bbiPrint_ItemClick(object sender, ItemClickEventArgs e)
        {
            int         id;
            GridControl gc = new GridControl();

            gc.DataSource = dataGridView1.DataSource;
            BillReport report = new BillReport();

            report.Parameters["pGuest"].Value   = txtGuest.Text;
            report.Parameters["pAddress"].Value = txtAddress.Text;
            report.Parameters["pDate"].Value    = System.DateTime.Now;
            report.Parameters["pTotal"].Value   = total;
            report.Parameters["pGift"].Value    = cbbGift.SelectedItem;
            using (var db = new PetStoreEntities())
            {
                var bill = new Bill();
                bill.b_purchaseDate = System.DateTime.Now;
                bill.b_address      = txtAddress.Text;
                bill.b_total        = total;
                bill.guest          = txtGuest.Text;
                bill.u_id           = 24;
                bill.g_id           = cbbGift.SelectedValue.ToString();
                db.Bills.Add(bill);
                db.SaveChanges();
                id = db.Bills.Last().b_id;
                int d = 0;
                foreach (var bd in list)
                {
                    var billDetail = new BillDetail();
                    billDetail.b_id = id;
                    if (bd.StartsWith("PET"))
                    {
                        billDetail.p_id = bd;
                    }
                    else if (bd.StartsWith("PTS"))
                    {
                        billDetail.pt_id = bd;
                    }
                    else if (bd.StartsWith("PFD"))
                    {
                        billDetail.pf_id = bd;
                    }
                    else if (bd.StartsWith("PAS"))
                    {
                        billDetail.pa_id = bd;
                    }
                    else if (bd.StartsWith("PMD"))
                    {
                        billDetail.pm_id = bd;
                    }
                    billDetail.quantity = int.Parse(dataGridView1.Rows[d].Cells["Quantity"].Value.ToString());
                    db.BillDetails.Add(billDetail);
                    db.SaveChanges();
                    d++;
                }
            }
            report.Parameters["pID"].Value = id;
            report.GridControl             = gc;
            ReportPrintTool printTool = new ReportPrintTool(report);

            printTool.ShowPreviewDialog();
            resetTable();
        }
        private void bbiAccept_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (selectedID != -1)
            {
                Bill bill;

                UserModel um = new UserModel();
                using (var db = new PetStoreEntities())
                {
                    var u = db.Bills.Find(selectedID);
                    bill       = u;
                    u.b_status = "Acitve";
                    db.SaveChanges();
                }
                DataGridView grvPrint = new DataGridView();
                DataTable    dt       = new DataTable();
                dt.Columns.Add(new DataColumn("Name", typeof(string)));
                dt.Columns.Add(new DataColumn("Price", typeof(int)));
                dt.Columns.Add(new DataColumn("Quantity", typeof(int)));
                using (var db = new PetStoreEntities())
                {
                    var               list = db.BillDetails.Where(x => x.b_id == selectedID);
                    PetModel          pm   = new PetModel();
                    PetFoodModel      pfm  = new PetFoodModel();
                    PetMedicineModel  pmm  = new PetMedicineModel();
                    PetToyModel       ptm  = new PetToyModel();
                    PetAccessoryModel pam  = new PetAccessoryModel();
                    int               d    = 0;
                    while (d != list.Count())
                    {
                        var bd = list.ToList()[d];
                        if (bd.p_id != null)
                        {
                            var p   = pm.getPet(bd.p_id);
                            var qty = list.Where(x => x.p_id == bd.p_id).Count();
                            dt.Rows.Add(p.p_name, p.p_salePrice, qty);
                            d += qty;
                        }
                        else if (bd.pt_id != null)
                        {
                            var pt  = ptm.getPetToy(bd.pt_id);
                            var qty = list.Where(x => x.pt_id == bd.pt_id).Count();
                            dt.Rows.Add(pt.pt_name, pt.pt_salePrice, qty);
                            d += qty;
                        }
                        else if (bd.pf_id != null)
                        {
                            var pf  = pfm.getPetFood(bd.pf_id);
                            var qty = list.Where(x => x.pf_id == bd.pf_id).Count();
                            dt.Rows.Add(pf.pf_name, pf.pf_salePrice, qty);
                            d += qty;
                        }
                        else if (bd.pm_id != null)
                        {
                            var pmd = pmm.getPetMedicine(bd.pm_id);
                            var qty = list.Where(x => x.pm_id == bd.pm_id).Count();
                            dt.Rows.Add(pmd.pm_name, pmd.pm_salePrice, qty);
                            d += qty;
                        }
                        else if (bd.pa_id != null)
                        {
                            var pa  = pam.getPetAccessory(bd.pa_id);
                            var qty = list.Where(x => x.pa_id == bd.pa_id).Count();
                            dt.Rows.Add(pa.pa_name, pa.pa_salePrice, qty);
                            d += qty;
                        }
                    }
                }
                grvPrint.DataSource = dt;
                GridControl gc = new GridControl();
                gc.DataSource = grvPrint.DataSource;
                BillReport report = new BillReport();
                report.Parameters["pGuest"].Value   = um.getUName(bill.u_id);
                report.Parameters["pAddress"].Value = bill.b_address;
                report.Parameters["pDate"].Value    = bill.b_purchaseDate;
                report.Parameters["pTotal"].Value   = bill.b_total;
                report.Parameters["pID"].Value      = bill.b_id;
                SelectGift sg = new SelectGift();
                sg.ShowDialog(this);
                report.Parameters["pGift"].Value = sg.cbbGift.Text;
                report.GridControl = gc;
                ReportPrintTool printTool = new ReportPrintTool(report);
                printTool.AutoShowParametersPanel = true;
                printTool.ShowPreviewDialog();
                load();
            }
        }
        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            DataGridView grvPrint = new DataGridView();
            DataTable    dt       = new DataTable();

            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Price", typeof(int)));
            dt.Columns.Add(new DataColumn("Quantity", typeof(int)));
            using (var db = new PetStoreEntities())
            {
                var               list = db.BillDetails.Where(x => x.b_id == selectedID);
                PetModel          pm   = new PetModel();
                PetFoodModel      pfm  = new PetFoodModel();
                PetMedicineModel  pmm  = new PetMedicineModel();
                PetToyModel       ptm  = new PetToyModel();
                PetAccessoryModel pam  = new PetAccessoryModel();
                int               d    = 0;
                while (d != list.Count())
                {
                    var bd = list.ToList()[d];
                    if (bd.p_id != null)
                    {
                        var p   = pm.getPet(bd.p_id);
                        var qty = list.Where(x => x.p_id == bd.p_id).Count();
                        dt.Rows.Add(p.p_name, p.p_salePrice, qty);
                        d += qty;
                    }
                    else if (bd.pt_id != null)
                    {
                        var pt  = ptm.getPetToy(bd.pt_id);
                        var qty = list.Where(x => x.pt_id == bd.pt_id).Count();
                        dt.Rows.Add(pt.pt_name, pt.pt_salePrice, qty);
                        d += qty;
                    }
                    else if (bd.pf_id != null)
                    {
                        var pf  = pfm.getPetFood(bd.pf_id);
                        var qty = list.Where(x => x.pf_id == bd.pf_id).Count();
                        dt.Rows.Add(pf.pf_name, pf.pf_salePrice, qty);
                        d += qty;
                    }
                    else if (bd.pm_id != null)
                    {
                        var pmd = pmm.getPetMedicine(bd.pm_id);
                        var qty = list.Where(x => x.pm_id == bd.pm_id).Count();
                        dt.Rows.Add(pmd.pm_name, pmd.pm_salePrice, qty);
                        d += qty;
                    }
                    else if (bd.pa_id != null)
                    {
                        var pa  = pam.getPetAccessory(bd.pa_id);
                        var qty = list.Where(x => x.pa_id == bd.pa_id).Count();
                        dt.Rows.Add(pa.pa_name, pa.pa_salePrice, qty);
                        d += qty;
                    }
                }
            }
            DetailBill dbf = new DetailBill();

            dbf.grvDetail.DataSource = dt;
            dbf.ShowDialog(this);
        }
Beispiel #17
0
 /// <summary>
 /// Display product
 /// </summary>
 /// <param name="name"></param>
 public void displayProduct(string name)
 {
     if (name.Equals("Pets"))
     {
         grvProduct.DataSource = null;
         using (var db = new PetStoreEntities()) {
             DataTable table = new DataTable();
             table.Columns.Add(new DataColumn("ID", typeof(string)));
             table.Columns.Add(new DataColumn("Name", typeof(string)));
             table.Columns.Add(new DataColumn("Price", typeof(int)));
             table.Columns.Add(new DataColumn("Picture", typeof(Image)));
             var select = from s in db.Pets where s.p_status == "Active" select s;
             foreach (var p in select)
             {
                 table.Rows.Add(p.p_id, p.p_name, p.p_salePrice, p.Picture);
             }
             grvProduct.DataSource = table;
             grvProduct.Columns["Price"].DefaultCellStyle.Format = "c";
             grvProduct.RowTemplate.Height = Row_Height;
             ((DataGridViewImageColumn)grvProduct.Columns["Picture"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
         }
     }
     else if (name.Equals("Pet's Toys"))
     {
         grvProduct.DataSource = null;
         using (var db = new PetStoreEntities())
         {
             DataTable table = new DataTable();
             table.Columns.Add(new DataColumn("ID", typeof(string)));
             table.Columns.Add(new DataColumn("Name", typeof(string)));
             table.Columns.Add(new DataColumn("Price", typeof(int)));
             table.Columns.Add(new DataColumn("Remain", typeof(int)));
             table.Columns.Add(new DataColumn("Picture", typeof(Image)));
             var select = from s in db.PetToys where s.pt_status == "Active" && s.pt_amount > 0 select s;
             int d      = 0;
             foreach (var pt in select)
             {
                 table.Rows.Add(pt.pt_id, pt.pt_name, pt.pt_salePrice, pt.pt_amount, pt.Picture);
             }
             grvProduct.DataSource = table;
             grvProduct.Columns["Price"].DefaultCellStyle.Format = "c";
             grvProduct.RowTemplate.Height = Row_Height;
             ((DataGridViewImageColumn)grvProduct.Columns["Picture"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
         }
     }
     else if (name.Equals("Pet's Foods"))
     {
         grvProduct.DataSource = null;
         using (var db = new PetStoreEntities())
         {
             DataTable table = new DataTable();
             table.Columns.Add(new DataColumn("ID", typeof(string)));
             table.Columns.Add(new DataColumn("Name", typeof(string)));
             table.Columns.Add(new DataColumn("Price", typeof(int)));
             table.Columns.Add(new DataColumn("Remain", typeof(int)));
             table.Columns.Add(new DataColumn("Picture", typeof(Image)));
             var select = from s in db.PetFoods where s.pf_status == "Active" && s.pf_amount > 0 select s;
             int d      = 0;
             foreach (var pf in select)
             {
                 table.Rows.Add(pf.pf_id, pf.pf_name, pf.pf_salePrice, pf.pf_amount, pf.Picture);
             }
             grvProduct.DataSource = table;
             grvProduct.Columns["Price"].DefaultCellStyle.Format = "c";
             grvProduct.RowTemplate.Height = Row_Height;
             ((DataGridViewImageColumn)grvProduct.Columns["Picture"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
         }
     }
     else if (name.Equals("Pet's Accessories"))
     {
         grvProduct.DataSource = null;
         using (var db = new PetStoreEntities())
         {
             DataTable table = new DataTable();
             table.Columns.Add(new DataColumn("ID", typeof(string)));
             table.Columns.Add(new DataColumn("Name", typeof(string)));
             table.Columns.Add(new DataColumn("Price", typeof(int)));
             table.Columns.Add(new DataColumn("Remain", typeof(int)));
             var select = from s in db.PetAccessories where s.pa_status == "Active" && s.pa_amount > 0 select s;
             int d      = 0;
             foreach (var pa in select)
             {
                 table.Rows.Add(pa.pa_id, pa.pa_name, pa.pa_salePrice, pa.pa_amount);
             }
             grvProduct.DataSource = table;
             grvProduct.Columns["Price"].DefaultCellStyle.Format = "c";
             //grvProduct.RowTemplate.Height = Row_Height;
             //((DataGridViewImageColumn)grvProduct.Columns["Picture"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
         }
     }
     else if (name.Equals("Pet's Medicines"))
     {
         grvProduct.DataSource = null;
         using (var db = new PetStoreEntities())
         {
             DataTable table = new DataTable();
             table.Columns.Add(new DataColumn("ID", typeof(string)));
             table.Columns.Add(new DataColumn("Name", typeof(string)));
             table.Columns.Add(new DataColumn("Price", typeof(int)));
             table.Columns.Add(new DataColumn("Remain", typeof(int)));
             table.Columns.Add(new DataColumn("Picture", typeof(Image)));
             var select = from s in db.PetMedicines where s.pm_status == "Active" && s.pm_amount > 0 select s;
             int d      = 0;
             foreach (var pm in select)
             {
                 table.Rows.Add(pm.pm_id, pm.pm_name, pm.pm_salePrice, pm.pm_amount, pm.Picture);
             }
             grvProduct.DataSource = table;
             grvProduct.Columns["Price"].DefaultCellStyle.Format = "c";
             grvProduct.RowTemplate.Height = Row_Height;
             ((DataGridViewImageColumn)grvProduct.Columns["Picture"]).ImageLayout = DataGridViewImageCellLayout.Zoom;
         }
     }
 }
Beispiel #18
0
        private void btnSaveEdit_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (te_FoodName.Text != "" && te_FoodAmount.Text != "" &&
                te_FoodPrice.Text != "" && te_FoodSalePrice.Text != "")
            {
                PetFoodModel pfm          = new PetFoodModel();
                String       image        = "";
                String       oldImageName = pfm.getPetFood(te_FoodID.Text).pf_image;
                if (te_FoodImage.Text != "")
                {
                    //set text box image = ID + ".jpg" or ".png"
                    if (openDialog.FileName.EndsWith(".jpg"))
                    {
                        image = te_FoodID.Text + ".jpg";
                    }
                    else
                    {
                        image = te_FoodID.Text + ".png";
                    }

                    //get path app project
                    String projectPath = Path.GetFullPath(Path.Combine(Application.StartupPath, "..\\.."));
                    //old image file path
                    String oldFilePath = projectPath + "\\img\\" + oldImageName;
                    //delete old image file if exist
                    FileInfo f = new FileInfo(oldFilePath);
                    if (f.Exists)
                    {
                        File.Delete(oldFilePath);
                    }

                    //get solution path
                    String solutionPath   = Directory.GetParent(projectPath).FullName;;
                    String oldWebFilePath = solutionPath + "\\PetStoreWebClient\\Assets\\images\\" + oldImageName;
                    //delete old image file if exist
                    FileInfo f2 = new FileInfo(oldWebFilePath);
                    if (f2.Exists)
                    {
                        File.Delete(oldWebFilePath);
                    }

                    //Get new image file path and copy it to image folder
                    String newFilepath    = Path.GetFullPath(projectPath + "\\img\\" + image);
                    String newFileWebpath = Path.GetFullPath(solutionPath + "\\PetStoreWebClient\\Assets\\images\\" + image);
                    File.Copy(te_FoodImage.Text, newFileWebpath);
                    File.Copy(te_FoodImage.Text, newFilepath);
                }
                else
                {
                    //get old image if dont change image
                    image = oldImageName;
                }
                //update pet food on database
                var db     = new PetStoreEntities();
                var typeID = (int)db.Types.FirstOrDefault(x => x.t_name == selectedType).t_id;
                pfm.UpdateFood(te_FoodID.Text, te_FoodName.Text, Convert.ToInt32(te_FoodPrice.Text),
                               Convert.ToInt32(te_FoodSalePrice.Text), Convert.ToInt32(te_FoodAmount.Text), typeID, te_FoodStatus.Text, image);
                //message success
                XtraMessageBox.Show("Edit successful !!!", "Congratulation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                XtraMessageBox.Show("Please fill in full information !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }