private void btnOk_Click(object sender, EventArgs e) { if (!Utils.IsValidGuid(cboxAnalMethods.SelectedValue)) { MessageBox.Show("Analysis method is mandatory"); return; } if (String.IsNullOrEmpty(tbCount.Text.Trim())) { MessageBox.Show("Count is mandatory"); return; } int count = Convert.ToInt32(tbCount.Text.Trim()); if (count == 0) { MessageBox.Show("Count can not be zero"); return; } SqlConnection connection = null; SqlTransaction transaction = null; try { connection = DB.OpenConnection(); transaction = connection.BeginTransaction(); int nextAnalNumber = DB.GetNextAnalysisNumber(connection, transaction, mPrep.Id); SqlCommand cmd = new SqlCommand("csp_insert_analysis", connection, transaction); cmd.CommandType = CommandType.StoredProcedure; while (count > 0) { Guid newAnalId = Guid.NewGuid(); cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@id", newAnalId); cmd.Parameters.AddWithValue("@number", nextAnalNumber++); cmd.Parameters.AddWithValue("@assignment_id", DBNull.Value); cmd.Parameters.AddWithValue("@laboratory_id", Common.LabId, Guid.Empty); cmd.Parameters.AddWithValue("@preparation_id", mPrep.Id); cmd.Parameters.AddWithValue("@analysis_method_id", cboxAnalMethods.SelectedValue, Guid.Empty); cmd.Parameters.AddWithValue("@workflow_status_id", 1); cmd.Parameters.AddWithValue("@specter_reference", DBNull.Value); cmd.Parameters.AddWithValue("@activity_unit_id", DBNull.Value); cmd.Parameters.AddWithValue("@activity_unit_type_id", DBNull.Value); cmd.Parameters.AddWithValue("@sigma_act", 0d); cmd.Parameters.AddWithValue("@sigma_mda", 0d); cmd.Parameters.AddWithValue("@nuclide_library", DBNull.Value); cmd.Parameters.AddWithValue("@mda_library", DBNull.Value); cmd.Parameters.AddWithValue("@instance_status_id", InstanceStatus.Active); cmd.Parameters.AddWithValue("@comment", DBNull.Value); 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(); count--; } string json = JsonConvert.SerializeObject(mSample); DB.AddAuditMessage(connection, transaction, "sample", mSample.Id, AuditOperationType.Update, json, ""); transaction.Commit(); DialogResult = DialogResult.OK; } catch (Exception ex) { transaction?.Rollback(); Common.Log.Error(ex); DialogResult = DialogResult.Abort; MessageBox.Show(ex.Message); } finally { connection?.Close(); } Close(); }
private void btnOk_Click(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(cboxPrinters.Text)) { MessageBox.Show("You must select a printer"); return; } if (cboxPaperSizes.SelectedItem == null) { MessageBox.Show("You must select a printer size"); return; } if (String.IsNullOrEmpty(tbCopies.Text)) { MessageBox.Show("Number of copies must be a positive number"); return; } int copies = Convert.ToInt32(tbCopies.Text); if (copies < 1) { MessageBox.Show("Number of copies must be a positive number"); return; } PaperSize paperSize = cboxPaperSizes.SelectedItem as PaperSize; printDocument.DefaultPageSettings.Landscape = cbLandscape.Checked; printDocument.DefaultPageSettings.PaperSize = paperSize; printDocument.PrintPage += PrintDocument_PrintPage; string query = @" select ps.name as 'project_sub_name', pm.name as 'project_main_name' from project_sub ps inner join project_main pm on pm.id = ps.project_main_id and ps.id = @psid "; SqlConnection conn = null; try { conn = DB.OpenConnection(); using (SqlDataReader reader = DB.GetDataReader(conn, null, query, CommandType.Text, new SqlParameter("@psid", mProjectId))) { if (!reader.HasRows) { MessageBox.Show("No id found for sub project"); return; } reader.Read(); ProjectMainName = reader.GetString("project_main_name"); ProjectSubName = reader.GetString("project_sub_name"); for (int c = 0; c < copies; c++) { printDocument.Print(); } } } catch (Exception ex) { Common.Log.Error(ex); MessageBox.Show(ex.Message); return; } finally { conn?.Close(); } mSettings.LabelPrinterName = cboxPrinters.Text; mSettings.LabelPrinterPaperName = paperSize.PaperName; mSettings.LabelPrinterLandscape = cbLandscape.Checked; DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { Common.Log.Error(ex); MessageBox.Show(ex.Message); } }