Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            itemRow.itemID            = txtItemID.Text;
            itemRow.name              = txtItemName.Text;
            itemRow.limitQuantity     = Int32.Parse(txtLimit.Text);
            itemRow.unitOfMeasurement = txtUnitOfMesasure.Text; //#########


            double purchasePrice;
            bool   res1 = Double.TryParse(txtPurchacePrice.Text, out purchasePrice);

            if (res1 == false)
            {
                MessageBox.Show("please Fill the purchase price");
            }
            else
            {
                itemRow.purchase_price = (float)purchasePrice;
            }

            itemRow.suppliedBy = "ss";

            itemRow.unitOfMeasurement = txtUnitOfMesasure.Text;
            //setting category id
            String cid = Util.getCategoryID("ItemCategory", comboItemcategories.Text);

            MessageBox.Show(cid);
            itemRow.categoryID = cid;

            itemRow.image = Util.convertImageToBinary(picBocitempic.Image);

            using (DBEntities db = new DBEntities())
            {
                if (operation == "insert")
                {
                    db.Items.Add(itemRow);
                    MessageBox.Show("Item Added Successfully");
                }
                else if (operation == "update")
                {
                    db.Entry(itemRow).State = EntityState.Modified;
                    MessageBox.Show("Item details Updated Successfully");
                }

                db.SaveChanges();
            }

            StockManagement sm = StockManagement.getInstance();

            sm.clearItemList();
            sm.loadKitchenItems();
            this.Hide();
            sm.Show();
        }//end of save method
Example #2
0
        //Adding Item to the Data Base -----------------------
        private void btnSaveFoodItem_Click(object sender, EventArgs e)
        {
            if (status == "food") //adding meal/food details
            {
                //getting the user entered value
                food.foodCode    = txtID.Text;
                food.name        = txtName.Text;
                food.description = txtDescription.Text;

                //setting selling price
                double sellingPrice;
                bool   result1 = Double.TryParse(txtSellingPrice.Text, out sellingPrice);
                if (result1 == false)
                {
                    MessageBox.Show("Please enter Selling price");
                }
                else
                {
                    food.sellingPrice = (float)sellingPrice;
                }

                //setting discount rate
                double discountRate;
                bool   result2 = Double.TryParse(txtDiscountRate.Text, out discountRate);
                if (result2 == false)
                {
                    MessageBox.Show("Please enter Discount Rate");
                }
                else
                {
                    food.disountRate = (float)discountRate;
                }

                //setting category id
                String cid = Util.getCategoryID("FoodCategory", comboCategory.Text);
                food.categoryID = cid;

                //setting Image
                food.foodImage = Util.convertImageToBinary(picBoxImage.Image);

                //****** saving informations to the database
                using (DBEntities db = new DBEntities())
                {
                    if (operation == "save")
                    {
                        db.Foods.Add(food);
                        MessageBox.Show("Meal/Food Item Added Successfully!!!");
                    }
                    else if (operation == "update")
                    {
                        //updating the database
                        db.Entry(food).State = EntityState.Modified;
                        MessageBox.Show("Food details Updated Successfully");
                    }
                    db.SaveChanges();
                    clear();
                }
            }
            else if (status == "readyMade") //addimng a readymade product details
            {
                //setting values to the row object
                itemModel.itemID = txtID.Text;
                itemModel.name   = txtName.Text;

                //setting purchase price
                double purchaseprice;
                bool   result3 = Double.TryParse(txtFoodPurchasePrice.Text, out purchaseprice);
                if (result3 == false)
                {
                    MessageBox.Show("Please enter Purchase price");
                }
                else
                {
                    itemModel.purchase_price = (float)purchaseprice;
                }

                itemModel.suppliedBy    = null; //this shold be implemented After adding supplier table
                itemModel.limitQuantity = Int32.Parse(textReadymadeLimitQuantity.Text);

                //setting category id
                String cid = Util.getCategoryID("ItemCategory", comboCategory.Text);
                itemModel.categoryID = cid;

                //setting Image
                itemModel.image = Util.convertImageToBinary(picBoxImage.Image);


                //************* details adding to readyMAde product table *
                readymaddModel.productID = txtID.Text;
                //setting selling price of the product
                double productSellPrice;
                bool   result4 = Double.TryParse(txtReadyMadeSellingPrice.Text, out productSellPrice);
                if (result4 == false)
                {
                    MessageBox.Show("Please enter Selling  price of the product");
                }
                else
                {
                    readymaddModel.sellingPrice = (float)productSellPrice;
                }
                //*************

                using (DBEntities db = new DBEntities())
                {
                    db.Items.Add(itemModel);
                    db.ReadyMadeProducts.Add(readymaddModel);
                    db.SaveChanges();

                    MessageBox.Show("Ready Made product Added Successfully");
                    clear();
                }
            }
            else
            {
                MessageBox.Show("Cannot identify !!! (rm or Food) ");
            }

            FoodManagement fm = FoodManagement.getInstance();

            fm.clearFoodcardpanel();
            fm.loadFoodItemCards();
            this.Hide();
            fm.Show();
        } // --------------------------------------------------------------------------------------------