public void StoreToDB(SqlConnection conn, SqlTransaction trans) { SqlCommand cmd = new SqlCommand("", conn, trans); if (!AssignmentAnalysisMethod.IdExists(conn, trans, Id)) { // Insert new aam cmd.CommandText = "csp_insert_assignment_analysis_method"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", Id); cmd.Parameters.AddWithValue("@assignment_preparation_method_id", AssignmentPreparationMethodId, Guid.Empty); cmd.Parameters.AddWithValue("@analysis_method_id", AnalysisMethodId, Guid.Empty); cmd.Parameters.AddWithValue("@analysis_method_count", AnalysisMethodCount); cmd.Parameters.AddWithValue("@comment", Comment, String.Empty); cmd.Parameters.AddWithValue("@create_date", DateTime.Now); cmd.Parameters.AddWithValue("@create_id", Common.UserId, Guid.Empty); cmd.Parameters.AddWithValue("@update_date", DateTime.Now); cmd.Parameters.AddWithValue("@update_id", Common.UserId, Guid.Empty); cmd.ExecuteNonQuery(); Dirty = false; } else { if (Dirty) { // Update existing aam cmd.CommandText = "csp_update_assignment_analysis_method"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", Id); cmd.Parameters.AddWithValue("@assignment_preparation_method_id", AssignmentPreparationMethodId, Guid.Empty); cmd.Parameters.AddWithValue("@analysis_method_id", AnalysisMethodId, Guid.Empty); cmd.Parameters.AddWithValue("@analysis_method_count", AnalysisMethodCount); cmd.Parameters.AddWithValue("@comment", Comment, String.Empty); cmd.Parameters.AddWithValue("@update_date", DateTime.Now); cmd.Parameters.AddWithValue("@update_id", Common.UserId, Guid.Empty); cmd.ExecuteNonQuery(); Dirty = false; } } }
private void btnOk_Click(object sender, EventArgs e) { if (!Utils.IsValidGuid(cboxAnalysisMethods.SelectedValue)) { MessageBox.Show("Analysis method is mandatory"); return; } if (String.IsNullOrEmpty(tbCount.Text)) { MessageBox.Show("Analysis method count is mandatory"); return; } if (!Utils.IsValidInteger(tbCount.Text)) { MessageBox.Show("Analysis method count must be a number"); return; } int cnt = Convert.ToInt32(tbCount.Text); if (cnt < 1 || cnt > 10000) { MessageBox.Show("Analysis method count must be between 1 and 10000"); return; } AssignmentAnalysisMethod aam = new AssignmentAnalysisMethod(); aam.AssignmentPreparationMethodId = mApm.Id; aam.AnalysisMethodId = Utils.MakeGuid(cboxAnalysisMethods.SelectedValue); aam.AnalysisMethodCount = cnt; aam.Comment = tbComment.Text.Trim(); aam.CreateDate = DateTime.Now; aam.CreateId = Common.UserId; aam.UpdateDate = DateTime.Now; aam.UpdateId = Common.UserId; aam.Dirty = true; mApm.AnalysisMethods.Add(aam); DialogResult = DialogResult.OK; Close(); }
public void LoadFromDB(SqlConnection conn, SqlTransaction trans, Guid apmId) { using (SqlDataReader reader = DB.GetDataReader(conn, trans, "csp_select_assignment_preparation_method", CommandType.StoredProcedure, new SqlParameter("@id", apmId))) { if (!reader.HasRows) { throw new Exception("Error: Assignment preparation method with id " + apmId.ToString() + " was not found"); } reader.Read(); Id = reader.GetGuid("id"); AssignmentSampleTypeId = reader.GetGuid("assignment_sample_type_id"); PreparationMethodId = reader.GetGuid("preparation_method_id"); PreparationMethodCount = reader.GetInt32("preparation_method_count"); PreparationLaboratoryId = reader.GetGuid("preparation_laboratory_id"); Comment = reader.GetString("comment"); CreateDate = reader.GetDateTime("create_date"); CreateId = reader.GetGuid("create_id"); UpdateDate = reader.GetDateTime("update_date"); UpdateId = reader.GetGuid("update_id"); Dirty = false; } List <Guid> analMethIds = new List <Guid>(); using (SqlDataReader reader = DB.GetDataReader(conn, trans, "select id from assignment_analysis_method where assignment_preparation_method_id = @apmid", CommandType.Text, new SqlParameter("@apmid", apmId))) { while (reader.Read()) { analMethIds.Add(reader.GetGuid("id")); } } foreach (Guid aamId in analMethIds) { AssignmentAnalysisMethod aam = new AssignmentAnalysisMethod(); aam.LoadFromDB(conn, trans, aamId); AnalysisMethods.Add(aam); } }