Esempio n. 1
0
        private ImageReference AddImage(string fileName)
        {
            ImageReference r = this.Database.Images[fileName];

            if (r == null)
            {
                r = ImageReference.CreateImageReference(fileName, this.ImagesPath);
                if (r == null)
                {
                    return(null);
                }
                else
                {
                    this.Database.Images.Add(r);
                }
            }
            else
            {
                if (r.CheckImages(this.ImagesPath))
                {
                    this.Database.Images.Update(r);
                }
            }

            this.Images.Add(r);
            Image b = new Bitmap(r.Image);

            this.pictureBox1.Image = b;

            return(r);
        }
Esempio n. 2
0
        private void AddImage(string fileName)
        {
            ImageReference r = this.Database.Images[fileName];

            if (r == null)
            {
                r = ImageReference.CreateImageReference(fileName, this.ImagesPath);
                if (r == null)
                {
                    return;
                }
                else
                {
                    this.Database.Images.Add(r);
                }
            }
            else
            {
                if (r.CheckImages(this.ImagesPath))
                {
                    this.Database.Images.Update(r);
                }
            }

            this.Current = r;
            this.Images.Add(this.Current);
            this.currentImage = new Bitmap(this.Current.Image);
            Invalidate();
        }
Esempio n. 3
0
        private void DrawContent(Graphics g)
        {
            int   width_names  = this.GetWidthNames(g);
            SizeF sizeCategory = g.MeasureString(this.headerText, this.fontHeader);
            float y            = sizeCategory.Height + 14;

            foreach (Field field in this.values.Keys)
            {
                float x_name  = 3;
                float x_value = width_names + 11;
                int   h_value = this.GetHeightValue(g, field);
                if (!field.IsPageField)
                {
                    StringFormat format = new StringFormat();
                    format.LineAlignment = StringAlignment.Center;
                    g.DrawString(field.Name, this.fontName, this.textBrush, new RectangleF(x_name, y, width_names + 1, h_value), format);
                    int w_value = Width - 6 - width_names;
                    switch (field.FieldType)
                    {
                    case FieldType.Boolean:
                        g.DrawImage(Resources.tick, new PointF(x_value, y + (h_value - 16) / 2));
                        break;

                    case FieldType.Date:
                        DateTime     dt    = (DateTime)this.values[field];
                        DateProperty dprop = field.Data as DateProperty;
                        string       date_format;
                        if (dprop.ViewTime)
                        {
                            date_format = "d MMM yyy H:mm:ss";
                        }
                        else
                        {
                            date_format = "d MMM yyy";
                        }

                        g.DrawString(dt.ToString(date_format), this.fontValue, this.textBrush, new RectangleF(x_value, y, w_value, h_value), format);
                        break;

                    case FieldType.Select:
                        int           val = (int)this.values[field];
                        List <string> sc  = (List <string>)field.Data;
                        if (val < sc.Count)
                        {
                            g.DrawString(sc[val], this.fontValue, this.textBrush, new RectangleF(x_value, y, w_value, h_value), format);
                        }

                        break;

                    case FieldType.Rating:
                        this.DrawContentRaiting(g, (decimal)this.values[field], new PointF(x_value, y + (h_value - 16) / 2));
                        break;

                    case FieldType.Reference:
                        ObjectData or      = (ObjectData)this.values[field];
                        PointF     pr      = new PointF(x_value, y);
                        SizeF      sizeRef = g.MeasureString(or.ToString(), this.fontValue);
                        float      dRef    = (h_value - sizeRef.Height) / 2;
                        g.DrawString(or.ToString(), this.fontValue, this.selectedBrush, new RectangleF(pr, new SizeF(w_value, h_value)), format);
                        pr.Y += dRef;
                        this.refs.Add(new ReferenceData(new RectangleF(pr, sizeRef), or, ReferenceType.ObjectData));
                        break;

                    case FieldType.Url:
                        string url = this.values[field].ToString();
                        pr = new PointF(x_value, y);
                        g.DrawString(url, this.fontValue, this.selectedBrush, new RectangleF(pr, new SizeF(w_value, h_value)), format);
                        SizeF sizeUrl = g.MeasureString(url, this.fontName);
                        this.refs.Add(new ReferenceData(new RectangleF(pr, sizeUrl), url, ReferenceType.Url));
                        break;

                    case FieldType.Number:
                        decimal        res      = (decimal)this.values[field];
                        NumberProperty num_prop = field.Data as NumberProperty;
                        g.DrawString(res.ToString(num_prop.Format), this.fontValue, this.textBrush, new RectangleF(x_value, y, w_value, h_value), format);
                        break;

                    default:
                        g.DrawString(this.values[field].ToString(), this.fontValue, this.textBrush, new RectangleF(x_value, y, w_value, h_value), format);
                        break;
                    }

                    y += h_value + 9;
                }
                else
                {
                    switch (field.FieldType)
                    {
                    case FieldType.Table:
                        TableData td         = (TableData)this.values[field];
                        SizeF     sizeHeader = g.MeasureString(field.Name, this.fontName);
                        SizeF     sizeRow    = g.MeasureString("A" /*td.First.Data.ToString()*/, this.fontValue);
                        SizeF     sizeTable  = new SizeF(Width - 6, sizeHeader.Height + 5 + (sizeRow.Height + 5) * td.RowCount + 1);

                        float y_t = y;
                        float x_t = x_name + 2;
                        foreach (ColumnProperty cp in td.Columns)
                        {
                            y_t = y + 3;

                            // заголовок
                            g.DrawString(cp.Name, this.fontName, this.textBrush, new PointF(x_t, y_t));
                            SizeF sizeCol = g.MeasureString(cp.Name, this.fontName);
                            y_t += sizeCol.Height + 5;
                            for (int r = 0; r < td.RowCount; r++)
                            {
                                object o = td[r][cp].Data;
                                if (o == null)
                                {
                                    continue;
                                }

                                PointF pf = new PointF(x_t, y_t);
                                SizeF  sizeN;
                                if (string.IsNullOrEmpty(o.ToString()))
                                {
                                    sizeN = g.MeasureString("A", this.fontValue);
                                }
                                else
                                {
                                    sizeN = g.MeasureString(o.ToString(), this.fontValue);
                                    if (o is ObjectData)
                                    {
                                        this.refs.Add(new ReferenceData(new RectangleF(pf, sizeN), o, ReferenceType.ObjectData));
                                        g.DrawString(o.ToString(), this.fontValue, this.selectedBrush, pf);
                                    }
                                    else
                                    {
                                        g.DrawString(o.ToString(), this.fontValue, this.textBrush, pf);
                                    }
                                }

                                if (sizeN.Width > sizeCol.Width)
                                {
                                    sizeCol.Width = sizeN.Width;
                                }

                                y_t += sizeN.Height + 5;
                            }

                            x_t += sizeCol.Width + 6;
                        }

                        break;

                    case FieldType.Memo:
                        string s    = (string)this.values[field];
                        SizeF  size = g.MeasureString(s, this.fontValue, Width - 6);
                        g.DrawString(s, this.fontValue, this.textBrush, new RectangleF(new PointF(x_name, y), size));
                        break;

                    case FieldType.List:
                        ListData sc = (ListData)this.values[field];
                        float    yc = y;
                        foreach (ObjectData sl in sc.Objects)
                        {
                            PointF pf = new PointF(x_name, yc);
                            g.DrawString(sl.ToString(), this.fontValue, this.selectedBrush, pf);
                            SizeF sizeList = g.MeasureString(sl.ToString(), this.fontValue);
                            yc += sizeList.Height;
                            this.refs.Add(new ReferenceData(new RectangleF(pf, sizeList), sl, ReferenceType.ObjectData));
                        }

                        break;

                    case FieldType.Image:
                        ImageData id = (ImageData)this.values[field];
                        float     xi = x_name;
                        float     yi = y;
                        foreach (string key in id.Images)
                        {
                            string         pathImages = MainForm.AppDir + @"\images";
                            ImageReference ir         = this.database.Images[key];
                            if (ir == null)
                            {
                                ir = ImageReference.CreateImageReference(key, pathImages);
                                if (ir != null)
                                {
                                    this.database.Images.Add(ir);
                                }
                            }
                            else
                            {
                                if (ir.CheckImages(pathImages))
                                {
                                    this.database.Images.Update(ir);
                                }

                                if (string.IsNullOrEmpty(ir.Copy))
                                {
                                    ir = null;
                                }
                            }

                            if (ir == null)
                            {
                                continue;
                            }

                            int w = WidthImage;
                            int h = HeightImage;

                            Image im = null;

                            if (File.Exists(ir.Thumbnail))
                            {
                                im = new Bitmap(ir.Thumbnail);
                                if (im.Width > im.Height)
                                {
                                    h = h * im.Height / im.Width;
                                }
                                else
                                {
                                    w = w * im.Width / im.Height;
                                }
                            }
                            else
                            {
                                Bitmap original = new Bitmap(ir.Image);
                                double k        = (double)original.Width / (double)original.Height;

                                if (k > 1)
                                {
                                    h = (int)Math.Round(WidthImage / k);
                                }
                                else if (k < 1)
                                {
                                    w = (int)Math.Round(HeightImage * k);
                                }

                                im = original.GetThumbnailImage(w, h, null, IntPtr.Zero);
                            }

                            int dx = 0;
                            int dy = 0;
                            if (w > h)
                            {
                                dy = (HeightImage - h) / 2;
                            }
                            else
                            {
                                dx = (WidthImage - w) / 2;
                            }

                            RectangleF rf = new RectangleF(xi + dx, yi + dy, w, h);
                            g.DrawImage(im, rf);
                            this.refs.Add(new ReferenceData(new RectangleF(rf.Location, rf.Size), ir.Image, ReferenceType.Image));
                            xi += WidthImage + DividerImage;
                            if (xi + WidthImage + DividerImage > Width)
                            {
                                xi  = x_name;
                                yi += HeightImage + DividerImage;
                            }
                        }

                        break;
                    }
                }
            }
        }