示例#1
0
        private void DesignPanel_MouseClick(object sender, MouseEventArgs e)
        {
            foreach (CellObject obj in lstobj)
            {
                if (obj.r.Contains(e.X, e.Y))
                {
                    if (obj.obj_type == 301)
                    {
                        IGridable     gridable = this;
                        List <string> lst      = new List <string>();

                        foreach (System.Data.DataColumn col in tb.Columns)
                        {
                            lst.Add(col.ColumnName);
                        }

                        if (gridable.EditGrid(lst.ToArray()) == true)
                        {
                            if (this.dataChange != null)
                            {
                                this.dataChange.Invoke(this, new EventArgs());
                            }
                        }
                        break;
                    }
                }
            }
        }
示例#2
0
        // =======================================
        // Blaine is a pain, and that is the truth
        // =======================================
        public static int TrainCrash(string trackString, string aTrain, int aTrainPos, string bTrain, int bTrainPos, int limit, bool visualise = false)
        {
            Console.WriteLine($"aTrain: {aTrain}. aTrainPos: {aTrainPos}. bTrain: {bTrain}. bTrainPos: {bTrainPos}. Limit {limit}.");
            var grid = new Grid(trackString);

            grid.PrintGrid();

            var start = grid.GetStart();
            var track = TrackBuilder.GetTrack(start, grid);

            var gridables = new IGridable[] { track, new Train(aTrain, aTrainPos, track), new Train(bTrain, bTrainPos, track) };
            var moveables = gridables.OfType <IMoveable>();

            grid.ClearGrid();

            int timer = 0;

            do
            {
                grid.Visualise(gridables, visualise, timer == 0);

                if (moveables.IsCollision())
                {
                    Console.WriteLine($"Collision at time {timer}.");
                    return(timer);
                }

                moveables.MoveAll();
                timer++;
            }while (timer <= limit);

            Console.WriteLine($"No Collision before {timer}.");
            return(-1);
        }
