FrmRemarkManage.cs
8.4 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Comm;
using Dal;
using Microsoft.Office.Interop.Word;
using ZedGraph;
using Rectangle=System.Drawing.Rectangle;
namespace App
{
public partial class FrmRemarkManage : App.FrmBase
{
private Remark _Remark;
private List<Remark> _RemarkList;
private List<Remark> _OldRemarkList;
private RectangleF _Rectangle ;
private PointF _StartPoint;
private Color _fillColor;
private string _text;
Fuction fuction = new Fuction();
private DataTable table1;
private int nameIndex;
public FrmRemarkManage(List<Remark> remarkList,RectangleF rectangle ,PointF startPoint)
{
_Rectangle = rectangle ;
_StartPoint = startPoint;
_OldRemarkList=new List<Remark>();
_OldRemarkList.AddRange(remarkList);
_RemarkList=remarkList;
InitializeComponent();
Init();
this.SetLanguage(this);
}
private void Init()
{
table1 = new DataTable(Const.REMARK);
DataColumnCollection columns = table1.Columns;
columns.Add(Const.REMARK_NO, typeof(System.String));
columns.Add(Const.REMARK_TEXT, typeof(System.String));
columns.Add(Const.REMARK_FillColor, typeof(Color));
columns.Add(Const.REMARK_LineColor, typeof(Color));
columns.Add(Const.REMARK_RectangleX, typeof(System.String));
columns.Add(Const.REMARK_RectangleY, typeof(System.String));
columns.Add(Const.REMARK_RectangleWidth, typeof(System.String));
columns.Add(Const.REMARK_RectangleHeight, typeof(System.String));
columns.Add(Const.REMARK_StartPointX, typeof(System.String));
columns.Add(Const.REMARK_StartPointY, typeof(System.String));
BindDGLogin();
}
public List<Remark> RemarkList
{
get { return _RemarkList; }
}
private void BindDGLogin()
{
table1.Rows.Clear();
DataRow dr;
for (int i = 0; i < _RemarkList.Count; i++)
{
dr = table1.NewRow();
dr[Const.REMARK_NO] = (i+1).ToString();
dr[Const.REMARK_TEXT] = _RemarkList[i].Text;
dr[Const.REMARK_FillColor] = _RemarkList[i].FillColor;
dr[Const.REMARK_LineColor] = _RemarkList[i].LineColor;
dr[Const.REMARK_RectangleX] = _RemarkList[i].Rectangle.X;
dr[Const.REMARK_RectangleY] = _RemarkList[i].Rectangle.Y;
dr[Const.REMARK_RectangleWidth] = _RemarkList[i].Rectangle.Width;
dr[Const.REMARK_RectangleHeight] = _RemarkList[i].Rectangle.Height;
dr[Const.REMARK_StartPointX] = _RemarkList[i].StartPoint.X;
dr[Const.REMARK_StartPointY] = _RemarkList[i].StartPoint.Y;
table1.Rows.Add(dr);
}
dg_Remark.DataSource = table1;
DataGridViewCellStyle dataGridViewCellStyle0 = CreatDataGridViewCellStyle();
dg_Remark.Columns[Const.REMARK_NO].DefaultCellStyle = dataGridViewCellStyle0;
dg_Remark.Columns[Const.REMARK_NO].HeaderCell.Style.BackColor = Color.SkyBlue;
dg_Remark.Columns[Const.REMARK_NO].SortMode = DataGridViewColumnSortMode.NotSortable;
dg_Remark.Columns[Const.REMARK_NO].Width = (dg_Remark.Width - 20)/4;
dg_Remark.Columns[Const.REMARK_TEXT].DefaultCellStyle = dataGridViewCellStyle0;
dg_Remark.Columns[Const.REMARK_TEXT].HeaderCell.Style.BackColor = Color.SkyBlue;
dg_Remark.Columns[Const.REMARK_TEXT].SortMode = DataGridViewColumnSortMode.NotSortable;
dg_Remark.Columns[Const.REMARK_TEXT].Width = (dg_Remark.Width - 20)*3/4;
dg_Remark.Columns[Const.REMARK_FillColor].Visible = false;
dg_Remark.Columns[Const.REMARK_LineColor].Visible = false;
dg_Remark.Columns[Const.REMARK_RectangleX].Visible = false;
dg_Remark.Columns[Const.REMARK_RectangleY].Visible = false;
dg_Remark.Columns[Const.REMARK_RectangleWidth].Visible = false;
dg_Remark.Columns[Const.REMARK_RectangleHeight].Visible = false;
dg_Remark.Columns[Const.REMARK_StartPointX].Visible = false;
dg_Remark.Columns[Const.REMARK_StartPointY].Visible = false;
if (table1.Rows.Count > 0)
{
nameIndex = 0;
dg_Remark.Rows[nameIndex].Selected = true;
ShowDetail(((DataTable) dg_Remark.DataSource).Rows[nameIndex]);
}
}
private void dg_Remark_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
dg_Remark.Rows[e.RowIndex].Selected = true;
nameIndex = e.RowIndex;
ShowDetail(((DataTable) dg_Remark.DataSource).Rows[nameIndex]);
}
}
private void ShowDetail(DataRow drRemark)
{
txt_Remark.Text = drRemark[Const.REMARK_TEXT].ToString();
p_BackColor.BackColor = (Color)(drRemark[Const.REMARK_FillColor]);
line.ForeColor = (Color)(drRemark[Const.REMARK_LineColor]);
}
private void btn_OK1_Click(object sender, EventArgs e)
{
this.Close();
}
private DialogResult _DialogResult;
private void btn_BackColor_Click(object sender, EventArgs e)
{
DialogResult result = colorDialog1.ShowDialog();
if (result == DialogResult.OK)//保存ʼþÏìÓ¦
{
p_BackColor.BackColor = colorDialog1.Color;//»ñÈ¡»òÉèÖÃÓû§Ñ¡ÖеÄÑÕÉ«
}
}
private void btn_ForColor_Click(object sender, EventArgs e)
{
DialogResult result = colorDialog1.ShowDialog();
if (result == DialogResult.OK)//保存ʼþÏìÓ¦
{
line.ForeColor = colorDialog1.Color;//»ñÈ¡»òÉèÖÃÓû§Ñ¡ÖеÄÑÕÉ«
}
}
private void btn_Add_Click(object sender, EventArgs e)
{
if (SameText(_RemarkList.Count + 1,txt_Remark.Text.Trim()))
{
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SAME_REMARK);
return;
}
if (txt_Remark.Text.Length > 20 || txt_Remark.Text.Length==0)
{
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.REMARK_LENGTH_WRONG);
return;
}
_Rectangle.Width = txt_Remark.Text.Trim().Length*12;
_Remark = new Remark(p_BackColor.BackColor, line.ForeColor, _Rectangle, _StartPoint, txt_Remark.Text.Trim());
_RemarkList.Add(_Remark);
BindDGLogin();
}
private bool SameText(int No, string text)
{
for (int i = 0; i < _RemarkList.Count; i++)
{
if (_RemarkList[i].Text == text && No != (i + 1))
return true;
}
return false;
}
private void btn_Update_Click(object sender, EventArgs e)
{
if (SameText(nameIndex + 1, txt_Remark.Text.Trim()))
{
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SAME_REMARK);
return;
}
if (txt_Remark.Text.Length > 20 || txt_Remark.Text.Length == 0)
{
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.REMARK_LENGTH_WRONG);
return;
}
_Remark = new Remark(p_BackColor.BackColor, line.ForeColor,
_RemarkList[nameIndex].Rectangle, _RemarkList[nameIndex].StartPoint, txt_Remark.Text.Trim());
_RemarkList[nameIndex]=_Remark;
BindDGLogin();
}
private void btn_Delete_Click(object sender, EventArgs e)
{
_RemarkList.RemoveAt(nameIndex);
BindDGLogin();
}
private void btn_Cancel1_Click(object sender, EventArgs e)
{
_RemarkList = _OldRemarkList;
this.Close();
}
private void btn_OK_Click(object sender, EventArgs e)
{
this.Close();
}
}
}