Esempio n. 1
0
 private void btnViewDetail_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (IDSelected != "")
     {
         DetailPetFoodForm vdf = new DetailPetFoodForm();
         PetFoodModel      pfm = new PetFoodModel();
         PetFood           f   = pfm.getPetFood(IDSelected);
         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        = "Pet's Food";
         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      = "Pet's Food detail for '" + f.pf_name + "'";
         String projectPath = Path.GetFullPath(Path.Combine(Application.StartupPath, "..\\.."));
         String pathImage   = projectPath + "\\img\\" + f.pf_image;
         Image  img         = Image.FromFile(pathImage);
         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);
     }
 }
Esempio n. 2
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 != "")
         {
             if (openDialog.FileName.EndsWith(".jpg"))
             {
                 image = te_FoodID.Text + ".jpg";
             }
             else
             {
                 image = te_FoodID.Text + ".png";
             }
             String   projectPath = Path.GetFullPath(Path.Combine(Application.StartupPath, "..\\.."));
             String   oldFilePath = projectPath + "\\img\\" + oldImageName;
             FileInfo f           = new FileInfo(oldFilePath);
             if (f.Exists)
             {
                 File.Delete(oldFilePath);
             }
             String newFilepath = Path.GetFullPath(projectPath + "\\img\\" + image);
             File.Copy(te_FoodImage.Text, newFilepath);
         }
         else
         {
             image = oldImageName;
         }
         pfm.UpdateFood(te_FoodID.Text, te_FoodName.Text, Convert.ToInt32(te_FoodPrice.Text),
                        Convert.ToInt32(te_FoodSalePrice.Text), Convert.ToInt32(te_FoodAmount.Text), 2, te_FoodStatus.Text, image);
         XtraMessageBox.Show("Edit successful !!!", "Congratulation", MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.Close();
     }
     else
     {
         XtraMessageBox.Show("Please fill in full information !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        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);
        }
Esempio n. 5
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);
            }
        }