Пример #1
0
        public IList <DdtCureType> GetAll()
        {
            IList <DdtCureType> list = new List <DdtCureType>();

            using (dynamic connection = connectionFactory.GetConnection())
            {
                String sql = "SELECT r_object_id, r_modify_date, r_creation_date, dss_name FROM ddt_cure_type";

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

                Npgsql.NpgsqlCommand command = new Npgsql.NpgsqlCommand(sql, connection);
                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        DdtCureType obj = new DdtCureType();
                        obj.ObjectId     = reader.IsDBNull(0) ? null : reader.GetString(0);
                        obj.ModifyDate   = reader.IsDBNull(1) ? DateTime.MinValue : reader.GetDateTime(1);
                        obj.CreationDate = reader.IsDBNull(2) ? DateTime.MinValue : reader.GetDateTime(2);
                        obj.Name         = reader.IsDBNull(3) ? null : reader.GetString(3);
                        list.Add(obj);
                    }
                }
            }
            return(list);
        }
Пример #2
0
        public string Save(DdtCureType obj)
        {
            using (dynamic connection = connectionFactory.GetConnection())
            {
                if (GetById(obj.ObjectId) != null)
                {
                    string sql = "UPDATE ddt_cure_type SET " +
                                 "dss_name = @Name " +
                                 "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("@Name", obj.Name);
                        cmd.Parameters.AddWithValue("@ObjectId", obj.ObjectId);
                        cmd.ExecuteNonQuery();
                    }
                    return(obj.ObjectId);
                }
                else
                {
                    string sql = "INSERT INTO ddt_cure_type(dss_name) " +
                                 "VALUES(@Name) 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("@Name", obj.Name);
                        return((string)cmd.ExecuteScalar());
                    }
                }
            }
        }
Пример #3
0
        public DdtCureType GetById(string id)
        {
            using (dynamic connection = connectionFactory.GetConnection())
            {
                String sql = String.Format("SELECT r_object_id, r_modify_date, r_creation_date, dss_name FROM ddt_cure_type 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())
                    {
                        DdtCureType obj = new DdtCureType();
                        obj.ObjectId     = reader.IsDBNull(0) ? null : reader.GetString(0);
                        obj.ModifyDate   = reader.IsDBNull(1) ? DateTime.MinValue : reader.GetDateTime(1);
                        obj.CreationDate = reader.IsDBNull(2) ? DateTime.MinValue : reader.GetDateTime(2);
                        obj.Name         = reader.IsDBNull(3) ? null : reader.GetString(3);
                        return(obj);
                    }
                }
            }
            return(null);
        }
Пример #4
0
        private void AddIssuedMedicine(DdtIssuedMedicine med, DdtCure cure)
        {
            medicineList.Add(med);

            FlowLayoutPanel ll = new FlowLayoutPanel();

            ll.FlowDirection = FlowDirection.LeftToRight;
            ll.Width         = 700;
            ll.AutoSize      = true;
            ll.Padding       = new Padding(0);
            ll.Margin        = new Padding(0);

            ComboBox cureTypeControl = new ComboBox();

            cureTypeControl.Width = 250;
            CommonUtils.InitCureTypeComboboxValues(DbDataService.GetInstance(), cureTypeControl);
            if (cure != null && cure.CureType != null)
            {
                for (int index = 0; index < cureTypeControl.Items.Count; index++)
                {
                    DdtCureType ct = (DdtCureType)cureTypeControl.Items[index];
                    if (ct.ObjectId == cure.CureType)
                    {
                        cureTypeControl.SelectedIndex = index;
                        break;
                    }
                }
            }
            ll.Controls.Add(cureTypeControl);

            ComboBox cureControl = new ComboBox();

            cureControl.Width = 350;

            DdtCureType cureType = (DdtCureType)cureTypeControl.SelectedItem;

            if (cureType != null)
            {
                CommonUtils.InitCureComboboxValuesByTypeId(DbDataService.GetInstance(), cureControl, cureType.ObjectId);
            }

            if (cure != null && cure.ObjectId != null)
            {
                for (int index = 0; index < cureControl.Items.Count; index++)
                {
                    DdtCure c = (DdtCure)cureControl.Items[index];
                    if (c.ObjectId == cure.ObjectId)
                    {
                        cureControl.SelectedIndex = index;
                        break;
                    }
                }
            }
            cureControl.SelectedIndexChanged += delegate(object sender2, EventArgs args)
            {
                DdtCure ddtCure = (DdtCure)cureControl.SelectedItem;
                if (ddtCure != null)
                {
                    med.Cure = ddtCure.ObjectId;
                }
                else
                {
                    med.Cure = null;
                }
            };
            ll.Controls.Add(cureControl);

            cureTypeControl.SelectedIndexChanged += delegate(object sender2, EventArgs args)
            {
                DdtCureType selectedVal = (DdtCureType)cureTypeControl.SelectedItem;
                CommonUtils.InitCureComboboxValuesByTypeId(DbDataService.GetInstance(), cureControl, selectedVal.ObjectId);
            };

            Button remove = new Button
            {
                Image = Properties.Resources.remove,
                Size  = new Size(25, 25),
                UseVisualStyleBackColor = true
            };

            ll.Controls.Add(remove);

            remove.Click += delegate(object sender2, EventArgs args)
            {
                medicineList.Remove(med);
                layout.Controls.Remove(ll);
            };
            layout.Controls.Add(ll);
        }