Inheritance: Gtk.DrawingArea
Ejemplo n.º 1
0
        public void UpdateList()
        {
            foreach(Widget wid in vboxImages.Children )
            {
                wid.Destroy ();
                vboxImages.Remove (wid);
            }

            foreach(Pixbuf pix in Images)
            {
                ImageViewer view = new ImageViewer();
                view.VerticalFit = false;
                view.HorizontalFit = true;
                view.Pixbuf = pix;
                //view.ButtonPressEvent += OnImagesButtonPressEvent;
                vboxImages.Add(view);
            }
            vboxImages.ShowAll ();
        }
Ejemplo n.º 2
0
        public void Fill(int doc_id)
        {
            QSMain.CheckConnectionAlive();
            logger.Info("Запрос документа №" + doc_id +"...");
            try
            {
                DocId = doc_id;

                string sql = "SELECT docs.*, users.name as username FROM docs " +
                    "LEFT JOIN users ON users.id = docs.user_id " +
                    "WHERE docs.id = @id";
                MySqlCommand cmd = new MySqlCommand(sql, QSMain.connectionDB);
                cmd.Parameters.AddWithValue("@id", DocId);
                MySqlDataReader rdr = cmd.ExecuteReader();

                if(!rdr.Read())
                    return;

                entryNumber.Text = rdr.GetString ("number");
                int DocType = rdr.GetInt32("type_id");
                dateDoc.Date = rdr.GetDateTime("date");
                labelCreateDate.LabelProp = String.Format("{0}", rdr.GetDateTime("create_date"));
                labelCreateUser.LabelProp = rdr.GetString("username");
                if(rdr["comments"] != DBNull.Value)
                    textviewComments.Buffer.Text = rdr.GetString("comments");

                rdr.Close();

                DocInfo = new DocumentInformation(DocType);
                this.Title = DocInfo.TypeName + " №" + entryNumber.Text + " от " + dateDoc.DateText;
                labelType.LabelProp = DocInfo.TypeName;

                //Дополнительные поля
                if(DocInfo.CountExtraFields > 0)
                {
                    FieldLables = new Dictionary<int, Label>();
                    FieldWidgets = new Dictionary<int, object>();
                    uint Row = 5;
                    foreach(DocFieldInfo field in DocInfo.FieldsList)
                    {
                        Label NameLable = new Label(field.Name + ":");
                        NameLable.Xalign = 1;
                        tableProperty.Attach(NameLable, 0, 1, Row, Row+1,
                                                 AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                        FieldLables.Add(field.ID, NameLable);
                        object ValueWidget;
                        switch (field.Type) {
                            case "varchar" :
                            ValueWidget = new Entry();
                            ((Entry)ValueWidget).IsEditable = QSMain.User.Permissions["can_edit"];
                            break;
                            default :
                            ValueWidget = new Label();
                            break;
                        }
                        tableProperty.Attach((Widget)ValueWidget, 1, 2, Row, Row+1,
                                                 AttachOptions.Fill, AttachOptions.Fill, 0, 0);
                        FieldWidgets.Add(field.ID, ValueWidget);

                        Row++;
                    }
                    tableProperty.ShowAll();

                    //Заполняем данными документа
                    sql = "SELECT * FROM extra_" + DocInfo.DBTableName +
                        " WHERE doc_id = @doc_id";
                    cmd = new MySqlCommand(sql, QSMain.connectionDB);
                    cmd.Parameters.AddWithValue("@doc_id", DocId);
                    rdr = cmd.ExecuteReader();
                    rdr.Read();

                    foreach(DocFieldInfo field in DocInfo.FieldsList)
                    {
                        if(rdr[field.DBName] == DBNull.Value)
                            continue;

                        switch (field.Type) {
                            case "varchar" :
                            ((Entry)FieldWidgets[field.ID]).Text = rdr.GetString(field.DBName);
                            ((Entry)FieldWidgets[field.ID]).TooltipText = rdr.GetString(field.DBName);
                            break;
                            default:
                            Console.WriteLine("Неизвестный тип поля");
                            break;
                        }
                    }
                    rdr.Close();
                }
                // Загружаем изображения
                sql = "SELECT * FROM images " +
                    "WHERE doc_id = @doc_id " +
                    "ORDER BY order_num";
                cmd = new MySqlCommand(sql, QSMain.connectionDB);
                cmd.Parameters.AddWithValue("@doc_id", DocId);
                rdr = cmd.ExecuteReader();

                while( rdr.Read())
                {
                    DocumentImage DocImage = new DocumentImage();
                    DocImage.Changed = false;
                    DocImage.id = rdr.GetInt32("id");
                    DocImage.order = rdr.GetInt32("order_num");
                    DocImage.size = rdr.GetInt64("size");
                    DocImage.type = rdr.GetString("type");
                    DocImage.file = new byte[DocImage.size];
                    rdr.GetBytes(rdr.GetOrdinal("image"), 0, DocImage.file, 0, (int) DocImage.size);
                    DocImage.Image = new Pixbuf(DocImage.file);

                    //Добавляем вижет
                    ImageViewer view = new ImageViewer();
                    view.VerticalFit = false;
                    view.HorizontalFit = true;
                    view.Pixbuf = DocImage.Image;
                    view.ButtonPressEvent += OnImagesButtonPressEvent;
                    vboxImages.Add(view);
                    DocImage.Widget = view;
                    Images.Add(DocImage);
                }
                rdr.Close();
                vboxImages.ShowAll();
                logger.Info("Ok");
            }
            catch (Exception ex)
            {
                QSMain.ErrorMessageWithLog(this, "Ошибка получения документа!", logger, ex);
            }
        }