private void btnUpdate_Click(object sender, EventArgs e) { if (Validation()) { bool success = false; if (cbUpdateItemInfo.Checked) { string sizeTableCode = null; int size_INT = 0; foreach (DataRow row in dt_Size.Rows) { if (row[dalData.SizeNumerator].ToString() == size_numerator.ToString()) { sizeTableCode = row[dalData.TableCode].ToString(); size_INT = int.TryParse(sizeTableCode, out size_INT) ? size_INT : 0; break; } } string typeTableCode = null; int type_INT = 0; foreach (DataRow row in dt_Type.Rows) { if (row[dalData.TypeName].ToString() == lblType.Text) { typeTableCode = row[dalData.TableCode].ToString(); type_INT = int.TryParse(typeTableCode, out type_INT) ? type_INT : 0; break; } } string categoryTableCode = null; int category_INT = 0; foreach (DataRow row in dt_Category.Rows) { if (row[dalData.CategoryName].ToString() == lblCategory.Text) { categoryTableCode = row[dalData.TableCode].ToString(); category_INT = int.TryParse(categoryTableCode, out category_INT) ? category_INT : 0; break; } } //MessageBox.Show("category: " + category_INT + " type: "+type_INT +" size: "+size_INT); uItem.item_code = cmbCode.Text; uItem.Size_tbl_code_1 = size_INT; uItem.Type_tbl_code = type_INT; uItem.Category_tbl_code = category_INT; success = dalItem.SPPUpdate(uItem); //if data is updated successfully then the value = true else false if (success == true) { //data updated successfully MessageBox.Show("Item successfully updated "); } else { //failed to update user MessageBox.Show("Failed to updated item"); } } if (cbUpdateStdPacking.Checked) { uData.Item_code = cmbCode.Text; uData.Qty_Per_Packet = Convert.ToInt32(txtQtyPerPacket.Text); uData.Qty_Per_Bag = Convert.ToInt32(txtQtyPerBag.Text); uData.Updated_Date = DateTime.Now; uData.Updated_By = MainDashboard.USER_ID; int tableCode = -1; foreach (DataRow row in dt_StdPacking.Rows) { if (row[dalData.ItemCode].ToString() == uData.Item_code) { tableCode = int.TryParse(row[dalData.TableCode].ToString(), out tableCode) ? tableCode : -1; } } if (tableCode > 0)//update data { uData.Table_Code = tableCode; success = dalData.StdPackingUpdate(uData); } else { success = dalData.InsertStdPacking(uData); } if (success == true) { //data updated successfully MessageBox.Show("Item std packing successfully updated "); dt_StdPacking = dalData.StdPackingSelect(); } else { //failed to update user MessageBox.Show("Failed to updated item std packing"); } } } }