/
Form1.cs
229 lines (210 loc) · 8.6 KB
/
Form1.cs
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
using System;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NetsuiteOnlineServicesOrders
{
public partial class Form1 : Form
{
delegate void SetTextCallback();
delegate void SetText2Callback();
public Form1()
{
InitializeComponent();
Common.objForm = this;
}
private void cargarArchivoToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
Common.dsData = new DataSet();
Common.LoadExcelData(openFileDialog1.FileName);
string[] arrCustomers = GlobalSettings.Default.exSheet.Split(new string[] { "," }, StringSplitOptions.None);
comboBox1.Items.Clear();
foreach (string strCustom in arrCustomers)
{
comboBox1.Items.Add(strCustom);
}
button1.Enabled = true;
try
{
File.Copy(openFileDialog1.FileName, GlobalSettings.Default.pathLog + @"\load_" + DateTime.Now.Ticks + "_" + openFileDialog1.SafeFileName);
}
catch (Exception)
{
}
Common.ShowMessage("File is loaded!");
Cursor.Current = Cursors.Default;
}
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
dataGridView1.Size = new Size(this.Size.Width - 50, this.Size.Height - 120);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
dataGridView1.DataSource = Common.dsData.Tables[comboBox1.SelectedIndex];
dataGridView1.ScrollBars = ScrollBars.Both;
}
catch (Exception)
{
Common.ShowMessage("The tab is empty.");
}
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex > -1)
{
DataTable dtData = Common.dsData.Tables[comboBox1.SelectedIndex];
progressBar1.Minimum = 0;
progressBar1.Value = 0;
progressBar1.Maximum = dtData.Rows.Count;
this.button1.Enabled = false;
this.comboBox1.Enabled = false;
if (comboBox1.SelectedItem.Equals("format1800"))
{
Common.LoadTable1800(dtData);
}
else
{
if (comboBox1.SelectedItem.Equals("FTD"))
Common.LoadTableMassMarket(dtData);
else
Common.LoadTable(dtData);
}
}
}
public void IncrementProcess()
{
if (this.progressBar1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(IncrementProcess);
this.Invoke(d, new object[] { });
}
else
{
dataGridView1.ClearSelection();
int numIndex = progressBar1.Value - 1;
if (this.progressBar1.Value < this.progressBar1.Maximum)
{
dataGridView1.Rows[progressBar1.Value].Selected = true;
this.progressBar1.Value += 1;
}
else
{
numIndex = progressBar1.Value - 1;
this.button1.Enabled = true;
this.comboBox1.Enabled = true;
}
this.lblTotal.Text = progressBar1.Value + " / " + progressBar1.Maximum;
try
{
dataGridView1.Rows[numIndex].ErrorText = Common.strMessage;
switch (Common.LastProcessResult)
{
case Common.ProcessResult.Processed:
dataGridView1.Rows[numIndex].DefaultCellStyle.BackColor = Color.Silver;
break;
case Common.ProcessResult.Ok1:
dataGridView1.Rows[numIndex].DefaultCellStyle.BackColor = Color.Yellow;
break;
case Common.ProcessResult.Ok2:
dataGridView1.Rows[numIndex].DefaultCellStyle.BackColor = Color.LightGreen;
break;
case Common.ProcessResult.Added:
dataGridView1.Rows[numIndex].DefaultCellStyle.BackColor = Color.LightBlue;
break;
case Common.ProcessResult.Error:
dataGridView1.Rows[numIndex].DefaultCellStyle.BackColor = Color.Orange;
break;
case Common.ProcessResult.Closed:
dataGridView1.Rows[numIndex].DefaultCellStyle.BackColor = Color.LightSalmon;
break;
}
//dataGridView1.Rows[numIndex].Selected = true;
}
catch (Exception)
{
}
}
}
private void testLoginToolStripMenuItem_Click(object sender, EventArgs e)
{
string strResult = Util.Login(GlobalSettings.Default.nsUser, GlobalSettings.Default.nsPassword, GlobalSettings.Default.nsAccount, GlobalSettings.Default.nsRole);
//Util.GetPackedBunch("QB00003109");
if (!string.IsNullOrEmpty(strResult))
{
Common.ShowMessage(GlobalSettings.Default.nsUser + ": " + strResult + "\n" + Util._service.Url);
}
else
{
Common.ShowMessage(GlobalSettings.Default.nsUser + ": Login OK!\n" + Util._service.Url);
}
}
private void loadMassMarketFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
Common.dsData = new DataSet();
Common.LoadExcelData(openFileDialog1.FileName);
string[] arrCustomers = GlobalSettings.Default.exSheet.Split(new string[] { "," }, StringSplitOptions.None);
comboBox1.Items.Clear();
foreach (string strCustom in arrCustomers)
{
comboBox1.Items.Add(strCustom);
}
button1.Enabled = true;
try
{
File.Copy(openFileDialog1.FileName, GlobalSettings.Default.pathLog + @"\load_" + DateTime.Now.Ticks + "_" + openFileDialog1.SafeFileName);
}
catch (Exception)
{
}
Common.ShowMessage("File is loaded!");
Cursor.Current = Cursors.Default;
}
}
private void load1800FileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
button1.Enabled = true;
string strNewFile = GlobalSettings.Default.pathLog + @"\load_1800_" + DateTime.Now.Ticks + ".csv";
try
{
//File.Copy(openFileDialog1.FileName, GlobalSettings.Default.pathLog + @"\load_1800_" + DateTime.Now.Ticks + "_" + openFileDialog1.SafeFileName);
File.Copy(openFileDialog1.FileName, strNewFile);
}
catch (Exception)
{
}
Common.dsData = new DataSet();
Common.LoadCSVData(strNewFile);
comboBox1.Items.Clear();
comboBox1.Items.Add("format1800");
Common.ShowMessage("File is loaded!");
Cursor.Current = Cursors.Default;
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
}
}
}