public List <clsUnitofMeasure> GetAllUOMsInfo() { List <clsUnitofMeasure> lst = new List <clsUnitofMeasure>(); using (SqlConnection conn = new SqlConnection(strConn)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("TMR_USP_GetUOMInfo")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { var info = new clsUnitofMeasure(); info.strUOMid = reader["UnitofMID"].ToString(); info.strUOMDesc = reader["UnitofMDescription"].ToString(); info.id = Convert.ToInt32(reader["ID"]); lst.Add(info); } conn.Close(); } } return(lst); }
public bool AddUOMInfo(clsUnitofMeasure info) { int st = 0; try { using (SqlConnection conn = new SqlConnection(strConn)) { conn.Open(); { using (SqlCommand cmd = new SqlCommand("TMR_USP_AddUOMInfo")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.AddWithValue("@UnitID", info.strUOMid); cmd.Parameters.AddWithValue("@UnitDescription", info.strUOMDesc); cmd.Parameters.AddWithValue("@ID", info.id); st = cmd.ExecuteNonQuery(); } } conn.Close(); } } catch (Exception ex) { } if (st > 0) { return(true); } else { return(false); } }
private void btnAdd_Click(object sender, EventArgs e) { if (txtID.Text.Trim() == string.Empty) { MessageBox.Show("UOM id cannot be empty."); txtID.Focus(); return; } if (txtDesc.Text.Trim() == "") { MessageBox.Show("UOM description cannot be empty."); txtDesc.Focus(); return; } foreach (DataGridViewRow dgr in dgList.Rows) { if (dgr.Cells["UOMID"].Value.ToString().Trim().ToUpper() == txtID.Text.Trim().ToUpper() && this.id != Convert.ToInt32(dgr.Cells["ID1"].Value)) { MessageBox.Show("A unit of measure with same ID already exists."); return; } } clsUnitofMeasure uom = new clsUnitofMeasure(); uom.strUOMid = txtID.Text.Trim(); uom.strUOMDesc = txtDesc.Text.Trim(); uom.id = this.id; bool result = da.AddUOMInfo(uom); if (result == false) { MessageBox.Show("An error occurred."); return; } LoadProjects(); Clear(); }