Example #1
0
 public ProcessBaseVm(AdminLevel a, ProcessDetails s, ICalcIndicators c)
 {
     r = new ProcessRepository();
     this.model = r.GetById(s.Id);
     adminLevel = a;
     calc = c;
 }
Example #2
0
 public ProcessBaseVm(AdminLevel a, int typeId, ICalcIndicators c)
 {
     adminLevel = a;
     r = new ProcessRepository();
     model = r.Create(typeId);
     model.AdminLevelId = adminLevel.Id;
     calc = c;
 }
Example #3
0
        public void BindData(ProcessBase e, List<AdminLevel> u, AdminLevel s)
        {
            source = s;
            Localizer.TranslateControl(this);
            sae = e;
            destinations = u;
            var idInd = e.IndicatorValues.FirstOrDefault(i => i.Indicator.DisplayName == "SaeId");
            lnkName.Text = e.DateReported.ToShortDateString();
            if (idInd != null && !string.IsNullOrEmpty(idInd.DynamicValue))
                lnkName.Text = idInd.DynamicValue + " - " + lnkName.Text;

            destinations.Insert(0, new AdminLevel { Id = -1, Name = "" });
            bindingSource1.DataSource = destinations;

            if (destinations.Count > 0)
                cbUnits.DropDownWidth = BaseForm.GetDropdownWidth(destinations.Select(a => a.Name));
        }
