public DdtEgds GetById(string id)
        {
            using (dynamic connection = connectionFactory.GetConnection())
            {
                String sql = String.Format("SELECT dsid_hospitality_session, r_object_id, dsdt_analysis_date, r_modify_date, dss_egds, dss_parent_type, r_creation_date, dsid_parent, dsb_admission_analysis, dsid_doctor, dsid_patient FROM ddt_egds WHERE r_object_id = '{0}'", id);

                Logger.Debug(CultureInfo.CurrentCulture, "SQL: {0}", sql);

                Npgsql.NpgsqlCommand command = new Npgsql.NpgsqlCommand(sql, connection);
                using (DbDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        DdtEgds obj = new DdtEgds();
                        obj.HospitalitySession = reader.IsDBNull(0) ? null : reader.GetString(0);
                        obj.ObjectId           = reader.IsDBNull(1) ? null : reader.GetString(1);
                        obj.AnalysisDate       = reader.IsDBNull(2) ? DateTime.MinValue : reader.GetDateTime(2);
                        obj.ModifyDate         = reader.IsDBNull(3) ? DateTime.MinValue : reader.GetDateTime(3);
                        obj.Egds              = reader.IsDBNull(4) ? null : reader.GetString(4);
                        obj.ParentType        = reader.IsDBNull(5) ? null : reader.GetString(5);
                        obj.CreationDate      = reader.IsDBNull(6) ? DateTime.MinValue : reader.GetDateTime(6);
                        obj.Parent            = reader.IsDBNull(7) ? null : reader.GetString(7);
                        obj.AdmissionAnalysis = reader.GetBoolean(8);
                        obj.Doctor            = reader.IsDBNull(9) ? null : reader.GetString(9);
                        obj.Patient           = reader.IsDBNull(10) ? null : reader.GetString(10);
                        return(obj);
                    }
                }
            }
            return(null);
        }
        private void InitControls()
        {
            DdtEgds egds = DbDataService.GetInstance().GetDdtEgdsService().GetById(objectId);

            refreshObject(egds);
            regularEgdsTxt.Enabled = isEditable;
            analysisDate.Enabled   = isEditable;
        }
 public string Save(DdtEgds obj)
 {
     using (dynamic connection = connectionFactory.GetConnection())
     {
         if (GetById(obj.ObjectId) != null)
         {
             string sql = "UPDATE ddt_egds SET " +
                          "dsid_hospitality_session = @HospitalitySession, " +
                          "dsid_patient = @Patient, " +
                          "dsid_doctor = @Doctor, " +
                          "dsdt_analysis_date = @AnalysisDate, " +
                          "dss_egds = @Egds, " +
                          "dsb_admission_analysis = @AdmissionAnalysis, " +
                          "dsid_parent = @Parent, " +
                          "dss_parent_type = @ParentType " +
                          "WHERE r_object_id = @ObjectId";
             Logger.Debug(CultureInfo.CurrentCulture, "SQL: {0}", sql);
             using (Npgsql.NpgsqlCommand cmd = new Npgsql.NpgsqlCommand(sql, connection))
             {
                 cmd.CommandType = CommandType.Text;
                 cmd.Parameters.AddWithValue("@HospitalitySession", obj.HospitalitySession);
                 cmd.Parameters.AddWithValue("@Patient", obj.Patient);
                 cmd.Parameters.AddWithValue("@Doctor", obj.Doctor);
                 cmd.Parameters.AddWithValue("@AnalysisDate", obj.AnalysisDate);
                 cmd.Parameters.AddWithValue("@Egds", obj.Egds == null ? "" : obj.Egds);
                 cmd.Parameters.AddWithValue("@AdmissionAnalysis", obj.AdmissionAnalysis);
                 cmd.Parameters.AddWithValue("@Parent", obj.Parent == null ? "0000000000000000" : obj.Parent);
                 cmd.Parameters.AddWithValue("@ParentType", obj.ParentType == null ? "" : obj.ParentType);
                 cmd.Parameters.AddWithValue("@ObjectId", obj.ObjectId);
                 cmd.ExecuteNonQuery();
             }
             return(obj.ObjectId);
         }
         else
         {
             string sql = "INSERT INTO ddt_egds(dsid_hospitality_session,dsid_patient,dsid_doctor,dsdt_analysis_date,dss_egds,dsb_admission_analysis,dsid_parent,dss_parent_type) " +
                          "VALUES(@HospitalitySession,@Patient,@Doctor,@AnalysisDate,@Egds,@AdmissionAnalysis,@Parent,@ParentType) RETURNING r_object_id";
             Logger.Debug(CultureInfo.CurrentCulture, "SQL: {0}", sql);
             using (Npgsql.NpgsqlCommand cmd = new Npgsql.NpgsqlCommand(sql, connection))
             {
                 cmd.CommandType = CommandType.Text;
                 cmd.Parameters.AddWithValue("@HospitalitySession", obj.HospitalitySession);
                 cmd.Parameters.AddWithValue("@Patient", obj.Patient);
                 cmd.Parameters.AddWithValue("@Doctor", obj.Doctor);
                 cmd.Parameters.AddWithValue("@AnalysisDate", obj.AnalysisDate);
                 cmd.Parameters.AddWithValue("@Egds", obj.Egds == null ? "" : obj.Egds);
                 cmd.Parameters.AddWithValue("@AdmissionAnalysis", obj.AdmissionAnalysis);
                 cmd.Parameters.AddWithValue("@Parent", obj.Parent == null ? "0000000000000000" : obj.Parent);
                 cmd.Parameters.AddWithValue("@ParentType", obj.ParentType == null ? "" : obj.ParentType);
                 return((string)cmd.ExecuteScalar());
             }
         }
     }
 }
        public object getObject()
        {
            DdtEgds egds = DbDataService.GetInstance().GetDdtEgdsService().GetById(objectId);

            if (egds == null)
            {
                egds = new DdtEgds();
            }
            egds.AnalysisDate = analysisDate.Value;
            egds.Egds         = regularEgdsTxt.Text;
            return(egds);
        }
 public void refreshObject(object obj)
 {
     if (obj != null && obj is DdtEgds)
     {
         DdtEgds egds = (DdtEgds)obj;
         regularEgdsTxt.Text   = egds.Egds;
         analysisTitleLbl.Text = "ЭГДС за " + egds.AnalysisDate.ToShortDateString();
         analysisDate.Value    = egds.AnalysisDate;
         objectId   = egds.ObjectId;
         isNew      = string.IsNullOrEmpty(objectId);
         hasChanges = false;
     }
 }
        public IList <DdtEgds> GetByParentId(string parentId)
        {
            IList <DdtEgds> list = new List <DdtEgds>();

            if (parentId == null)
            {
                return(list);
            }
            using (dynamic connection = connectionFactory.GetConnection())
            {
                String sql = String.Format("SELECT dsid_hospitality_session, eg.r_object_id, dsdt_analysis_date, r_modify_date, dss_egds, eg.dss_parent_type, " +
                                           "r_creation_date, rel.dsid_parent, dsb_admission_analysis, dsid_doctor, dsid_patient FROM ddt_egds eg, ddt_relation rel " +
                                           "WHERE rel.dsid_parent = '{0}' AND rel.dsid_child=eg.r_object_id", parentId);

                Logger.Debug(CultureInfo.CurrentCulture, "SQL: {0}", sql);

                Npgsql.NpgsqlCommand command = new Npgsql.NpgsqlCommand(sql, connection);
                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        DdtEgds obj = new DdtEgds();
                        obj.HospitalitySession = reader.IsDBNull(0) ? null : reader.GetString(0);
                        obj.ObjectId           = reader.IsDBNull(1) ? null : reader.GetString(1);
                        obj.AnalysisDate       = reader.IsDBNull(2) ? DateTime.MinValue : reader.GetDateTime(2);
                        obj.ModifyDate         = reader.IsDBNull(3) ? DateTime.MinValue : reader.GetDateTime(3);
                        obj.Egds              = reader.IsDBNull(4) ? null : reader.GetString(4);
                        obj.ParentType        = reader.IsDBNull(5) ? null : reader.GetString(5);
                        obj.CreationDate      = reader.IsDBNull(6) ? DateTime.MinValue : reader.GetDateTime(6);
                        obj.Parent            = reader.IsDBNull(7) ? null : reader.GetString(7);
                        obj.AdmissionAnalysis = reader.GetBoolean(8);
                        obj.Doctor            = reader.IsDBNull(9) ? null : reader.GetString(9);
                        obj.Patient           = reader.IsDBNull(10) ? null : reader.GetString(10);
                        list.Add(obj);
                    }
                }
            }
            return(list);
        }
        public void saveObject(DdtHospital hospitalitySession, string parentId, string parentType)
        {
            if (isEditable && (isDirty() || isNew && getIsValid()))
            {
                DdtEgds egds = (DdtEgds)getObject();
                egds.HospitalitySession = hospitalitySession.ObjectId;
                egds.Doctor             = hospitalitySession.CuringDoctor;
                egds.Patient            = hospitalitySession.Patient;
                if (parentId != null)
                {
                    egds.Parent = parentId;
                }
                if (parentType != null)
                {
                    egds.ParentType = parentType;
                }

                objectId   = DbDataService.GetInstance().GetDdtEgdsService().Save(egds);
                hasChanges = false;
                isNew      = false;
            }
        }