示例#1
0
        public void Fill(int doc_id)
        {
            MainClass.StatusMessage("Запрос документа №" + 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);
                    //Добавляем вижет
                    DocImage.Widget = new Gtk.Image();

                    double hratio = scrolledImages.Hadjustment.PageSize / DocImage.Image.Width;
                    int Heigth = Convert.ToInt32(DocImage.Image.Height * hratio);
                    int Width = (int)scrolledImages.Hadjustment.PageSize;
                    DocImage.Widget.Pixbuf = DocImage.Image.ScaleSimple (Width,
                                                       Heigth,
                                                       InterpType.Bilinear);
                    EventBox Ebox = new EventBox();
                    Ebox.Add(DocImage.Widget);
                    Ebox.ButtonPressEvent += OnImagesButtonPressEvent;
                    EventBoxes.Add(DocImage.id, Ebox);
                    vboxImages.Add(Ebox);
                    Images.Add(DocImage);
                }
                rdr.Close();
                vboxImages.ShowAll();
                MainClass.StatusMessage("Ok");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                MainClass.StatusMessage("Ошибка получения документа!");
                QSMain.ErrorMessage(this,ex);
            }
        }
示例#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.Name + " №" + entryNumber.Text + " от " + dateDoc.DateText;
                labelType.LabelProp = DocInfo.Name;

                //Дополнительные поля
                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);
            }
        }