프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter_AutoModeling / ConverterForm.cs @ f6d90b6e

이력 | 보기 | 이력해설 | 다운로드 (9.51 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 23eb98bf gaqhf
        private DataTable converterDT = new DataTable();
28
        private RepositoryItemComboBox templateComboBox;
29
30 96a2080c gaqhf
        public ConverterForm()
31
        {
32
            InitializeComponent();
33 1278ba59 gaqhf
34 fab4f207 gaqhf
            CultureInfo culture = CultureInfo.GetCultureInfo("ko");
35 23eb98bf gaqhf
            Msg.Culture = culture;
36
37 1278ba59 gaqhf
            InitGridControl();
38 fab4f207 gaqhf
            InitID2Project();
39 1278ba59 gaqhf
        }
40
41
        private void InitGridControl()
42
        {
43
            #region Converter Page
44
            gridViewConverter.OptionsSelection.MultiSelect = true;
45
            gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
46
47
            DataColumn col = converterDT.Columns.Add("colDrawingFileName");
48
            col.Caption = "Drawing File Name";
49
            col = converterDT.Columns.Add("colUnit");
50
            col.Caption = "Unit";
51
            col = converterDT.Columns.Add("colTemplate");
52
            col.Caption = "Template";
53
            col = converterDT.Columns.Add("colDrawingNumber");
54
            col.Caption = "Drawing Number";
55
            col = converterDT.Columns.Add("colDrawingName");
56
            col.Caption = "Drawing Name";
57
            col = converterDT.Columns.Add("colStatus");
58
            col.Caption = "Status";
59
            col = converterDT.Columns.Add("colUID");
60
            gridControlConverter.DataSource = converterDT;
61
62
            templateComboBox = new RepositoryItemComboBox();
63
            templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor;
64
            gridControlConverter.RepositoryItems.Add(templateComboBox);
65
            gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox;
66
67
            RepositoryItemButtonEdit unitButton = new RepositoryItemButtonEdit();
68
            unitButton.ButtonClick += UnitButton_ButtonClick;
69
            unitButton.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
70
            gridControlConverter.RepositoryItems.Add(unitButton);
71
            gridViewConverter.Columns["colUnit"].ColumnEdit = unitButton;
72
73
            gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false;
74
            gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true;
75
            gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false;
76
            gridViewConverter.Columns["colUID"].Visible = false;
77
78
            gridViewConverter.BestFitColumns();
79
            #endregion
80
        }
81
82 23eb98bf gaqhf
        private void btnID2Project_ButtonClick(object sender, ButtonPressedEventArgs e)
83
        {
84 fab4f207 gaqhf
            xtraFolderBrowserDialog.SelectedPath = btnID2Project.Text;
85
86 23eb98bf gaqhf
            if (xtraFolderBrowserDialog.ShowDialog() == DialogResult.OK)
87
            {
88 fab4f207 gaqhf
                if (xtraFolderBrowserDialog.SelectedPath[xtraFolderBrowserDialog.SelectedPath.Length - 1] == '\\')
89
                    xtraFolderBrowserDialog.SelectedPath = xtraFolderBrowserDialog.SelectedPath.Remove(xtraFolderBrowserDialog.SelectedPath.Length - 1);
90
                Settings.Default.LatestProjectPath = xtraFolderBrowserDialog.SelectedPath;
91
                Settings.Default.Save();
92
                if (InitID2Project())
93
                    MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
94
                else
95 23eb98bf gaqhf
                    MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
96
            }
97
        }
98
99 fab4f207 gaqhf
        private bool InitID2Project()
100 23eb98bf gaqhf
        {
101 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
102 fab4f207 gaqhf
            _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
103
            if (Project_DB.ConnTestAndCreateTable())
104 23eb98bf gaqhf
            {
105 fab4f207 gaqhf
                _ProjectInfo.Enable = true;
106 171142c5 gaqhf
                btnID2Project.Text = _ProjectInfo.DefaultPath;
107 23eb98bf gaqhf
                labelID2ProjectName.Text = _ProjectInfo.Name;
108
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue;
109
                labelID2ProjectStatus.Text = Msg.ConnectionSuccessful;
110
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue;
111 fab4f207 gaqhf
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
112
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
113
114
                InitSPPIDDB();
115
                return true;
116 23eb98bf gaqhf
            }
117
            else
118
            {
119 fab4f207 gaqhf
                _ProjectInfo.Enable = false;
120 23eb98bf gaqhf
                btnID2Project.Text = "";
121
                labelID2ProjectName.Text = " ";
122
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red;
123
                labelID2ProjectStatus.Text = Msg.ConnectionFail;
124
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red;
125 fab4f207 gaqhf
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
126
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
127
128
                InitSPPIDDB();
129
                return false;
130 23eb98bf gaqhf
            }
131
        }
132
133 fab4f207 gaqhf
        private void InitSPPIDDB()
134 23eb98bf gaqhf
        {
135 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
136 fab4f207 gaqhf
            if (_ProjectInfo.Enable)
137
            {
138
                DataTable dt = Project_DB.SelectSPPID_DB_INFO();
139 ec0c7045 gaqhf
                if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
140
                    SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
141
                else
142
                    SPPID_DBInfo.Clear();
143 fab4f207 gaqhf
            }
144 ec0c7045 gaqhf
145
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
146 23eb98bf gaqhf
            if (_SPPIDInfo.Enable)
147
            {
148
                labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant;
149
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue;
150
                labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful;
151
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue;
152
            }
153
            else
154
            {
155
                labelSPPIDPlantName.Text = " ";
156
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red;
157
                labelSPPIDDBStatus.Text = Msg.ConnectionFail;
158
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red;
159
            }
160
        }
161
162
        private bool IsID2Project(string path)
163
        {
164
            bool result = false;
165
            string[] directories = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly);
166
            for (int i = 0; i < directories.Length; i++)
167
                directories[i] = Path.GetFileName(directories[i]);
168
            List<string> dirList = directories.ToList();
169
170
            if (dirList.Contains("db") &&
171
                dirList.Contains("Temp") &&
172
                dirList.Contains("image"))
173
            {
174
                result = true;
175
            }
176
177
            return result;
178
        }
