/// <summary>
 /// 删除组件
 /// </summary>
 /// <param name="_mode">是否记录</param>
 public static void Delete_Control(bool _record)
 {
     if (DraggableObjects.Count > 0)
     {
         DraggableObjects.Remove(DraggableObjects[control_Num]);
         if (DraggableObjects.Count < 1)
         {
             control_Num = -1;
             RBuild_Info.Set_DefaultInfo();
         }
         else
         {
             control_Num -= 1;
             if (control_Num < 0)
             {
                 control_Num = 0;
             }
             DraggableObjects[control_Num].Setimage = LinBox(DraggableObjects[control_Num].Region.Width, DraggableObjects[control_Num].Region.Height, 1, DraggableObjects[control_Num].ControlType, control_Num);
             RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);
             DraggableObjects[control_Num].IsDragging = false;
             if (_record)
             {
                 Object_Record();
             }
         }
         page_Install.Invalidate();
         page_Container.Invalidate();
         Print_PageType.Invalidate();
         RBuild_MouseEvent.CursorFlag = -1;
         ReportChange_Flag            = true;
     }
 }
 public static void PageType_MouseClick(object sender, MouseEventArgs e)
 {
     for (int i = DraggableObjects.Count - 1; i >= 0; i--)
     {
         if (DraggableObjects[i].Region.Contains(e.Location))
         {
             if (i != control_Num)
             {
                 DraggableObjects[control_Num].Setimage = LinBox(
                     DraggableObjects[control_Num].Region.Width,
                     DraggableObjects[control_Num].Region.Height,
                     0,
                     DraggableObjects[control_Num].ControlType, control_Num
                     );
                 control_Num = i;
                 DraggableObjects[i].Setimage = LinBox(
                     DraggableObjects[i].Region.Width,
                     DraggableObjects[i].Region.Height,
                     1,
                     DraggableObjects[i].ControlType, i
                     );
                 Print_PageType.Invalidate();
                 RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);
                 break;
             }
             else
             {
                 break;
             }
         }
     }
 }
    /// <summary>
    /// 粘贴组件
    /// </summary>
    /// <param name="lx">粘贴位置 x</param>
    /// <param name="ly">粘贴位置 y</param>
    public static void Object_OperationPast(int lx, int ly)
    {
        if ((operationObject.Id != null) && (band_Num != -1))
        {
            if (control_Num > -1)
            {
                DraggableObjects[control_Num].Setimage = LinBox(
                    DraggableObjects[control_Num].Region.Width,
                    DraggableObjects[control_Num].Region.Height,
                    0,
                    DraggableObjects[control_Num].ControlType, control_Num
                    );
            }
            operationObject.Region = new Rectangle(
                DraggableBandObjects[band_Num].Region.Left + lx,
                DraggableBandObjects[band_Num].Region.Top + ly,
                operationObject.Region.Width,
                operationObject.Region.Height
                );
            Draggable draggableBlock = new Draggable(operationObject.Region.Left, operationObject.Region.Top, operationObject.ControlType);

            draggableBlock.Id                  = GetMd5Str16(DateTime.Now.ToString());
            draggableBlock.Belong_Band         = band_Num;
            draggableBlock.Region              = operationObject.Region;
            draggableBlock.Setimage            = operationObject.Setimage;
            draggableBlock.isContent           = operationObject.isContent;
            draggableBlock.Field_Img           = operationObject.Field_Img;
            draggableBlock.Field_Text          = operationObject.Field_Text;
            draggableBlock.Field_Calculate     = operationObject.Field_Calculate;
            draggableBlock.Field_TextFont      = operationObject.Field_TextFont;
            draggableBlock.Field_TextFontSize  = operationObject.Field_TextFontSize;
            draggableBlock.Field_TextFontStyle = operationObject.Field_TextFontStyle;
            draggableBlock.Field_Align         = operationObject.Field_Align;
            draggableBlock.Field_ImgZoom       = operationObject.Field_ImgZoom;
            for (int i = 0; i < 8; i++)
            {
                draggableBlock.Field_BoxLine[i] = operationObject.Field_BoxLine[i];
            }
            draggableBlock.Field_LineColor     = operationObject.Field_LineColor;
            draggableBlock.Field_LineThickness = operationObject.Field_LineThickness;
            draggableBlock.Field_LineType      = operationObject.Field_LineType;
            draggableBlock.Field_Shape         = operationObject.Field_Shape;
            draggableBlock.Field_ControlColor  = operationObject.Field_ControlColor;
            draggableBlock.Field_BackColor     = operationObject.Field_BackColor;

            control_Num = DraggableObjects.Count;
            DraggableObjects.Add(draggableBlock);
            Print_PageType.Invalidate();
            Object_Record();
            RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);
            ReportChange_Flag = true;
        }
    }
    // 打开文件
    public static void Open_File()
    {
        OpenFileDialog ofd = new OpenFileDialog();

        ofd.Filter           = "报表文件(*.rpt)|*.rpt";
        ofd.FilterIndex      = 1;
        ofd.RestoreDirectory = true;

        if (ofd.ShowDialog() == DialogResult.OK)
        {
            if (ReportChange_Flag)
            {
                DialogResult _save = MessageBox.Show("是否保存报表文件?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (_save.ToString().Equals("Yes"))
                {
                    Save_File();
                }
                if (_save.ToString().Equals("Cancel"))
                {
                    return;
                }
            }
            SerializerObject.Clear();
            string localFilePath = ofd.FileName.ToString();
            ReportFile_Name.Text = localFilePath;
            try
            {
                SerializerObject = Serializer.FileToObject <List <OperationObject> >(localFilePath);

                DraggableObjects.Clear();
                recordObjects.Clear();
                control_Num = -1;

                int _select = 0;
                for (int i = 0; i < SerializerObject.Count; i++)
                {
                    Draggable draggableBlock = new Draggable(SerializerObject[i].Region.Left, SerializerObject[i].Region.Top, SerializerObject[i].ControlType);
                    draggableBlock.Id          = SerializerObject[i].Id;
                    draggableBlock.Belong_Band = SerializerObject[i].Belong_Band;
                    draggableBlock.Region      = SerializerObject[i].Region;
                    draggableBlock.isContent   = SerializerObject[i].isContent;
                    if (SerializerObject[i].ControlType == 2)
                    {
                        draggableBlock.Field_Img = Base64StringToImage(SerializerObject[i].Field_ImgBase64);
                    }
                    draggableBlock.Field_Text          = SerializerObject[i].Field_Text;
                    draggableBlock.Field_Calculate     = SerializerObject[i].Field_Calculate;
                    draggableBlock.Field_TextFont      = SerializerObject[i].Field_TextFont;
                    draggableBlock.Field_TextFontSize  = SerializerObject[i].Field_TextFontSize;
                    draggableBlock.Field_TextFontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), SerializerObject[i].Field_TextFontStyleString);
                    draggableBlock.Field_Align         = SerializerObject[i].Field_Align;
                    draggableBlock.Field_ImgZoom       = SerializerObject[i].Field_ImgZoom;
                    for (int t = 0; t < 8; t++)
                    {
                        draggableBlock.Field_BoxLine[t] = SerializerObject[i].Field_BoxLine[t];
                    }
                    draggableBlock.Field_LineColor     = ColorTranslator.FromHtml(SerializerObject[i].Field_LineColorString);
                    draggableBlock.Field_LineThickness = SerializerObject[i].Field_LineThickness;
                    draggableBlock.Field_LineType      = SerializerObject[i].Field_LineType;
                    draggableBlock.Field_Shape         = SerializerObject[i].Field_Shape;
                    draggableBlock.Field_ControlColor  = ColorTranslator.FromHtml(SerializerObject[i].Field_ControlColorString);
                    draggableBlock.Field_BackColor     = ColorTranslator.FromHtml(SerializerObject[i].Field_BackColorString);
                    DraggableObjects.Add(draggableBlock);

                    control_Num = i;
                    if (i == SerializerObject.Count - 1)
                    {
                        _select = 1;
                    }
                    DraggableObjects[i].Setimage = LinBox(SerializerObject[i].Region.Width, SerializerObject[i].Region.Height, _select, SerializerObject[i].ControlType, i);
                }

                page_TypeFace = SerializerObject[0].page_Type;
                _pgselect     = page_TypeFace.Page_Type;

                for (int i = 0; i < 3; i++)
                {
                    DraggableBandObjects[i].Region = SerializerObject[0].Band_Region[i];
                }

                Print_PageType.Size = page_TypeFace.Page_Area;

                int _iLeft = (page_Container.Width / 2) - (page_TypeFace.Page_Area.Width / 2);
                if (_iLeft < 0)
                {
                    _iLeft = 0;
                }
                page_Install.Size     = new Size(page_TypeFace.Page_Area.Width + 20, page_TypeFace.Page_Area.Height + 20);
                page_Install.Location = new Point(_iLeft, 0);

                // 设置预览页面大小
                PreViewPage_Area = new Size(page_TypeFace.Page_Area.Width, page_TypeFace.Page_Area.Height - 126);

                Print_PageType.Invalidate();
                RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);

                ReportChange_Flag = false;
            }

            catch
            {
                MessageBox.Show("报表打开错误!");
            }
        }
    }
    /// <summary>
    /// 撤销、重做
    /// </summary>
    /// <param name="_mode">模式</param>
    public static void Object_Operation(int _mode)
    {
        bool Oper = false;

        if (_mode == 0) // 撤销
        {
            oper_Record -= 1;
            if (oper_Record < 0)
            {
                Oper        = false;
                oper_Record = 0;
            }
            else
            {
                Oper = true;
            }
        }
        else
        if (_mode == 1) // 重做
        {
            oper_Record += 1;
            if (oper_Record >= recordObjects.Count)
            {
                Oper        = false;
                oper_Record = recordObjects.Count - 1;
            }
            else
            {
                Oper = true;
            }
        }

        if (Oper)
        {
            DraggableObjects.Clear();
            for (int i = 0; i < recordObjects[oper_Record].Count; i++)
            {
                Draggable draggableBlock = new Draggable(recordObjects[oper_Record][i].Region.Left, recordObjects[oper_Record][i].Region.Top, recordObjects[oper_Record][i].ControlType);

                draggableBlock.Id                  = recordObjects[oper_Record][i].Id;
                draggableBlock.Belong_Band         = recordObjects[oper_Record][i].Belong_Band;
                draggableBlock.Region              = recordObjects[oper_Record][i].Region;
                draggableBlock.Setimage            = recordObjects[oper_Record][i].Setimage;
                draggableBlock.isContent           = recordObjects[oper_Record][i].isContent;
                draggableBlock.Field_Img           = recordObjects[oper_Record][i].Field_Img;
                draggableBlock.Field_Text          = recordObjects[oper_Record][i].Field_Text;
                draggableBlock.Field_Calculate     = recordObjects[oper_Record][i].Field_Calculate;
                draggableBlock.Field_TextFont      = recordObjects[oper_Record][i].Field_TextFont;
                draggableBlock.Field_TextFontSize  = recordObjects[oper_Record][i].Field_TextFontSize;
                draggableBlock.Field_TextFontStyle = recordObjects[oper_Record][i].Field_TextFontStyle;
                draggableBlock.Field_Align         = recordObjects[oper_Record][i].Field_Align;
                draggableBlock.Field_ImgZoom       = recordObjects[oper_Record][i].Field_ImgZoom;
                for (int t = 0; t < 8; t++)
                {
                    draggableBlock.Field_BoxLine[t] = recordObjects[oper_Record][i].Field_BoxLine[t];
                }
                draggableBlock.Field_LineColor     = recordObjects[oper_Record][i].Field_LineColor;
                draggableBlock.Field_LineThickness = recordObjects[oper_Record][i].Field_LineThickness;
                draggableBlock.Field_LineType      = recordObjects[oper_Record][i].Field_LineType;
                draggableBlock.Field_Shape         = recordObjects[oper_Record][i].Field_Shape;
                draggableBlock.Field_ControlColor  = recordObjects[oper_Record][i].Field_ControlColor;
                draggableBlock.Field_BackColor     = recordObjects[oper_Record][i].Field_BackColor;

                DraggableObjects.Add(draggableBlock);
            }
            control_Num = recordObjects[oper_Record][0].Num;
            for (int i = 0; i < 3; i++)
            {
                DraggableBandObjects[i].Region = recordObjects[oper_Record][0].Band_Region[i];
            }

            Print_PageType.Invalidate();
            RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);
            ReportChange_Flag = true;
        }
    }
    public static void PageType_Click(object sender, EventArgs e)
    {
        PanelEx pL = (PanelEx)sender;

        bool is_band = false;

        for (int i = 0; i < 3; i++)
        {
            is_band = false;
            if ((A4location_XY.X >= 0) && (A4location_XY.X <= Print_PageType.Width) &&
                (A4location_XY.Y >= DraggableBandObjects[i].Region.Top + 20) && (A4location_XY.Y <= DraggableBandObjects[i].Region.Bottom - 20))
            {
                is_band = true;
                break;
            }
        }

        if ((control_Type != -1) && (is_band))
        {
            if (control_Num > -1)
            {
                DraggableObjects[control_Num].Setimage = LinBox(
                    DraggableObjects[control_Num].Region.Width,
                    DraggableObjects[control_Num].Region.Height,
                    0,
                    DraggableObjects[control_Num].ControlType, control_Num
                    );
            }
            Point _Location = A4location_XY;

            control_Num = DraggableObjects.Count;

            if ((_Location.X + 51) > Print_PageType.Width)
            {
                _Location.X = Print_PageType.Width - 51;
            }
            if ((_Location.Y + 51) > DraggableBandObjects[band_Num].Region.Bottom - 20)
            {
                _Location.Y = DraggableBandObjects[band_Num].Region.Bottom - 20 - 51;
            }

            Draggable draggableBlock = new Draggable(_Location.X, _Location.Y, control_Type);
            DraggableObjects.Add(draggableBlock);

            int _width  = 51;
            int _height = 51;

            DraggableObjects[control_Num].Belong_Band        = band_Num;
            DraggableObjects[control_Num].Field_Align        = "Left,Top";
            DraggableObjects[control_Num].Field_TextFont     = "微软雅黑";
            DraggableObjects[control_Num].Field_ControlColor = Color.FromArgb(0, 0, 0);
            DraggableObjects[control_Num].Field_TextFontSize = 9;
            DraggableObjects[control_Num].Field_ImgZoom      = 1;

            for (int i = 0; i < 8; i++)
            {
                DraggableObjects[control_Num].Field_BoxLine[i] = false;
            }
            DraggableObjects[control_Num].Setimage = LinBox(_width, _height, 1, control_Type, control_Num);
            control_Type = -1;
            Print_PageType.Invalidate();

            RBuild_Info.set_Info(DraggableObjects[control_Num].ControlType);

            Object_Record();
            ReportChange_Flag = true;
        }
    }