private void btnSubmit_Click(object sender, EventArgs e) { //if button submit is clicked, validate all the fields according to the project case if (txtName.Text.Equals("")) lblError.Text = "Name must not be empty"; else if (!checkName()) lblError.Text = "Name can only accept alphabet"; else if (txtName.Text.Length > 50) lblError.Text = "Max name length is 50 characters"; else if (cmbType.SelectedIndex < 0) lblError.Text = "Select product type"; else if (txtWeight.Text.Equals("")) lblError.Text = "Weight must not be empty"; else if (!checkWeight()) lblError.Text = "Weight can only received numerical format"; else { if (op == 1) { //if the varible op contain 1 value, then do insert to database MsProduct obj = new MsProduct(); obj.ProductID = txtID.Text; obj.ProductDescription = txtDesc.Text; obj.ProductName = txtName.Text; obj.ProductType = cmbType.SelectedIndex + 1; obj.ProductWeight = Decimal.Parse(txtWeight.Text); ent.AddToMsProduct(obj); ent.SaveChanges(); refreshTable(); } else if (op == 2) { //if the varible op contain 2 value, then do update to database MsProduct obj = (from x in ent.MsProduct where x.ProductID.Equals(txtID.Text )select x).First(); obj.ProductDescription = txtDesc.Text; obj.ProductName = txtName.Text; obj.ProductType = cmbType.SelectedIndex + 1; obj.ProductWeight = Decimal.Parse(txtWeight.Text); ent.SaveChanges(); refreshTable(); } //return to the initial state btnCancel.Visible = false; btnSubmit.Visible = false; btnUpdate.Enabled = true; btnDelete.Enabled = true; btnInsert.Enabled = true; txtName.Enabled = false; txtWeight.Enabled = false; txtDesc.Enabled = false; cmbType.Enabled = false; btnFirst.Enabled = true; btnPrev.Enabled = true; btnNext.Enabled = true; btnLast.Enabled = true; op = 0; } }
/// <summary> /// Deprecated Method for adding a new object to the MsProduct EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToMsProduct(MsProduct msProduct) { base.AddObject("MsProduct", msProduct); }
private void btnAdd_Click(object sender, EventArgs e) { //when button add is clicked, check whether the totalproduct is 0, 1 or 2, or has reached maximum allowed (3) switch (totalProduct) { case 0: if (cmbpID1.SelectedIndex == -1) { lblError2.Text = "Choose Product"; } else if (!checkQuantity(1)) { lblError2.Text = "Product qty must not be empty and only numeric"; } else { productsID[totalProduct] = cmbpID1.SelectedItem.ToString(); newProduct[0] = new MsProduct(); newProduct[0].ProductID = cmbpID1.SelectedItem.ToString(); newProduct[0].ProductDescription = txtDesc1.Text; newProduct[0].ProductName = txtpName1.Text; newProduct[0].ProductType = cmbpType1.SelectedIndex + 1; newProduct[0].ProductWeight = decimal.Parse(txtWeight1.Text); qty[0] = int.Parse( txtQty1.Text ); gbItem2.Visible = true; totalProduct++; } break; case 1: if (cmbpID2.SelectedIndex == -1) { lblError2.Text = "Choose Product"; } else if( checkSameProduct( cmbpID2.SelectedItem.ToString()) ) { lblError2.Text = "Can’t choose the same product"; } else if (!checkQuantity(2)) { lblError2.Text = "Product qty must not be empty and only numeric"; } else { productsID[totalProduct] = cmbpID2.SelectedItem.ToString(); newProduct[1] = new MsProduct(); newProduct[1].ProductID = cmbpID2.SelectedItem.ToString(); newProduct[1].ProductDescription = txtDesc2.Text; newProduct[1].ProductName = txtpName2.Text; newProduct[1].ProductType = cmbpType2.SelectedIndex + 1; newProduct[1].ProductWeight = decimal.Parse(txtWeight2.Text); qty[1] = int.Parse(txtQty2.Text); gbItem3.Visible = true; totalProduct++; } break; case 2: lblError2.Text = "Only 3 Items Allowed"; break; } }
/// <summary> /// Create a new MsProduct object. /// </summary> /// <param name="productID">Initial value of the ProductID property.</param> /// <param name="productName">Initial value of the ProductName property.</param> /// <param name="productType">Initial value of the ProductType property.</param> /// <param name="productWeight">Initial value of the ProductWeight property.</param> public static MsProduct CreateMsProduct(global::System.String productID, global::System.String productName, global::System.Int32 productType, global::System.Decimal productWeight) { MsProduct msProduct = new MsProduct(); msProduct.ProductID = productID; msProduct.ProductName = productName; msProduct.ProductType = productType; msProduct.ProductWeight = productWeight; return msProduct; }
private void btnProceed2_Click(object sender, EventArgs e) { //when button proceed is clicked, check whether have inputted the available field in correct format switch (totalProduct) { case 0: if (cmbpID1.SelectedIndex == -1) { lblError2.Text = "Choose Product"; } else if (!checkQuantity(1)) { lblError2.Text = "Product qty must not be empty and only numeric"; } else { productsID[totalProduct] = cmbpID1.SelectedItem.ToString(); newProduct[0] = new MsProduct(); newProduct[0].ProductID = cmbpID1.SelectedItem.ToString(); newProduct[0].ProductDescription = txtDesc1.Text; newProduct[0].ProductName = txtpName1.Text; newProduct[0].ProductType = cmbpType1.SelectedIndex + 1; newProduct[0].ProductWeight = decimal.Parse( txtWeight1.Text ); qty[0] = int.Parse(txtQty1.Text); totalProduct++; step = 2; tabControl1.SelectedIndex = step; initThirdTab(); } break; case 1: if (cmbpID2.SelectedIndex == -1) { lblError2.Text = "Choose Product"; } else if (checkSameProduct(cmbpID2.SelectedItem.ToString())) { lblError2.Text = "Can’t choose the same product"; } else if (!checkQuantity(2)) { lblError2.Text = "Product qty must not be empty and only numeric"; } else { productsID[totalProduct] = cmbpID2.SelectedItem.ToString(); newProduct[1] = new MsProduct(); newProduct[1].ProductID = cmbpID2.SelectedItem.ToString(); newProduct[1].ProductDescription = txtDesc2.Text; newProduct[1].ProductName = txtpName2.Text; newProduct[1].ProductType = cmbpType2.SelectedIndex + 1; newProduct[1].ProductWeight = decimal.Parse(txtWeight2.Text); qty[1] = int.Parse(txtQty1.Text); totalProduct++; step = 2; tabControl1.SelectedIndex = step; initThirdTab(); } break; case 2: if (cmbpID3.SelectedIndex == -1) { lblError2.Text = "Choose Product"; } else if (checkSameProduct(cmbpID3.SelectedItem.ToString())) { lblError2.Text = "Can’t choose the same product"; } else if (!checkQuantity(3)) { lblError2.Text = "Product qty must not be empty and only numeric"; } else { productsID[totalProduct] = cmbpID3.SelectedItem.ToString(); newProduct[2] = new MsProduct(); newProduct[2].ProductID = cmbpID3.SelectedItem.ToString(); newProduct[2].ProductDescription = txtDesc3.Text; newProduct[2].ProductName = txtpName3.Text; newProduct[2].ProductType = cmbpType3.SelectedIndex + 1; newProduct[2].ProductWeight = decimal.Parse(txtWeight3.Text); qty[2] = int.Parse(txtQty1.Text); totalProduct++; step = 2; tabControl1.SelectedIndex = step; initThirdTab(); } break; } }