Пример #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!Utils.IsValidGuid(cboxComponents.SelectedValue))
            {
                MessageBox.Show("Sample component is required");
                return;
            }

            if (String.IsNullOrEmpty(tbCount.Text.Trim()))
            {
                MessageBox.Show("Count is required");
                return;
            }

            Guid compId = Utils.MakeGuid(cboxComponents.SelectedValue);
            int  count  = 0;

            try
            {
                count = Convert.ToInt32(tbCount.Text.Trim());
            }
            catch
            {
                MessageBox.Show("Invalid number format");
                return;
            }

            if (count < 1 || count > 10000)
            {
                MessageBox.Show("Split count must be between 1 and 10000");
                return;
            }

            SqlConnection  conn  = null;
            SqlTransaction trans = null;

            try
            {
                conn  = DB.OpenConnection();
                trans = conn.BeginTransaction();

                DateTime currDate = DateTime.Now;

                for (int i = 0; i < count; i++)
                {
                    mNewSample.Id                = Guid.NewGuid();
                    mNewSample.Number            = DB.GetNextSampleCount(conn, trans);
                    mNewSample.SampleComponentId = compId;
                    mNewSample.TransformFromId   = mOldSampleId;
                    mNewSample.CreateDate        = currDate;
                    mNewSample.CreateId          = Common.UserId;
                    mNewSample.UpdateDate        = currDate;
                    mNewSample.UpdateId          = Common.UserId;

                    mNewSample.StoreToDB(conn, trans);

                    string json = JsonConvert.SerializeObject(mNewSample);
                    DB.AddAuditMessage(conn, trans, "sample", mNewSample.Id, AuditOperationType.Insert, json, "");
                }

                trans.Commit();
            }
            catch (Exception ex)
            {
                trans?.Rollback();
                Common.Log.Error(ex);
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn?.Close();
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Пример #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (!Utils.IsValidGuid(cboxSampleType.SelectedValue))
            {
                MessageBox.Show("Sample type is mandatory");
                return;
            }

            if (!Utils.IsValidGuid(cboxProjectMain.SelectedValue))
            {
                MessageBox.Show("Main project is mandatory");
                return;
            }

            if (!Utils.IsValidGuid(cboxProjectSub.SelectedValue))
            {
                MessageBox.Show("Sub project is mandatory");
                return;
            }

            if (!Utils.IsValidGuid(cboxLaboratory.SelectedValue))
            {
                MessageBox.Show("Laboratory is mandatory");
                return;
            }

            SqlConnection  conn  = null;
            SqlTransaction trans = null;

            try
            {
                conn  = DB.OpenConnection();
                trans = conn.BeginTransaction();

                DateTime currDate = DateTime.Now;

                Sample sample = new Sample();
                sample.Number       = DB.GetNextSampleCount(conn, trans);
                sample.LaboratoryId = Utils.MakeGuid(cboxLaboratory.SelectedValue);
                sample.SampleTypeId = Utils.MakeGuid(cboxSampleType.SelectedValue);
                if (Utils.IsValidGuid(cboxSampleComponent.SelectedValue))
                {
                    sample.SampleComponentId = Utils.MakeGuid(cboxSampleComponent.SelectedValue);
                }
                sample.ProjectSubId     = Utils.MakeGuid(cboxProjectSub.SelectedValue);
                sample.InstanceStatusId = InstanceStatus.Active;
                sample.CreateDate       = currDate;
                sample.CreateId         = Common.UserId;
                sample.UpdateDate       = currDate;
                sample.UpdateId         = Common.UserId;

                sample.StoreToDB(conn, trans);

                string json = JsonConvert.SerializeObject(sample);
                DB.AddAuditMessage(conn, trans, "sample", sample.Id, AuditOperationType.Insert, json, "");

                trans.Commit();

                SampleId     = sample.Id;
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                trans?.Rollback();
                Common.Log.Error(ex);
                MessageBox.Show(ex.Message);
                DialogResult = DialogResult.Abort;
            }
            finally
            {
                conn?.Close();
            }

            Close();
        }
