ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
using HotelPms.Share.Windows.GraphicsApi;
using HotelPms.Share.Windows.Util;
//using NetTopologySuite.Operation.Buffer;
using Org.BouncyCastle.Bcpg;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using Topology = NetTopologySuite.Geometries;
 
namespace HotelPms.SourceFactory
{
    public partial class FormGdi : Form
    {
        // 存储当鼠标在PictureBox中左键按下的位置,相对于PictureBox左上角坐标点的位置来讲。
        private Point mouseDownPoint = new Point();
        private bool isDown = false;
 
        Region r = new System.Drawing.Region();
        PointF start = PointF.Empty;
        PointF continues = PointF.Empty;
        PointF end = PointF.Empty;
        int isDrawing = 0;
        List<List<PointF>> drawpaths = new List<List<PointF>>();
        List<PointF> drawpathtemp = new List<PointF>();
 
 
        public FormGdi()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            Rectangle r1 = new Rectangle(panel1.Location, panel1.Size);
            Rectangle r2 = new Rectangle(panel2.Location, panel2.Size);
            textBox2.Text = $"({r1.Left}, {r1.Top})-({r1.Right},{r1.Bottom})";
            textBox3.Text = $"({r2.Left}, {r2.Top})-({r2.Right},{r2.Bottom})";
            textBox1.Text = Overlap.RectRect(r1, r2) ? "相交" : "分离";
 
            textBox5.Text = $"!({r1.Right} < {r2.Left} || {r1.Bottom} < {r2.Top} || {r2.Right} < {r1.Left} || {r2.Bottom} < {r1.Top})";
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            Rectangle r1 = new Rectangle(panel1.Location, panel1.Size);
            Rectangle r2 = new Rectangle(panel2.Location, panel2.Size);
            textBox2.Text = $"({r1.Left}, {r1.Top})-({r1.Right},{r1.Bottom})";
            textBox3.Text = $"({r2.Left}, {r2.Top})-({r2.Right},{r2.Bottom})";
            textBox1.Text = Overlap.RectRect2(r1, r2) ? "相交" : "分离";
            textBox5.Text = string.Empty;
        }
 
