public clsSizeCodes GetSizeCodeInfoByProjectandSizeCode(string Project, string SizeCode) { clsSizeCodes info = new clsSizeCodes(); using (SqlConnection conn = new SqlConnection(strConn)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("TMR_USP_UnitIDByProjectandSizeCode")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.AddWithValue("@ProjectID", Project); cmd.Parameters.AddWithValue("@SizeCodeID", SizeCode); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { info.strUnitSizeCode = reader["Project"].ToString(); info.strUnitSizeCode = reader["UnitSizeCode"].ToString(); info.strUnitSizeDescription = reader["UnitSizeDescription"].ToString(); info.decArea = Convert.ToDecimal(reader["Area"]); info.UoMID = reader["UoMID"].ToString(); info.UoMDescription = reader["UoMDescription"].ToString(); info.strPrefix = reader["Prefix"].ToString(); info.strCurrentNumber = reader["CurrentNumber"].ToString(); info.ID = Convert.ToInt32(reader["ID"]); } conn.Close(); } } return(info); }
public bool AddSizeCode(clsSizeCodes info) { int st = 0; try { using (SqlConnection conn = new SqlConnection(strConn)) { conn.Open(); { using (SqlCommand cmd = new SqlCommand("TMR_USP_AddSizeCode")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.AddWithValue("@Project", info.strProject); cmd.Parameters.AddWithValue("@UnitSizeCode", info.strUnitSizeCode); cmd.Parameters.AddWithValue("@UnitSizeDescription", info.strUnitSizeDescription); cmd.Parameters.AddWithValue("@Area", info.decArea); cmd.Parameters.AddWithValue("@UnitID", info.UoMID); cmd.Parameters.AddWithValue("@UnitDescription", info.UoMDescription); cmd.Parameters.AddWithValue("@Prefix", info.strPrefix); cmd.Parameters.AddWithValue("@CurrentNumber", info.strCurrentNumber); cmd.Parameters.AddWithValue("@ID", info.ID); st = cmd.ExecuteNonQuery(); } } conn.Close(); } } catch (Exception ex) { } if (st > 0) { return(true); } else { return(false); } }
public List <clsSizeCodes> GetAllSizeCodeInfoByProject(string strProject) { List <clsSizeCodes> lst = new List <clsSizeCodes>(); using (SqlConnection conn = new SqlConnection(strConn)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("TMR_USP_GetSizeCodeByProject")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.AddWithValue("@ProjectID", strProject); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { var info = new clsSizeCodes(); info.strProject = reader["Project"].ToString(); info.strUnitSizeCode = reader["UnitSizeCode"].ToString(); info.strUnitSizeDescription = reader["UnitSizeDescription"].ToString(); info.decArea = Convert.ToDecimal(reader["Area"]); info.UoMID = reader["UoMID"].ToString(); info.UoMDescription = reader["UoMDescription"].ToString(); info.strPrefix = reader["Prefix"].ToString(); info.strCurrentNumber = reader["CurrentNumber"].ToString(); info.ID = Convert.ToInt32(reader["ID"]); lst.Add(info); } conn.Close(); } } return(lst); }
private void btnAdd_Click(object sender, EventArgs e) { decimal decArea = 0; bool b = decimal.TryParse(txtArea.Text, out decArea); if (b == false) { MessageBox.Show("Please enter a valid area."); txtArea.Focus(); return; } if (txtID.Text.Trim() == string.Empty) { MessageBox.Show("Code cannot be empty."); txtID.Focus(); return; } if (txtName.Text.Trim() == "") { MessageBox.Show("Description cannot be empty."); txtName.Focus(); return; } if (txtArea.Text.Trim() == "") { MessageBox.Show("Area cannot be empty."); txtArea.Focus(); return; } if (cmbUoM.Text.Trim() == "") { MessageBox.Show("Please select a unit of measure."); cmbUoM.Focus(); return; } if (txtPrefix.Text.Trim() == "") { MessageBox.Show("Prefix cannot be empty."); txtPrefix.Focus(); return; } if (txtCurrentNumber.Text.Trim() == "") { MessageBox.Show("Current number cannot be empty."); txtCurrentNumber.Focus(); return; } if (cmbProjectID.Text.Trim() == "") { MessageBox.Show("A project must be selected."); cmbProjectID.Focus(); return; } foreach (DataGridViewRow dgr in dgList.Rows) { if (dgr.Cells["Project"].Value.ToString().Trim().ToUpper() == cmbProjectID.Text.Trim().ToUpper() && dgr.Cells["UnitSizeCode"].Value.ToString().Trim().ToUpper() == txtID.Text.Trim().ToUpper() && this.id != Convert.ToInt32(dgr.Cells["ID1"].Value)) { MessageBox.Show("A size code with same ID already exists."); return; } if (dgr.Cells["Project"].Value.ToString().Trim().ToUpper() == cmbProjectID.Text.Trim().ToUpper() && dgr.Cells["Prefix"].Value.ToString().Trim().ToUpper() == txtPrefix.Text.Trim().ToUpper() && this.id != Convert.ToInt32(dgr.Cells["ID1"].Value)) { MessageBox.Show("A prefix code with same ID already exists."); return; } } clsSizeCodes project = new clsSizeCodes(); project.strProject = cmbProjectID.Text; project.strUnitSizeCode = txtID.Text.Trim(); project.strUnitSizeDescription = txtName.Text.Trim(); project.strPrefix = txtPrefix.Text.Trim(); project.strCurrentNumber = txtCurrentNumber.Text.Trim(); project.UoMID = cmbUoM.Text.Trim(); project.decArea = decArea; project.UoMDescription = ""; project.ID = this.id; bool result = da.AddSizeCode(project); if (result == false) { MessageBox.Show("An error occurred."); return; } LoadSizeCodes(); Clear(); }