179
180 1278ba59 gaqhf
        private void UnitButton_ButtonClick(object sender, ButtonPressedEventArgs e)
181
        {
182
            //UnitForm unitForm = new UnitForm(dUnit);
183
            //if (unitForm.ShowDialog() == DialogResult.OK)
184
            //{
185
            //    ButtonEdit button = sender as ButtonEdit;
186
            //    button.EditValue = unitForm.SelectedUnit;
187
            //    gridViewConverter.CloseEditor();
188
            //    gridViewConverter.UpdateCurrentRow();
189
            //    gridViewConverter.BestFitColumns();
190
            //}
191
        }
192
193
        private void btnLoadFile_Click(object sender, EventArgs e)
194
        {
195 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
196 23eb98bf gaqhf
            if (!_ProjectInfo.Enable)
197
            {
198
                MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
199
                return;
200
            }
201 1278ba59 gaqhf
202 171142c5 gaqhf
            xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath;
203 23eb98bf gaqhf
            if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK)
204 1278ba59 gaqhf
            {
205 23eb98bf gaqhf
                foreach (string fileName in xtraOpenFileDialog.FileNames)
206 1278ba59 gaqhf
                {
207 60244a8b gaqhf
                    Document document = new Document(fileName);
208 1278ba59 gaqhf
                }
209
            }
210 f6d90b6e gaqhf
        } 
211 1278ba59 gaqhf
212
        private void btnRun_Click(object sender, EventArgs e)
213
        {
214
            DialogResult = DialogResult.OK;
215 96a2080c gaqhf
        }
216 23eb98bf gaqhf
217
        private void btnSPPIDDB_Click(object sender, EventArgs e)
218
        {
219
            SPPID_DB_SettingForm form = new SPPID_DB_SettingForm();
220
            if (form.ShowDialog() == DialogResult.OK)
221 fab4f207 gaqhf
                InitSPPIDDB();
222 23eb98bf gaqhf
        }
223 df4559fc gaqhf
224
        private void btnItemMapping_Click(object sender, EventArgs e)
225
        {
226 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
227 df4559fc gaqhf
            if (!_ProjectInfo.Enable)
228
            {
229
                MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
230
                return;
231
            }
232
233
            MappingForm form = new MappingForm();
234
            form.ShowDialog();
235
        }
236 96a2080c gaqhf
    }
237
}