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
private void btnSaveVehicle_Click(object sender, EventArgs e) { vehimodel.vehicleID = txtVID.Text; vehimodel.vehicleNo = txtVno.Text; vehimodel.type = comboVCategory.Text; vehimodel.model = txtModel.Text; vehimodel.brand = txtbrand.Text; vehimodel.InsuaranceType = txtVInsuarancetype.Text; double rentPerday; bool result1 = Double.TryParse(txtRentPerday.Text, out rentPerday); if (result1 == false) { MessageBox.Show("Please enter Rent per day"); } else { vehimodel.RentPerDay = (float)rentPerday; } double rentPerKM; bool result2 = Double.TryParse(txtrentPerKM.Text, out rentPerKM); if (result1 == false) { MessageBox.Show("Please enter Rent per KM"); } else { vehimodel.RentPerkm = (float)rentPerKM; } vehimodel.VehicleImage = Util.convertImageToBinary(picBoxVehicleImage.Image); using (DBEntities db = new DBEntities()) { db.Vehicles.Add(vehimodel); db.SaveChanges(); MessageBox.Show("Vehicle Added Successfully"); } }
//save employee details database private void btnSave_Click_1(object sender, EventArgs e) { if (validateFormDetails()) { try { //text boxes employeeModel.employeeId = txtempid.Text; employeeModel.fname = txtfname.Text; employeeModel.lname = txtlname.Text; employeeModel.dob = txtdob.Value; employeeModel.contactno = int.Parse(txtconatcno.Text); employeeModel.nic = txtnic.Text; employeeModel.matrialstatus = txtmatrialststus.Text; employeeModel.email = txtemail.Text; employeeModel.basicsalary = Int32.Parse(txtbasicsal.Text); employeeModel.gender = cmbgender.Text; employeeModel.nationality = txtnationality.Text; employeeModel.address = txtaddress.Text; employeeModel.designation = empType; if (empType == "driver") { //textboxes and combo box driver driverModel.driverid = txtempid.Text; driverModel.licenceNo = Int32.Parse(txtlicenceno.Text); driverModel.service = cmbDriverSerivice.Text; driverModel.type = cmbdrivertype.Text; } if (empType == "cleaner") { //combo box cleaner cleanerModel.ctype = txtclenertype.Text; cleanerModel.cleanerid = txtempid.Text; } if (empType == "receptionist") { //combo box receptions receptionModel.receptionid = txtempid.Text; receptionModel.language = cmblanguage.Text; } if (empType == "manager") { //combo boc manager ManagerModel.Managerid = txtempid.Text; ManagerModel.experience = cmbexperiecnce.Text; } if (empType == "headChef") { //combo box mheadchef HeadchefModel.headchefid = txtempid.Text; HeadchefModel.service = txtservice.Text; } //imagee employeeModel.image = Util.convertImageToBinary(picBoxEmp.Image); } //exception handling catch (NullReferenceException) { MessageBox.Show("Please fill the text box and Image", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (FormatException) { MessageBox.Show("please fill the integer number", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } using (DBEntities db = new DBEntities()) { if (status == "insert") { //adding the employee db.Employees.Add(employeeModel); } else if (status == "update") { db.Entry(employeeModel).State = EntityState.Modified; } if (empType == "driver") { if (status == "insert") { //adding the driver db.Drivers.Add(driverModel); MessageBox.Show("Driver added Successfully!!!"); } else if (status == "update") { //update the table db.Entry(driverModel).State = EntityState.Modified; MessageBox.Show("driver Updated Successfully"); } clearTexts(); // db.SaveChanges(); } else if (empType == "cleaner") { if (status == "insert") { //adding the cleaner db.Cleaners.Add(cleanerModel); MessageBox.Show("Cleaner added Successfully!!!"); } else if (status == "update") { //update the table db.Entry(cleanerModel).State = EntityState.Modified; MessageBox.Show("driver Updated Successfully"); } clearTexts(); //db.SaveChanges(); } else if (empType == "receptionist") { if (status == "insert") { //adding the receptionist db.Receptions.Add(receptionModel); MessageBox.Show("receptionist added Successfully!!!"); } else if (status == "update") { //update the table db.Entry(receptionModel).State = EntityState.Modified; MessageBox.Show("Reception Updated Successfully"); } clearTexts(); // db.SaveChanges(); } else if (empType == "manager") { if (status == "insert") { //adding the manager db.Managers.Add(ManagerModel); MessageBox.Show("Manager added Successfully!!!"); } else if (status == "update") { //update the table db.Entry(ManagerModel).State = EntityState.Modified; MessageBox.Show("Reception Updated Successfully"); } // db.SaveChanges(); clearTexts(); } else if (empType == "headChef") { if (status == "insert") { //adding the headchef db.HeadChefs.Add(HeadchefModel); MessageBox.Show("Manager added Successfully!!!"); } else if (status == "update") { //update the table db.Entry(HeadchefModel).State = EntityState.Modified; MessageBox.Show("Reception Updated Successfully"); } //db.SaveChanges(); clearTexts(); } try { db.SaveChanges(); } catch (DbUpdateException ex) { MessageBox.Show(ex.Message); } catch (DbEntityValidationException ex) { MessageBox.Show(ex.Message); } } EmployeeMangementDetailsList em = EmployeeMangementDetailsList.getInstance(); em.Show(); this.Hide(); em.clearempcardpanel(); em.loadEmployees(); Refresh(); } }//end of save event==============================================================
//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(); } // --------------------------------------------------------------------------------------------