Пример #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!Utils.IsValidGuid(cboxSampleType.SelectedValue))
            {
                MessageBox.Show("You must select a sample type");
                return;
            }

            Dictionary <string, object> map = new Dictionary <string, object>();

            SqlConnection  conn  = null;
            SqlTransaction trans = null;

            try
            {
                conn  = DB.OpenConnection();
                trans = conn.BeginTransaction();

                DateTime currDate = DateTime.Now;

                Guid   oldSampleId = Utils.MakeGuid(gridSamples.Rows[0].Cells["id"].Value);
                Sample newSample   = new Sample();
                newSample.LoadFromDB(conn, trans, oldSampleId);
                newSample.Id = Guid.NewGuid();
                foreach (Preparation p in newSample.Preparations)
                {
                    p.Analyses.Clear();
                }
                newSample.Preparations.Clear();
                newSample.Parameters.Clear();
                newSample.Number       = DB.GetNextSampleCount(conn, trans);
                newSample.ExternalId   = String.IsNullOrEmpty(tbExternalId.Text.Trim()) ? String.Empty : tbExternalId.Text.Trim();
                newSample.SampleTypeId = Utils.MakeGuid(cboxSampleType.SelectedValue);
                if (Utils.IsValidGuid(cboxSampleComponent.SelectedValue))
                {
                    newSample.SampleComponentId = Utils.MakeGuid(cboxSampleComponent.SelectedValue);
                }
                else
                {
                    newSample.SampleComponentId = Guid.Empty;
                }
                newSample.TransformFromId     = Guid.Empty;
                newSample.MunicipalityId      = Guid.Empty;
                newSample.LocationType        = String.Empty;
                newSample.Location            = String.Empty;
                newSample.StationId           = Guid.Empty;
                newSample.SampleStorageId     = Guid.Empty;
                newSample.SamplerId           = Guid.Empty;
                newSample.SamplingMethodId    = Guid.Empty;
                newSample.Latitude            = newSample.Longitude = newSample.Altitude = null;
                newSample.InstanceStatusId    = InstanceStatus.Active;
                newSample.SamplingDateFrom    = new DateTime(dtSamplingDate.Value.Year, dtSamplingDate.Value.Month, dtSamplingDate.Value.Day, dtSamplingTime.Value.Hour, dtSamplingTime.Value.Minute, dtSamplingTime.Value.Second);
                newSample.SamplingDateTo      = null;
                newSample.ReferenceDate       = new DateTime(dtReferenceDate.Value.Year, dtReferenceDate.Value.Month, dtReferenceDate.Value.Day, dtReferenceTime.Value.Hour, dtReferenceTime.Value.Minute, dtReferenceTime.Value.Second);
                newSample.WetWeight_g         = null;
                newSample.DryWeight_g         = null;
                newSample.LodWeightStart      = null;
                newSample.LodWeightEnd        = null;
                newSample.LodTemperature      = null;
                newSample.LodWaterPercent     = null;
                newSample.LodFactor           = null;
                newSample.LodWeightStartAsh   = null;
                newSample.LodWeightEndAsh     = null;
                newSample.LodTemperatureAsh   = null;
                newSample.LodWaterPercentAsh  = null;
                newSample.LodFactorAsh        = null;
                newSample.LodWeightStartAsh2  = null;
                newSample.LodWeightEndAsh2    = null;
                newSample.LodTemperatureAsh2  = null;
                newSample.LodWaterPercentAsh2 = null;
                newSample.LodFactorAsh2       = null;
                newSample.Comment             = tbComment.Text.Trim();
                newSample.LockedId            = Guid.Empty;
                newSample.CreateDate          = currDate;
                newSample.CreateId            = Common.UserId;
                newSample.UpdateDate          = currDate;
                newSample.UpdateId            = Common.UserId;

                newSample.StoreToDB(conn, trans);

                string json = JsonConvert.SerializeObject(newSample);
                DB.AddAuditMessage(conn, trans, "sample", newSample.Id, AuditOperationType.Insert, json, "");

                SqlCommand cmd = new SqlCommand("update sample set transform_to_id = @transform_to_id where id in(" + mSampleIdsCsv + ")", conn, trans);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@transform_to_id", newSample.Id);
                cmd.ExecuteNonQuery();

                trans.Commit();
            }
            catch (Exception ex)
            {
                trans?.Rollback();
                Common.Log.Error(ex);
                MessageBox.Show(ex.Message);
                return;
            }
            finally
            {
                conn?.Close();
            }

            DialogResult = DialogResult.OK;
            Close();
        }