public bool SaveSubItem(SubItemBO subItem,List<SubItemDetailBO> subItemDetailList) { DBEgine objDbAccess = new DBEgine(); bool result = false; SqlTransaction tran = null; try { SqlParameter[] parms = new SqlParameter[6]; SqlParameter parmItemID = new SqlParameter(); parmItemID.Value = subItem.SubItemID; parmItemID.SqlDbType = SqlDbType.Int; parmItemID.Direction = ParameterDirection.InputOutput; parmItemID.ParameterName = "@SubItemID"; parms[0] = parmItemID; SqlParameter parmItemSerial = new SqlParameter(); parmItemSerial.Value = subItem.SubItemSerial; parmItemSerial.SqlDbType = SqlDbType.VarChar; parmItemSerial.Direction = ParameterDirection.Input; parmItemSerial.ParameterName = "@SubItemSerial"; parms[1] = parmItemSerial; SqlParameter parmDescription = new SqlParameter(); parmDescription.Value = subItem.SubItemDescription; parmDescription.SqlDbType = SqlDbType.VarChar; parmDescription.Direction = ParameterDirection.Input; parmDescription.ParameterName = "@SubItemDescription"; parms[2] = parmDescription; SqlParameter parmMeasuringUnit = new SqlParameter(); parmMeasuringUnit.Value = subItem.SubItemMeasureUnit; parmMeasuringUnit.SqlDbType = SqlDbType.Int; parmMeasuringUnit.Direction = ParameterDirection.Input; parmMeasuringUnit.ParameterName = "@SubItemMeasureUnit"; parms[3] = parmMeasuringUnit; SqlParameter parmCreatedUser = new SqlParameter(); parmCreatedUser.Value = subItem.CreatedUser; parmCreatedUser.SqlDbType = SqlDbType.Int; parmCreatedUser.Direction = ParameterDirection.Input; parmCreatedUser.ParameterName = "@CreatedUser"; parms[4] = parmCreatedUser; SqlParameter parmSubItemUnitPrice = new SqlParameter(); parmSubItemUnitPrice.Value = subItem.SubItemUnitPrice; parmSubItemUnitPrice.SqlDbType = SqlDbType.Decimal; parmSubItemUnitPrice.Direction = ParameterDirection.Input; parmSubItemUnitPrice.ParameterName = "@SubItemUnitPrice"; parms[5] = parmSubItemUnitPrice; objDbAccess.DBOpen(tran); if (objDbAccess.ExecNonQueryStoredProc("Inventory.SaveSubItem", parms) > 0) { new SubItemDetailDAL().DeleteSubItemDetailByID(objDbAccess,int.Parse(parmItemID.Value.ToString())); subItemDetailList.ForEach(delegate(SubItemDetailBO obj) { obj.SubItemID = int.Parse(parmItemID.Value.ToString()); new SubItemDetailDAL().SaveSubItemWithTransaction(obj, objDbAccess); }); result = true; } objDbAccess.DBTransAction.Commit(); return result; } catch (Exception ex) { objDbAccess.DBTransAction.Rollback(); throw ex; } finally { objDbAccess.DBClose(); } }
public SubItemBO GetSubItemByID(int id) { DBEgine objDbAccess = new DBEgine(); var subItem = new SubItemBO(); try { SqlParameter[] parms = new SqlParameter[1]; SqlParameter parmItemID = new SqlParameter(); parmItemID.Value = id; parmItemID.SqlDbType = SqlDbType.Int; parmItemID.Direction = ParameterDirection.Input; parmItemID.ParameterName = "@SubItemID"; parms[0] = parmItemID; objDbAccess.DBOpen(); SqlDataReader dr = objDbAccess.ExecuteReader("Inventory.GetAllSubItemByID", parms); while (dr.Read()) { subItem.SubItemID = int.Parse(dr["SubItemID"].ToString()); subItem.SubItemSerial = dr["SubItemSerial"].ToString(); subItem.SubItemDescription = dr["SubItemDescription"].ToString(); subItem.SubItemUnitPrice = Convert.ToDecimal(dr["SubItemUnitPrice"].ToString()); subItem.SubItemMeasureUnit = Convert.ToInt16(dr["SubItemMeasureUnit"].ToString()); } return subItem; } catch (Exception ex) { throw ex; } finally { objDbAccess.DBClose(); } }
private void buttonSave_Click(object sender, EventArgs e) { try { if (SubItemID > 0 && !ScreenFunctions.Update) { MessageBoxClass.ShowMessage(CommonMethods.GetError("INV_020"), false); return; } DialogResult dialogResult = MessageBoxClass.ShowDialog(CommonMethods.GetError("INV_019")); if (dialogResult == DialogResult.Yes) { var subItemBO = new SubItemBO(); subItemBO.SubItemID = SubItemID; subItemBO.SubItemSerial = textBoxSubItemNo.Text.Trim(); subItemBO.SubItemDescription = textBoxSubItemDescription.Text.Trim(); subItemBO.SubItemMeasureUnit = SubItemMeasuringUnit; subItemBO.SubItemUnitPrice = numericUpDownSubItemUnitPrice.Value; foreach (DataGridViewRow row in dataGridViewSubItemDetails.Rows)//editing enable in grid view { SubItemDetailBOList.Find(s => s.Serial == row.Cells[0].Value.ToString().Trim()).QtyForUnit = decimal.Parse(row.Cells[3].Value.ToString()); } bool result = new SubItemDAL().SaveSubItem(subItemBO, SubItemDetailBOList); if (result) { MessageBoxClass.ShowMessage(CommonMethods.GetError("INV_007"), false); buttonNew_Click(null, null); } else { MessageBoxClass.ShowMessage(CommonMethods.GetError("INV_006"), true); } } } catch { MessageBoxClass.ShowMessage(CommonMethods.GetError("INV_006"), true); } }