Ejemplo n.º 1
0
        /// <summary>
        /// Show Pet detail
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDetail_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (petID != "")    //check user is select pet
            {
                DetailPetForm dtPet = new DetailPetForm();
                PetModel      pm    = new PetModel();
                Pet           p     = pm.getPet(petID);

                //set pet data for textbox on PetDetail Form
                dtPet.txt_pID.Text          = p.p_id;
                dtPet.txt_pName.Text        = p.p_name;
                dtPet.txt_pOriginPrice.Text = p.p_prices.ToString();
                dtPet.txt_pPriceSale.Text   = p.p_salePrice.ToString();
                dtPet.txt_Type.Text         = "";

                //Set color for pet status
                if (p.p_status == "Active")
                {
                    dtPet.txt_pStatus.ForeColor = Color.Green;
                }
                else
                {
                    dtPet.txt_pStatus.ForeColor = Color.Red;
                }

                dtPet.txt_pStatus.Text         = p.p_status;
                dtPet.txt_pOriginPrice.Enabled = true;
                dtPet.lblTitle.Text            = p.p_name;

                //get image path, resize and display image to pictureBox
                String projectPath = Path.GetFullPath(Path.Combine(Application.StartupPath, "..\\.."));
                String pathImage   = projectPath + "\\img\\" + p.p_image;
                Image  img         = Image.FromFile(pathImage);
                dtPet.ptbImage.Image = pm.ResizeImage(img, 440, 440);

                //Show PetDetail Form
                dtPet.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please choose a food to view detail !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 2
0
        private void btnViewDetail_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (petID != "")
            {
                DetailPetForm dtPet = new DetailPetForm();
                PetModel      pm    = new PetModel();

                Pet p = pm.getPet(petID);

                dtPet.txt_pID.Text          = p.p_id;
                dtPet.txt_pName.Text        = p.p_name;
                dtPet.txt_pOriginPrice.Text = p.p_prices.ToString();
                dtPet.txt_pPriceSale.Text   = p.p_salePrice.ToString();
                dtPet.txt_Type.Text         = "";

                if (p.p_status == "Active")
                {
                    dtPet.txt_pStatus.ForeColor = Color.Green;
                }
                else
                {
                    dtPet.txt_pStatus.ForeColor = Color.Red;
                }

                dtPet.txt_pStatus.Text         = p.p_status;
                dtPet.txt_pOriginPrice.Enabled = true;
                dtPet.lblTitle.Text            = p.p_name;

                String projectPath = Path.GetFullPath(Path.Combine(Application.StartupPath, "..\\.."));
                String pathImage   = projectPath + "\\img\\" + p.p_image;
                Image  img         = Image.FromFile(pathImage);
                dtPet.ptbImage.Image = pm.ResizeImage(img, 440, 440);

                dtPet.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please choose a food to view detail !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Edit Pet and close form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (te_PName.Text != "" && te_POriginPrice.Text != "" && te_PSalePrice.Text != "" &&
                Status != "")
            {
                PetModel  pm = new PetModel();
                TypeModel tm = new TypeModel();
                //get pet status
                int    pStatus = tm.getIDByTName(Status);
                String image   = "";
                //get name of image file already in database
                String oldImageName = pm.getPet(te_PID.Text).p_image;
                //Check Image is empty or not
                if (te_PImage.Text != "")
                {
                    //set name image file is Pet's ID appends .jpg or .png
                    if (openDialog.FileName.EndsWith(".jpg"))
                    {
                        image = te_PID.Text + ".jpg";
                    }
                    else
                    {
                        image = te_PID.Text + ".png";
                    }

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

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

                    //get image folder on Apps and Web
                    String newFileAppPath = Path.GetFullPath(projectPath + "\\img\\" + image);
                    String newFileWebPath = Path.GetFullPath(solutionPath + "\\PetStoreWebClient\\Assets\\images\\" + image);
                    //Copy image to 2 image folder
                    File.Copy(te_PImage.Text, newFileAppPath);
                    File.Copy(te_PImage.Text, newFileWebPath);
                }
                else
                {
                    image = oldImageName; //if no new image is seleted then don't change image file
                }

                //Update Pet on database
                pm.UpdatePet(te_PID.Text, te_PName.Text, Convert.ToInt32(te_POriginPrice.Text),
                             Convert.ToInt32(te_PSalePrice.Text), image, te_PDescription.Text,
                             te_PStatus.Text, pStatus);
                //Notify to user
                XtraMessageBox.Show("Edit successful !!!", "Congratulation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else    //send error message
            {
                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);
        }