hytos / DTI_PID / SPPIDConverter_AutoModeling / ConverterForm.cs @ 0d8062b2
이력 | 보기 | 이력해설 | 다운로드 (10.8 KB)
1 | 96a2080c | gaqhf | 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 | 23eb98bf | gaqhf | using Converter.BaseModel; |
12 | 1278ba59 | gaqhf | using DevExpress.XtraEditors.Repository; |
13 | using DevExpress.XtraEditors.Controls; |
||
14 | using DevExpress.XtraEditors; |
||
15 | 23eb98bf | gaqhf | using System.Globalization; |
16 | using System.Threading; |
||
17 | using System.IO; |
||
18 | 171142c5 | gaqhf | using Converter.AutoModeling.SPPID.Properties; |
19 | ebd79b4d | gaqhf | using Converter.AutoModeling.SPPID.DB; |
20 | using Converter.AutoModeling.SPPID.Util; |
||
21 | using Converter.AutoModeling.SPPID.Form; |
||
22 | 96a2080c | gaqhf | |
23 | ebd79b4d | gaqhf | namespace Converter.AutoModeling.SPPID |
24 | 96a2080c | gaqhf | { |
25 | public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm |
||
26 | { |
||
27 | 0d8062b2 | gaqhf | private Dictionary<string, Document> _DicDocuments = new Dictionary<string, Document>(); |
28 | 23eb98bf | gaqhf | private DataTable converterDT = new DataTable(); |
29 | private RepositoryItemComboBox templateComboBox; |
||
30 | |||
31 | 96a2080c | gaqhf | public ConverterForm() |
32 | { |
||
33 | InitializeComponent(); |
||
34 | 1278ba59 | gaqhf | |
35 | fab4f207 | gaqhf | CultureInfo culture = CultureInfo.GetCultureInfo("ko"); |
36 | 23eb98bf | gaqhf | Msg.Culture = culture; |
37 | |||
38 | 1278ba59 | gaqhf | InitGridControl(); |
39 | fab4f207 | gaqhf | InitID2Project(); |
40 | 1278ba59 | gaqhf | } |
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 | 0d8062b2 | gaqhf | col = converterDT.Columns.Add("colDrawingFilePath"); |
51 | col.Caption = "DrawingFilePath"; |
||
52 | 1278ba59 | gaqhf | 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 | 0d8062b2 | gaqhf | gridViewConverter.Columns["colDrawingFilePath"].Visible = false; |
80 | 1278ba59 | gaqhf | gridViewConverter.Columns["colUID"].Visible = false; |
81 | |||
82 | gridViewConverter.BestFitColumns(); |
||
83 | #endregion |
||
84 | } |
||
85 | |||
86 | 23eb98bf | gaqhf | private void btnID2Project_ButtonClick(object sender, ButtonPressedEventArgs e) |
87 | { |
||
88 | fab4f207 | gaqhf | xtraFolderBrowserDialog.SelectedPath = btnID2Project.Text; |
89 | |||
90 | 23eb98bf | gaqhf | if (xtraFolderBrowserDialog.ShowDialog() == DialogResult.OK) |
91 | { |
||
92 | fab4f207 | gaqhf | 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 | 23eb98bf | gaqhf | MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
100 | } |
||
101 | } |
||
102 | |||
103 | fab4f207 | gaqhf | private bool InitID2Project() |
104 | 23eb98bf | gaqhf | { |
105 | ec0c7045 | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
106 | fab4f207 | gaqhf | _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
107 | if (Project_DB.ConnTestAndCreateTable()) |
||
108 | 23eb98bf | gaqhf | { |
109 | fab4f207 | gaqhf | _ProjectInfo.Enable = true; |
110 | 171142c5 | gaqhf | btnID2Project.Text = _ProjectInfo.DefaultPath; |
111 | 23eb98bf | gaqhf | labelID2ProjectName.Text = _ProjectInfo.Name; |
112 | labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue; |
||
113 | labelID2ProjectStatus.Text = Msg.ConnectionSuccessful; |
||
114 | labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
||
115 | fab4f207 | gaqhf | layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
116 | layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
||
117 | |||
118 | InitSPPIDDB(); |
||
119 | return true; |
||
120 | 23eb98bf | gaqhf | } |
121 | else |
||
122 | { |
||
123 | fab4f207 | gaqhf | _ProjectInfo.Enable = false; |
124 | 23eb98bf | gaqhf | btnID2Project.Text = ""; |
125 | labelID2ProjectName.Text = " "; |
||
126 | labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red; |
||
127 | labelID2ProjectStatus.Text = Msg.ConnectionFail; |
||
128 | labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red; |
||
129 | fab4f207 | gaqhf | layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
130 | layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
||
131 | |||
132 | InitSPPIDDB(); |
||
133 | return false; |
||
134 | 23eb98bf | gaqhf | } |
135 | } |
||
136 | |||
137 | fab4f207 | gaqhf | private void InitSPPIDDB() |
138 | 23eb98bf | gaqhf | { |
139 | ec0c7045 | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
140 | fab4f207 | gaqhf | if (_ProjectInfo.Enable) |
141 | { |
||
142 | DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
||
143 | ec0c7045 | gaqhf | if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
144 | SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
||
145 | else |
||
146 | SPPID_DBInfo.Clear(); |
||
147 | fab4f207 | gaqhf | } |
148 | ec0c7045 | gaqhf | |
149 | SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
||
150 | 23eb98bf | gaqhf | 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 | 1278ba59 | gaqhf | 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 | ec0c7045 | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
200 | 23eb98bf | gaqhf | if (!_ProjectInfo.Enable) |
201 | { |
||
202 | MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
203 | return; |
||
204 | } |
||
205 | 1278ba59 | gaqhf | |
206 | 171142c5 | gaqhf | xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath; |
207 | 23eb98bf | gaqhf | if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK) |
208 | 1278ba59 | gaqhf | { |
209 | 23eb98bf | gaqhf | foreach (string fileName in xtraOpenFileDialog.FileNames) |
210 | 1278ba59 | gaqhf | { |
211 | 60244a8b | gaqhf | Document document = new Document(fileName); |
212 | 0d8062b2 | gaqhf | 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 | 1278ba59 | gaqhf | } |
233 | } |
||
234 | f6d90b6e | gaqhf | } |
235 | 1278ba59 | gaqhf | |
236 | private void btnRun_Click(object sender, EventArgs e) |
||
237 | { |
||
238 | DialogResult = DialogResult.OK; |
||
239 | 96a2080c | gaqhf | } |
240 | 23eb98bf | gaqhf | |
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 | fab4f207 | gaqhf | InitSPPIDDB(); |
246 | 23eb98bf | gaqhf | } |
247 | df4559fc | gaqhf | |
248 | private void btnItemMapping_Click(object sender, EventArgs e) |
||
249 | { |
||
250 | ec0c7045 | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
251 | df4559fc | gaqhf | 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 | 96a2080c | gaqhf | } |
261 | } |