        private void panel2_MouseDown(object sender, MouseEventArgs e)
        {
            isDown = true;
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                mouseDownPoint = e.Location;
            }
        }
 
        private void panel2_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDown)
            {
                Panel obj = sender as Panel;
 
                //PointToClient 将指定屏幕点的位置计算成工作区坐标(控件内)。坐标原点为黄色区域(控件)左上角,X轴方向从左到右,Y轴方向从上到下,坐标单位为像素;
 
                //PointToScreen 将指定工作区点的位置计算成屏幕坐标。坐标原点在屏幕左上角,X轴方向从左到右,Y轴方向从上到下,坐标单位为像素。
 
                //1、PointToClient(Point p)
                //这里的p,坐标原点为Screen左上角,即(0, 0)。
                //它计算以当前Control的位置在Screen位置为坐标原点,返回p相对于坐标原点的值。
                //如上图例,btn在screen中位置为(328, 188),那么,screen上点(10, 10)相对于(320, 188)即为结果(-318, -178),同理screen上点(0, 0)相对于pnl来说,是(-183, -185)。
                //Control在Screen上点计算方式为:窗体Location加上其各级Parent的Location。
 
                //2、PointToScreen(Point p)
                //这里的p,坐标原点相对于Control的Location。
                //这是求p于Control的Locaton在Screen上点迭加结果。
                //如上例,pnl相对于窗体位置为(80, 60),其加上窗体Location(200, 100),再加上边框宽度3、标题栏高度25,即得185。
                //btn.PointToScreen(new Point(30, 20)): { X = 358,Y = 208}
                //此值即为:btn在Screen上位置(328, 188)加上(30, 20)所得。
 
                // 先获取到当前鼠标所在位置,并减去鼠标左键按下时相对PictureBox左上角的坐标点,就是当前坐标要停留的坐标点位置。
                Point point = this.PointToClient(obj.PointToScreen(new Point(e.X - mouseDownPoint.X, e.Y - mouseDownPoint.Y)));
                obj.Location = point;
            }
        }
 
        private void panel2_MouseUp(object sender, MouseEventArgs e)
        {
            if (isDown)
            { 
            }
 
            isDown = false;
        }
 
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Pen pen = new Pen(Color.Red);
            if (isDrawing == 1)
            {
                if (drawpaths.Count >= 1)
                {
                    foreach (List<PointF> drawpath in drawpaths)
                    {
                        if (drawpath.Count >= 2)
                        {
                            e.Graphics.DrawLines(pen, drawpath.ToArray());
                            if (continues.Equals(PointF.Empty) == false)
                            {
                                e.Graphics.DrawLine(pen, start, continues);
                            }
                        }
                        else
                        {
                            if (continues.Equals(PointF.Empty) == false)
                            {
                                e.Graphics.DrawLine(pen, start, continues);
                            }
                        }
                    }
                }
                if (drawpathtemp.Count >= 2)
                {
                    e.Graphics.DrawLines(pen, drawpathtemp.ToArray());
                    if (continues.Equals(PointF.Empty) == false)
                    {
                        e.Graphics.DrawLine(pen, start, continues);
                    }
                }
                else
                {
                    if (continues.Equals(PointF.Empty) == false)
                    {
                        e.Graphics.DrawLine(pen, start, continues);
                    }
                }
            }
            else if (isDrawing == 0)
            {
                foreach (List<PointF> drawpath in drawpaths)
                {
                    if (drawpath.Count >= 2)
                    {
                        e.Graphics.DrawLines(pen, drawpath.ToArray());
                    }
                }
            }
 
        }
 
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (isDrawing == 0)
                {
                    start = e.Location;
                    isDrawing = 1;
                    drawpathtemp.Add(start);
                }
                else if (isDrawing == 1)
                {
                    start = e.Location;
                    drawpathtemp.Add(start);
                }
                else if (isDrawing == 2)
                {
 
                }
                this.Refresh();
            }
            if (e.Button == MouseButtons.Right)
            {
                if (r.IsVisible(e.Location))
                {
                    MessageBox.Show("在选中区域内");
                }
                else
                {
                    MessageBox.Show("不在选中区域内");
                }
            }
        }
 
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDrawing == 1)
            {
                continues = e.Location;
                this.Refresh();
            }
 
        }
 
        private void FormGdi_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Escape:
                    drawpathtemp.Add(drawpathtemp.ElementAt(0));
                    List<PointF> temp = new List<PointF>();
                    if (drawpathtemp.Count > 2)
                    {
                        temp = drawpathtemp.GetRange(0, drawpathtemp.Count);
                        drawpaths.Add(temp);
                    }
                    drawpathtemp.Clear();
                    start = PointF.Empty;
                    end = PointF.Empty;
                    continues = PointF.Empty;
                    isDrawing = 0;
                    GraphicsPath gp = new GraphicsPath();
                    gp.Reset();
                    foreach (List<PointF> item in drawpaths)
                    {
                        gp.AddPolygon(item.ToArray());
                        r.MakeEmpty();
                        r.Union(gp);
                    }
                    this.Refresh();
                    break;
                default:
                    break;
            }
        }
 
#if false
        private PointF[] ToPointF(Topology.Coordinate[] coordinates)
        {
            PointF[] pointFs = new PointF[coordinates.Length];
            int i = 0;
            foreach (Topology.Coordinate item in coordinates)
            {
 
                pointFs[i] = new PointF((float)item.X, (float)item.Y);
                i++;
            }
            return pointFs;
        }
 
        private List<PointD> ToPointD(Topology.Coordinate[] coordinates)
        {
            List<PointD> pointFs = new List<PointD>();
            int i = 0;
            foreach (Topology.Coordinate item in coordinates)
            {
 
                pointFs.Add(new PointD(item.X, item.Y));
                i++;
            }
            return pointFs;
        }
#endif
 
        private void panel2_DoubleClick(object sender, EventArgs e)
        {
            (sender as Panel).BringToFront();
        }
 