示例#3
0
        private void contextMenuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            this.contextMenuStrip2.Visible = false;
            try
            {
                if (e.ClickedItem.Text == "文本内容")
                {
                    IInput input = new InputString();
                    string def   = "";
                    if (SelectObjects.Count == 1)
                    {
                        IContextable contextable = (IContextable)SelectObjects[0];
                        def = contextable.Context;
                    }
                    if (input.Input(def, out def) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IContextable contextable = (IContextable)ins;
                            contextable.Context = def;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "文本对齐")
                {
                    ISelectContextAlign align = new SelectContextAlign();
                    int def = 0;
                    if (SelectObjects.Count == 1)
                    {
                        IContextAlignAble contextalignable = (IContextAlignAble)SelectObjects[0];
                        def = contextalignable.Align;
                    }
                    if (align.Select(def, out def) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IContextAlignAble contextalignable = (IContextAlignAble)ins;
                            contextalignable.Align = def;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "区域")
                {
                    IInput input = new InputString();
                    int    Area  = -1;
                    if (SelectObjects.Count == 1)
                    {
                        IChangeAreaAble changeareaable = (IChangeAreaAble)SelectObjects[0];
                        Area = changeareaable.Area;
                    }
                    IChangePrintArea printarea = new ChangePrintArea();
                    if (printarea.Change(Area, out Area) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IChangeAreaAble changeareaable = (IChangeAreaAble)ins;
                            changeareaable.Area = Area;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "删除")
                {
                    List <IPrintObject> lst = new List <IPrintObject>();
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        lst.Add(ins);
                    }
                    foreach (IPrintObject ins in lst)
                    {
                        IDeleteable deleteable = (IDeleteable)ins;
                        deleteable.Delete(pnl);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "字体")
                {
                    FontDialog f = new FontDialog();

                    if (SelectObjects.Count == 1)
                    {
                        IFontable fontable = (IFontable)SelectObjects[0];
                        f.Font = fontable.Font;
                    }
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IFontable fontable = (IFontable)ins;
                            fontable.Font = f.Font;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "边框")
                {
                    IEditBorder border       = new EditBorder();
                    int         borderLeft   = 0;
                    int         borderRight  = 0;
                    int         borderTop    = 0;
                    int         borderBottom = 0;
                    if (SelectObjects.Count == 1)
                    {
                        IBorderable borderable = (IBorderable)SelectObjects[0];
                        borderLeft   = borderable.BorderLeft;
                        borderRight  = borderable.BorderRight;
                        borderTop    = borderable.BorderTop;
                        borderBottom = borderable.BorderBottom;
                    }
                    if (border.EditBorder(borderLeft, borderRight, borderTop, borderBottom,
                                          out borderLeft, out borderRight, out borderTop, out borderBottom) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IBorderable borderable = (IBorderable)ins;
                            borderable.BorderLeft   = borderLeft;
                            borderable.BorderRight  = borderRight;
                            borderable.BorderTop    = borderTop;
                            borderable.BorderBottom = borderBottom;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "颜色")
                {
                    ColorDialog f   = new ColorDialog();
                    Color       def = Color.Black;
                    if (SelectObjects.Count == 1)
                    {
                        IColorable colorable = (IColorable)SelectObjects[0];
                        def = colorable.Color;
                    }
                    f.Color = def;
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IColorable colorable = (IColorable)ins;
                            colorable.Color = f.Color;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "左对齐")
                {
                    ISizeable sizeable2 = (ISizeable)_fistSelectObject;
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        ISizeable sizeable = (ISizeable)ins;

                        sizeable.Location = new Point(sizeable2.Location.X, sizeable.Location.Y);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "右对齐")
                {
                    ISizeable sizeable2 = (ISizeable)_fistSelectObject;
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        ISizeable sizeable = (ISizeable)ins;

                        sizeable.Location = new Point((sizeable2.Location.X + sizeable2.Size.Width) - sizeable.Size.Width, sizeable.Location.Y);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "上对齐")
                {
                    ISizeable sizeable2 = (ISizeable)_fistSelectObject;
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        ISizeable sizeable = (ISizeable)ins;

                        sizeable.Location = new Point(sizeable.Location.X, sizeable2.Location.Y);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "下对齐")
                {
                    ISizeable sizeable2 = (ISizeable)_fistSelectObject;
                    foreach (IPrintObject ins in SelectObjects)
                    {
                        ISizeable sizeable = (ISizeable)ins;

                        sizeable.Location = new Point(sizeable.Location.X, (sizeable2.Location.Y + sizeable2.Size.Height) - sizeable.Size.Height);
                    }
                    Record();
                }
                else if (e.ClickedItem.Text == "表格内容")
                {
                    IGridable     gridable = (IGridable)_fistSelectObject;
                    List <string> lst      = new List <string>();

                    if (tbdetail != null)
                    {
                        foreach (System.Data.DataColumn col in tbdetail.Columns)
                        {
                            if (col.ColumnName.StartsWith("#") == false)
                            {
                                lst.Add(col.ColumnName);
                            }
                        }
                    }

                    if (lst.Contains("#") == false)
                    {
                        lst.Add("#");
                    }
                    if (lst.Contains("i") == false)
                    {
                        lst.Add("i");
                    }



                    if (gridable.EditGrid(lst.ToArray()) == true)
                    {
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "表格格式")
                {
                    IGridable gridable = (IGridable)_fistSelectObject;
                    if (gridable.SetStyle() == true)
                    {
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "导入图片")
                {
                    OpenFileDialog f = new OpenFileDialog();
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        var     fileInfo = new System.IO.FileInfo(f.FileName);
                        decimal len      = Conv.ToDecimal(fileInfo.Length);
                        len = len / 1024;
                        if (len > 500)
                        {
                            throw new Exception("图片文件大于500K");
                        }
                        var        img       = Image.FromFile(f.FileName);
                        IImageAble imageable = (IImageAble)_fistSelectObject;
                        imageable.Image = img;
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "导出图片")
                {
                    IImageAble imageable = (IImageAble)_fistSelectObject;
                    if (imageable.Image == null)
                    {
                        throw new Exception("无可导出的图片");
                    }
                    else
                    {
                        SaveFileDialog f = new SaveFileDialog();
                        f.Filter = "*.jpg|*.jpg";
                        if (f.ShowDialog() == DialogResult.OK)
                        {
                            imageable.Image.Save(f.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                    }
                }
                else if (e.ClickedItem.Text == "属性")
                {
                    System.Windows.Forms.MessageBox.Show(_fistSelectObject.propertyInfo, "属性");
                }
                else if (e.ClickedItem.Text == "格式化")
                {
                    IInput input = new InputFormatString();
                    string def   = "";
                    if (SelectObjects.Count == 1)
                    {
                        IFormatable formatable = (IFormatable)SelectObjects[0];
                        def = formatable.Format;
                    }
                    if (input.Input(def, out def) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IFormatable formatable = (IFormatable)ins;
                            formatable.Format = def;
                        }
                        Record();
                    }
                }
                else if (e.ClickedItem.Text == "改字段")
                {
                    string def = "";
                    if (SelectObjects.Count == 1)
                    {
                        IFieldAble fieldable = (IFieldAble)SelectObjects[0];
                        def = fieldable.Field;
                    }
                    IChangeField  chg = new ChangeField();
                    List <string> lst = new List <string>();
                    if (tbmain != null)
                    {
                        foreach (System.Data.DataColumn col in tbmain.Columns)
                        {
                            lst.Add(col.ColumnName);
                        }
                    }
                    if (chg.Change(lst.ToArray(), def, out def) == true)
                    {
                        foreach (IPrintObject ins in SelectObjects)
                        {
                            IFieldAble fieldable = (IFieldAble)ins;
                            fieldable.Field = def;
                        }
                        Record();
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
示例#4
0
        public virtual void Remove(IGridable gr)
        {
            if (gr.Cell != null)
                gr.Cell.Components.Remove(gr);

            Components.Remove(gr);
        }
示例#5
0
 /// <summary>
 /// Return cell that contains specified grid component
 /// </summary>
 /// <param name="gr"></param>
 /// <returns></returns>
 public virtual Cell IndexOf(IGridable gr)
 {
     return IndexOf(gr.GridPosition);
 }
示例#6
0
        public virtual void Add(IGridable gr)
        {
            Cell cell = this.IndexOf(gr.GridPosition);

            if (cell != null)
                cell.Components.Add(gr);

            this.Components.Add(gr);
            gr.Cell = cell;
        }