Example #4
0
 public ProcessBaseVm(AdminLevel a, ProcessBase s, ICalcIndicators c)
 {
     this.model = s;
     adminLevel = a;
     calc = c;
 }
 public ProcessBase Create(int typeId)
 {
     ProcessBase Process = new ProcessBase();
     Process.ProcessType = GetProcessType(typeId);
     return Process;
 }
 private void GetProcessIndicatorValues(OleDbConnection connection, ProcessBase Process)
 {
     OleDbCommand command = new OleDbCommand(@"Select 
                 ProcessIndicatorValues.ID,   
                 ProcessIndicatorValues.IndicatorId,
                 ProcessIndicatorValues.DynamicValue,
                 ProcessIndicatorValues.MemoValue,
                 ProcessIndicators.DisplayName,
                 ProcessIndicatorValues.CalcByRedistrict
                 FROM ProcessIndicatorValues INNER JOIN ProcessIndicators on ProcessIndicatorValues.IndicatorId = ProcessIndicators.ID
                 WHERE ProcessIndicatorValues.ProcessId = @ProcessId", connection);
     command.Parameters.Add(new OleDbParameter("@ProcessId", Process.Id));
     using (OleDbDataReader reader = command.ExecuteReader())
     {
         while (reader.Read())
         {
             if (!Process.ProcessType.Indicators.ContainsKey(reader.GetValueOrDefault<string>("DisplayName")))
                 continue;
             var ind = Process.ProcessType.Indicators[reader.GetValueOrDefault<string>("DisplayName")];
             string val = reader.GetValueOrDefault<string>("DynamicValue");
             if (ind.DataTypeId == (int)IndicatorDataType.LargeText && !string.IsNullOrEmpty(reader.GetValueOrDefault<string>("MemoValue")))
                 val = reader.GetValueOrDefault<string>("MemoValue");
             Process.IndicatorValues.Add(new IndicatorValue
             {
                 Id = reader.GetValueOrDefault<int>("ID"),
                 IndicatorId = reader.GetValueOrDefault<int>("IndicatorId"),
                 DynamicValue = val,
                 CalcByRedistrict = reader.GetValueOrDefault<bool>("CalcByRedistrict"),
                 Indicator = ind
             });
         }
         reader.Close();
     }
 }
        private void AddProcessIndicatorValues(OleDbConnection connection, ProcessBase Process, int userId)
        {
            OleDbCommand command = new OleDbCommand(@"DELETE FROM ProcessIndicatorValues WHERE ProcessId=@ProcessId", connection);
            command.Parameters.Add(new OleDbParameter("@ProcessId", Process.Id));
            command.ExecuteNonQuery();

            foreach (IndicatorValue val in Process.IndicatorValues)
            {
                command = new OleDbCommand(@"Insert Into ProcessIndicatorValues (IndicatorId, ProcessId, DynamicValue, MemoValue, UpdatedById, UpdatedAt, CalcByRedistrict) VALUES
                        (@IndicatorId, @ProcessId, @DynamicValue, @MemoValue, @UpdatedById, @UpdatedAt, @CalcByRedistrict)", connection);
                command.Parameters.Add(new OleDbParameter("@IndicatorId", val.IndicatorId));
                command.Parameters.Add(new OleDbParameter("@ProcessId", Process.Id));
                AddValueParam(command, val);
                command.Parameters.Add(new OleDbParameter("@UpdatedById", userId));
                command.Parameters.Add(OleDbUtil.CreateDateTimeOleDbParameter("@UpdatedAt", DateTime.Now));
                command.Parameters.Add(new OleDbParameter("@CalcByRedistrict", val.CalcByRedistrict));
                command.ExecuteNonQuery();
            }
        }
        public void Save(OleDbCommand command, OleDbConnection connection, ProcessBase process, int userId)
        {
            // Mapping year reported
            process.MapIndicatorsToProperties();
            process.MapPropertiesToIndicators();

            if (process.Id > 0)
                command = new OleDbCommand(@"UPDATE processes SET ProcessTypeId=@ProcessTypeId, AdminLevelId=@AdminLevelId, DateReported=@DateReported,
                           SCMDrug=@SCMDrug, PCTrainTrainingCategory=@PCTrainTrainingCategory,
                           Notes=@Notes, UpdatedById=@UpdatedById, UpdatedAt=@UpdatedAt WHERE ID=@id", connection);
            else
                command = new OleDbCommand(@"INSERT INTO processes (ProcessTypeId, AdminLevelId, DateReported, SCMDrug, PCTrainTrainingCategory,
                            Notes, UpdatedById, UpdatedAt, CreatedById, CreatedAt) values (@ProcessTypeId, @AdminLevelId, @DateReported, @SCMDrug, 
                            @PCTrainTrainingCategory, @Notes, @UpdatedById, @UpdatedAt, @CreatedById, @CreatedAt)", connection);
            command.Parameters.Add(new OleDbParameter("@ProcessTypeId", process.ProcessType.Id));
            command.Parameters.Add(OleDbUtil.CreateNullableParam("@AdminLevelId", process.AdminLevelId));
            command.Parameters.Add(OleDbUtil.CreateDateTimeOleDbParameter("@DateReported", process.DateReported));
            command.Parameters.Add(OleDbUtil.CreateNullableParam("@SCMDrug", process.SCMDrug));
            command.Parameters.Add(OleDbUtil.CreateNullableParam("@PCTrainTrainingCategory", process.PCTrainTrainingCategory));
            command.Parameters.Add(OleDbUtil.CreateNullableParam("@Notes", process.Notes));
            command.Parameters.Add(new OleDbParameter("@UpdatedById", userId));
            command.Parameters.Add(OleDbUtil.CreateDateTimeOleDbParameter("@UpdatedAt", DateTime.Now));
            if (process.Id > 0)
                command.Parameters.Add(new OleDbParameter("@id", process.Id));
            else
            {
                command.Parameters.Add(new OleDbParameter("@CreatedById", userId));
                command.Parameters.Add(OleDbUtil.CreateDateTimeOleDbParameter("@CreatedAt", DateTime.Now));
            }

            command.ExecuteNonQuery();

            if (process.Id <= 0)
            {
                command = new OleDbCommand(@"SELECT Max(ID) FROM processes", connection);
                process.Id = (int)command.ExecuteScalar();
            }

            AddProcessIndicatorValues(connection, process, userId);
        }
        public void Save(ProcessBase process, int userId)
        {
            bool transWasStarted = false;
            OleDbConnection connection = new OleDbConnection(DatabaseData.Instance.AccessConnectionString);
            using (connection)
            {
                connection.Open();
                try
                {
                    // START TRANS
                    OleDbCommand command = new OleDbCommand("BEGIN TRANSACTION", connection);
                    command.ExecuteNonQuery();
                    transWasStarted = true;

                    Save(command, connection, process, userId);

                    // COMMIT TRANS
                    command = new OleDbCommand("COMMIT TRANSACTION", connection);
                    command.ExecuteNonQuery();
                    transWasStarted = false;
                }
                catch (Exception)
                {
                    if (transWasStarted)
                    {
                        try
                        {
                            OleDbCommand cmd = new OleDbCommand("ROLLBACK TRANSACTION", connection);
                            cmd.ExecuteNonQuery();
                        }
                        catch { }
                    }
                    throw;
                }
            }
        }
        public ProcessBase GetProcess(OleDbCommand command, OleDbConnection connection, int pId)
        {
            var process = new ProcessBase();
            int ptypeId = 0;

            try
            {
                command = new OleDbCommand(@"Select processes.AdminLevelId, processes.DateReported, SCMDrug, PCTrainTrainingCategory,
                        processes.Notes, processes.UpdatedById, processes.UpdatedAt, aspnet_Users.UserName, AdminLevels.DisplayName, 
                        processes.ProcessTypeId, created.UserName as CreatedBy, processes.CreatedAt
                        FROM (((processes INNER JOIN aspnet_Users on processes.UpdatedById = aspnet_Users.UserId)
                            LEFT OUTER JOIN AdminLevels on processes.AdminLevelId = AdminLevels.ID)
                            INNER JOIN aspnet_Users created on processes.CreatedById = created.UserId)
                        WHERE processes.ID=@id", connection);
                command.Parameters.Add(new OleDbParameter("@id", pId));
                using (OleDbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        reader.Read();
                        process.Id = pId;
                        process.AdminLevelId = reader.GetValueOrDefault<Nullable<int>>("AdminLevelId");
                        process.DateReported = reader.GetValueOrDefault<DateTime>("DateReported");
                        process.SCMDrug = reader.GetValueOrDefault<string>("SCMDrug");
                        process.PCTrainTrainingCategory = reader.GetValueOrDefault<string>("PCTrainTrainingCategory");
                        process.Notes = reader.GetValueOrDefault<string>("Notes");
                        process.UpdatedAt = reader.GetValueOrDefault<DateTime>("UpdatedAt");
                        process.UpdatedBy = GetAuditInfo(reader);
                        ptypeId = reader.GetValueOrDefault<int>("ProcessTypeId");
                    }
                    reader.Close();
                }

                process.ProcessType = GetProcessType(ptypeId);
                GetProcessIndicatorValues(connection, process);
                process.MapIndicatorsToProperties();
            }
            catch (Exception)
            {
                throw;
            }

            return process;
        }
Example #11
0
 public SaeMatcher(ProcessBase e, List<AdminLevel> u, AdminLevel s)
     : base()
 {
     InitializeComponent();
     BindData(e, u, s);
 }