#if false
        private void panel3_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;  //使绘图质量最高,即消除锯齿
                                                                 //g.InterpolationMode = InterpolationMode.HighQualityBicubic; //要らない!!!
                                                                 //g.CompositingQuality = CompositingQuality.HighQuality; //要らない!!!            
 
            //32.923023515806,130.70006035416
            //32.933253514755,130.69430969802
            //32.936999415636,130.7124199733
            //32.929507455233,130.73954247087
 
            //double rate = 1D;
            Topology.LineString ls = new Topology.LineString(
                new Topology.Coordinate[] {
                    //new Topology.Coordinate { X = 32.923023515806 * rate, Y = 130.70006035416* rate },
                    //new Topology.Coordinate { X = 32.933253514755 * rate, Y = 130.69430969802* rate },
                    //new Topology.Coordinate { X = 32.936999415636 * rate, Y = 130.7124199733* rate },
                    //new Topology.Coordinate { X = 32.929507455233 * rate , Y = 130.73954247087* rate }
                    new Topology.Coordinate { X = 32.923023515806, Y = 130.70006035416 },
                    new Topology.Coordinate { X = 32.933253514755, Y = 130.69430969802 },
                    new Topology.Coordinate { X = 32.936999415636, Y = 130.7124199733 },
                    new Topology.Coordinate { X = 32.929507455233 , Y = 130.73954247087 }
                    //new Topology.Coordinate { X = 25, Y = 28 }, 
                    //new Topology.Coordinate { X = 200, Y = 32 }, 
                    //new Topology.Coordinate { X = 250, Y = 326 },
                    //new Topology.Coordinate { X = 350, Y = 326 },
                    //new Topology.Coordinate { X = 350, Y = 426 },
                    //new Topology.Coordinate { X = 150, Y = 476 }
                });
            //Topology.Polygon result = ls.Buffer(10, NetTopologySuite.Operation.Buffer.EndCapStyle.Flat) as Topology.Polygon;
 
            PointF[] pointFs = ToPointF(ls.Coordinates);
            e.Graphics.DrawLines(new Pen(Color.Red, 3), pointFs);
            //pointFs = ToPointF(result.Coordinates);
            //e.Graphics.DrawPolygon(new Pen(Color.Blue, 3), pointFs);
 
            List<PointD> pointDs = ToPointD(ls.Coordinates);
            List<PointD> r1 = Geometry.OffsetCoords(pointDs, 0.0005) as List<PointD>;
            StringBuilder text = new StringBuilder();
            foreach (PointD item in r1)
            {
                text.AppendLine("{" + $" lat: {item.X}, lng: {item.Y} " + "},");
            }
            System.Diagnostics.Debug.WriteLine(text.ToString());
 
            e.Graphics.DrawLines(new Pen(Color.Green, 3), PointD.ToPointF(r1).ToArray());
 
            List<PointD> r2 = Geometry.OffsetCoords(pointDs, -0.0005) as List<PointD>;
            StringBuilder text1 = new StringBuilder();
            foreach (PointD item in r2)
            {
                text1.AppendLine("{" + $" lat: {item.X}, lng: {item.Y} " + "},");
            }
            System.Diagnostics.Debug.WriteLine(text1.ToString());
            e.Graphics.DrawLines(new Pen(Color.Green, 3), PointD.ToPointF(r2).ToArray());
 
            r2.Reverse();
            r1.AddRange(r2);
 
            StringBuilder text2 = new StringBuilder();
            foreach (PointD item in r1)
            {
                text2.AppendLine("{" + $" lat: {item.X}, lng: {item.Y} " + "},");
            }
            System.Diagnostics.Debug.WriteLine(text2.ToString());
 
            StringBuilder text3 = new StringBuilder();
            foreach (PointD item in r1)
            {
                text3.AppendLine($"{item.X},{item.Y}");
            }
            System.Diagnostics.Debug.WriteLine(text3.ToString());
 
            e.Graphics.DrawPolygon(new Pen(Color.Blue, 3), PointD.ToPointF(r1).ToArray());
 
            e.Graphics.SmoothingMode = SmoothingMode.Default;
        }
#endif
    }
}