hytos / DTI_PID / SPPIDConverter_AutoModeling / ConverterForm.cs @ 0d8062b2
이력 | 보기 | 이력해설 | 다운로드 (10.8 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Data; |
5 |
using System.Drawing; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows.Forms; |
10 |
using Microsoft.VisualBasic; |
11 |
using Converter.BaseModel; |
12 |
using DevExpress.XtraEditors.Repository; |
13 |
using DevExpress.XtraEditors.Controls; |
14 |
using DevExpress.XtraEditors; |
15 |
using System.Globalization; |
16 |
using System.Threading; |
17 |
using System.IO; |
18 |
using Converter.AutoModeling.SPPID.Properties; |
19 |
using Converter.AutoModeling.SPPID.DB; |
20 |
using Converter.AutoModeling.SPPID.Util; |
21 |
using Converter.AutoModeling.SPPID.Form; |
22 |
|
23 |
namespace Converter.AutoModeling.SPPID |
24 |
{ |
25 |
public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm |
26 |
{ |
27 |
private Dictionary<string, Document> _DicDocuments = new Dictionary<string, Document>(); |
28 |
private DataTable converterDT = new DataTable(); |
29 |
private RepositoryItemComboBox templateComboBox; |
30 |
|
31 |
public ConverterForm() |
32 |
{ |
33 |
InitializeComponent(); |
34 |
|
35 |
CultureInfo culture = CultureInfo.GetCultureInfo("ko"); |
36 |
Msg.Culture = culture; |
37 |
|
38 |
InitGridControl(); |
39 |
InitID2Project(); |
40 |
} |
41 |
|
42 |
private void InitGridControl() |
43 |
{ |
44 |
#region Converter Page |
45 |
gridViewConverter.OptionsSelection.MultiSelect = true; |
46 |
gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; |
47 |
|
48 |
DataColumn col = converterDT.Columns.Add("colDrawingFileName"); |
49 |
col.Caption = "Drawing File Name"; |
50 |
col = converterDT.Columns.Add("colDrawingFilePath"); |
51 |
col.Caption = "DrawingFilePath"; |
52 |
col = converterDT.Columns.Add("colUnit"); |
53 |
col.Caption = "Unit"; |
54 |
col = converterDT.Columns.Add("colTemplate"); |
55 |
col.Caption = "Template"; |
56 |
col = converterDT.Columns.Add("colDrawingNumber"); |
57 |
col.Caption = "Drawing Number"; |
58 |
col = converterDT.Columns.Add("colDrawingName"); |
59 |
col.Caption = "Drawing Name"; |
60 |
col = converterDT.Columns.Add("colStatus"); |
61 |
col.Caption = "Status"; |
62 |
col = converterDT.Columns.Add("colUID"); |
63 |
gridControlConverter.DataSource = converterDT; |
64 |
|
65 |
templateComboBox = new RepositoryItemComboBox(); |
66 |
templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor; |
67 |
gridControlConverter.RepositoryItems.Add(templateComboBox); |
68 |
gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox; |
69 |
|
70 |
RepositoryItemButtonEdit unitButton = new RepositoryItemButtonEdit(); |
71 |
unitButton.ButtonClick += UnitButton_ButtonClick; |
72 |
unitButton.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
73 |
gridControlConverter.RepositoryItems.Add(unitButton); |
74 |
gridViewConverter.Columns["colUnit"].ColumnEdit = unitButton; |
75 |
|
76 |
gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false; |
77 |
gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true; |
78 |
gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false; |
79 |
gridViewConverter.Columns["colDrawingFilePath"].Visible = false; |
80 |
gridViewConverter.Columns["colUID"].Visible = false; |
81 |
|
82 |
gridViewConverter.BestFitColumns(); |
83 |
#endregion |
84 |
} |
85 |
|
86 |
private void btnID2Project_ButtonClick(object sender, ButtonPressedEventArgs e) |
87 |
{ |
88 |
xtraFolderBrowserDialog.SelectedPath = btnID2Project.Text; |
89 |
|
90 |
if (xtraFolderBrowserDialog.ShowDialog() == DialogResult.OK) |
91 |
{ |
92 |
if (xtraFolderBrowserDialog.SelectedPath[xtraFolderBrowserDialog.SelectedPath.Length - 1] == '\\') |
93 |
xtraFolderBrowserDialog.SelectedPath = xtraFolderBrowserDialog.SelectedPath.Remove(xtraFolderBrowserDialog.SelectedPath.Length - 1); |
94 |
Settings.Default.LatestProjectPath = xtraFolderBrowserDialog.SelectedPath; |
95 |
Settings.Default.Save(); |
96 |
if (InitID2Project()) |
97 |
MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
98 |
else |
99 |
MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
100 |
} |
101 |
} |
102 |
|
103 |
private bool InitID2Project() |
104 |
{ |
105 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
106 |
_ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
107 |
if (Project_DB.ConnTestAndCreateTable()) |
108 |
{ |
109 |
_ProjectInfo.Enable = true; |
110 |
btnID2Project.Text = _ProjectInfo.DefaultPath; |
111 |
labelID2ProjectName.Text = _ProjectInfo.Name; |
112 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue; |
113 |
labelID2ProjectStatus.Text = Msg.ConnectionSuccessful; |
114 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
115 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
116 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
117 |
|
118 |
InitSPPIDDB(); |
119 |
return true; |
120 |
} |
121 |
else |
122 |
{ |
123 |
_ProjectInfo.Enable = false; |
124 |
btnID2Project.Text = ""; |
125 |
labelID2ProjectName.Text = " "; |
126 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red; |
127 |
labelID2ProjectStatus.Text = Msg.ConnectionFail; |
128 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red; |
129 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
130 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
131 |
|
132 |
InitSPPIDDB(); |
133 |
return false; |
134 |
} |
135 |
} |
136 |
|
137 |
private void InitSPPIDDB() |
138 |
{ |
139 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
140 |
if (_ProjectInfo.Enable) |
141 |
{ |
142 |
DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
143 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
144 |
SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
145 |
else |
146 |
SPPID_DBInfo.Clear(); |
147 |
} |
148 |
|
149 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
150 |
if (_SPPIDInfo.Enable) |
151 |
{ |
152 |
labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant; |
153 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue; |
154 |
labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful; |
155 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
156 |
} |
157 |
else |
158 |
{ |
159 |
labelSPPIDPlantName.Text = " "; |
160 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red; |
161 |
labelSPPIDDBStatus.Text = Msg.ConnectionFail; |
162 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red; |
163 |
} |
164 |
} |
165 |
|
166 |
private bool IsID2Project(string path) |
167 |
{ |
168 |
bool result = false; |
169 |
string[] directories = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly); |
170 |
for (int i = 0; i < directories.Length; i++) |
171 |
directories[i] = Path.GetFileName(directories[i]); |
172 |
List<string> dirList = directories.ToList(); |
173 |
|
174 |
if (dirList.Contains("db") && |
175 |
dirList.Contains("Temp") && |
176 |
dirList.Contains("image")) |
177 |
{ |
178 |
result = true; |
179 |
} |
180 |
|
181 |
return result; |
182 |
} |
183 |
|
184 |
private void UnitButton_ButtonClick(object sender, ButtonPressedEventArgs e) |
185 |
{ |
186 |
//UnitForm unitForm = new UnitForm(dUnit); |
187 |
//if (unitForm.ShowDialog() == DialogResult.OK) |
188 |
//{ |
189 |
// ButtonEdit button = sender as ButtonEdit; |
190 |
// button.EditValue = unitForm.SelectedUnit; |
191 |
// gridViewConverter.CloseEditor(); |
192 |
// gridViewConverter.UpdateCurrentRow(); |
193 |
// gridViewConverter.BestFitColumns(); |
194 |
//} |
195 |
} |
196 |
|
197 |
private void btnLoadFile_Click(object sender, EventArgs e) |
198 |
{ |
199 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
200 |
if (!_ProjectInfo.Enable) |
201 |
{ |
202 |
MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
203 |
return; |
204 |
} |
205 |
|
206 |
xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath; |
207 |
if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK) |
208 |
{ |
209 |
foreach (string fileName in xtraOpenFileDialog.FileNames) |
210 |
{ |
211 |
Document document = new Document(fileName); |
212 |
DataRow[] rows = converterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName)); |
213 |
DataRow row; |
214 |
if (rows.Length == 0) |
215 |
{ |
216 |
row = converterDT.NewRow(); |
217 |
row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName); |
218 |
row["colDrawingFilePath"] = fileName; |
219 |
row["colDrawingNumber"] = document.DWGNAME; |
220 |
row["colDrawingName"] = document.DWGNAME; |
221 |
if (document.Enable) |
222 |
row["colStatus"] = "Ready"; |
223 |
else |
224 |
row["colStatus"] = "Error"; |
225 |
row["colUID"] = ""; |
226 |
converterDT.Rows.Add(row); |
227 |
} |
228 |
if (!_DicDocuments.ContainsKey(fileName)) |
229 |
_DicDocuments.Add(fileName, null); |
230 |
|
231 |
_DicDocuments[fileName] = document; |
232 |
} |
233 |
} |
234 |
} |
235 |
|
236 |
private void btnRun_Click(object sender, EventArgs e) |
237 |
{ |
238 |
DialogResult = DialogResult.OK; |
239 |
} |
240 |
|
241 |
private void btnSPPIDDB_Click(object sender, EventArgs e) |
242 |
{ |
243 |
SPPID_DB_SettingForm form = new SPPID_DB_SettingForm(); |
244 |
if (form.ShowDialog() == DialogResult.OK) |
245 |
InitSPPIDDB(); |
246 |
} |
247 |
|
248 |
private void btnItemMapping_Click(object sender, EventArgs e) |
249 |
{ |
250 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
251 |
if (!_ProjectInfo.Enable) |
252 |
{ |
253 |
MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
254 |
return; |
255 |
} |
256 |
|
257 |
MappingForm form = new MappingForm(); |
258 |
form.ShowDialog(); |
259 |
} |
260 |
} |
261 |
} |