-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableMaintnance.cs
680 lines (577 loc) · 29.7 KB
/
tableMaintnance.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.IO;
using System.Diagnostics;
namespace TecanPartListManager
{
public partial class tableMaintnance : Form
{
MainPartsListDisplay mainForm;
String currentTable = "";
public void SetMainFormInstance(MainPartsListDisplay inst)
{
mainForm = inst;
}
public tableMaintnance()
{
InitializeComponent();
}
private void instrumentBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.instrumentBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.tecanPartsListDataSet);
}
private void tableMaintnance_Load(object sender, EventArgs e)
{
partsListTableAdapter.Connection.ConnectionString = mainForm.whichDb;
salesTypeTableAdapter.Connection.ConnectionString = mainForm.whichDb;
dBMembershipTableAdapter.Connection.ConnectionString = mainForm.whichDb;
sSPCategoryTableAdapter.Connection.ConnectionString = mainForm.whichDb;
subCategoryTableAdapter.Connection.ConnectionString = mainForm.whichDb;
categoryTableAdapter.Connection.ConnectionString = mainForm.whichDb;
instrumentTableAdapter.Connection.ConnectionString = mainForm.whichDb;
//String str1 = salesTypeTableAdapter.Connection.ConnectionString.ToString();
//String str2 = dBMembershipTableAdapter.Connection.ConnectionString.ToString();
//String str3 = sSPCategoryTableAdapter.Connection.ConnectionString.ToString();
//String str4 = subCategoryTableAdapter.Connection.ConnectionString.ToString();
//String str5 = categoryTableAdapter.Connection.ConnectionString.ToString();
//String str6 = instrumentTableAdapter.Connection.ConnectionString.ToString();
//String str7 = partsListTableAdapter.Connection.ConnectionString.ToString();
//MessageBox.Show(str1 + "\n" + str2 + "\n" + str3 + "\n" + str4 + "\n" + str5 + "\n" + str6 + "\n" + str7);
this.partsListTableAdapter.Fill(this.tecanPartsListDataSet.PartsList);
this.suppumentalDocsTableAdapter.Fill(this.tecanPartsListDataSet.SuppumentalDocs);
this.salesTypeTableAdapter.Fill(this.tecanPartsListDataSet.SalesType);
this.dBMembershipTableAdapter.Fill(this.tecanPartsListDataSet.DBMembership);
this.sSPCategoryTableAdapter.Fill(this.tecanPartsListDataSet.SSPCategory);
this.subCategoryTableAdapter.Fill(this.tecanPartsListDataSet.SubCategory);
this.categoryTableAdapter.Fill(this.tecanPartsListDataSet.Category);
this.instrumentTableAdapter.Fill(this.tecanPartsListDataSet.Instrument);
// Add All Supplemental Documents to List
SqlCeConnection TecanSuppDocsDatabase = null;
TecanSuppDocsDatabase = new SqlCeConnection();
// String dataPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
TecanSuppDocsDatabase.ConnectionString = "Data Source=|DataDirectory|\\TecanSuppDocs.sdf;Max Database Size=4000;Max Buffer Size=1024;Persist Security Info=False";
TecanSuppDocsDatabase.Open();
SqlCeCommand cmd = TecanSuppDocsDatabase.CreateCommand();
cmd.CommandText = "SELECT DocID, FileName FROM SuppumentalDocs ORDER BY FileName";
SqlCeDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
allSuppDocsDataGridView.Rows.Add(reader[0].ToString(), reader[1].ToString());
}
reader.Dispose();
TecanSuppDocsDatabase.Close();
allSuppDocsDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
suppumentalDocsDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
// Add Compatibilities to List
ArrayList theCompatibilities = new ArrayList();
SqlCeConnection TecanDatabase = null;
TecanDatabase = new SqlCeConnection();
// String dataPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
TecanDatabase.ConnectionString = "Data Source=|DataDirectory|\\TecanPartsList.sdf;Max Database Size=4000;Max Buffer Size=1024;Persist Security Info=False";
TecanDatabase.Open();
cmd = TecanDatabase.CreateCommand();
cmd.CommandText = "SELECT CompatibilityName, CompatibilityID FROM Compatibility ORDER BY CompatibilityName";
reader = cmd.ExecuteReader();
while (reader.Read())
{
theCompatibilities.Add(new Compatibilities(reader[0].ToString(), reader[1].ToString()));
}
reader.Dispose();
TecanDatabase.Close();
compatibilityListBox.DataSource = theCompatibilities;
compatibilityListBox.DisplayMember = "Name";
compatibilityListBox.ValueMember = "ID";
}
//public class Compatibilities
//{
// private String CompatibilityID;
// private String CompatibilityName;
// public Compatibilities(string strName, string strID)
// {
// this.CompatibilityID = strID;
// this.CompatibilityName = strName;
// }
// public string ID
// {
// get
// {
// return CompatibilityID;
// }
// }
// public string Name
// {
// get
// {
// return CompatibilityName;
// }
// }
//}
public void clearCurrentTable()
{
currentTable = "";
}
private void tableMaintnance_Close(object sender, EventArgs e)
{
if (currentTable != "")
{
mainForm.associatedTableReturn(currentTable);
}
}
private void addInstrumentButton_Click(object sender, EventArgs e)
{
currentTable = "Instrument";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Add Instrument Item";
EditTableForm.LoadTableEdit("Instrument", "Add");
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void addCategoryButton_Click(object sender, EventArgs e)
{
currentTable = "Category";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Add Category Item";
EditTableForm.LoadTableEdit("Category", "Add");
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void addSubCategoryButton_Click(object sender, EventArgs e)
{
currentTable = "SubCategory";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Add Sub-Category Item";
EditTableForm.LoadTableEdit("SubCategory", "Add");
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void addSSPCategoryButton_Click(object sender, EventArgs e)
{
currentTable = "SSPCategory";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Add SSP-Category Item";
EditTableForm.LoadTableEdit("SSPCategory", "Add");
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void addDBMembershipButton_Click(object sender, EventArgs e)
{
currentTable = "DBMembership";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Add Database Membership Item";
EditTableForm.LoadTableEdit("DBMembership", "Add");
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void addSalesTypeButton_Click(object sender, EventArgs e)
{
currentTable = "SalesType";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Add Sales Type Item";
EditTableForm.LoadTableEdit("SalesType", "Add");
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void addCompatibilityButton_Click(object sender, EventArgs e)
{
currentTable = "Compatibility";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Add Compatibility Item";
EditTableForm.LoadTableEdit("Compatibility", "Add");
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void instrumentListBox_DoubleClick(object sender, EventArgs e)
{
currentTable = "Instrument";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Edit or Delete Instrument Item";
EditTableForm.LoadTableEdit("Instrument", "Edit", instrumentListBox.GetItemText(instrumentListBox.SelectedItem));
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void categoryListBox_DoubleClick(object sender, EventArgs e)
{
currentTable = "Category";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Edit or Delete Category Item";
EditTableForm.LoadTableEdit("Category", "Edit", categoryListBox.GetItemText(categoryListBox.SelectedItem));
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void subCategoryListBox_DoubleClick(object sender, EventArgs e)
{
currentTable = "SubCategory";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Edit or Delete Sub-Category Item";
EditTableForm.LoadTableEdit("SubCategory", "Edit", subCategoryListBox.GetItemText(subCategoryListBox.SelectedItem));
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void sSPCategoryListBox_DoubleClick(object sender, EventArgs e)
{
currentTable = "SSPCategory";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Edit or Delete SSP Category Item";
EditTableForm.LoadTableEdit("SSPCategory", "Edit", sSPCategoryListBox.GetItemText(sSPCategoryListBox.SelectedItem));
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void dBMembershipListBox_DoubleClick(object sender, EventArgs e)
{
currentTable = "DBMembership";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Edit or Delete Database Membership Item";
EditTableForm.LoadTableEdit("DBMembership", "Edit", dBMembershipListBox.GetItemText(dBMembershipListBox.SelectedItem));
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void salesTypeListBox_DoubleClick(object sender, EventArgs e)
{
currentTable = "SalesType";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Edit or Delete Sales Type Item";
EditTableForm.LoadTableEdit("SalesType", "Edit", salesTypeListBox.GetItemText(salesTypeListBox.SelectedItem));
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void compatibilityListBox_DoubleClick(object sender, EventArgs e)
{
currentTable = "Compatibility";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Edit or Delete Compatibility Item";
EditTableForm.LoadTableEdit("Compatibility", "Edit", compatibilityListBox.GetItemText(compatibilityListBox.SelectedItem));
EditTableForm.TopMost = true;
EditTableForm.Show();
}
private void addSuppDocButton_Click(object sender, EventArgs e)
{
String newRowCount = "";
int newRowCountNum = 0;
String suppumentalPath, suppumentalFileName, suppumentalExt;
Byte[] suppumentalData;
long suppumentalNumBytes;
// Get Suppumental Filename and Path
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
// openFileDialog1.Filter = "mdb files (*.mdb)|*.mdb|accdb files (*.accdb)|*.accdb";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
SqlCeConnection TecanSuppDocsDatabase = null;
TecanSuppDocsDatabase = new SqlCeConnection();
String dataPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
TecanSuppDocsDatabase.ConnectionString = "Data Source=|DataDirectory|\\TecanSuppDocs.sdf;Max Database Size=4000;Max Buffer Size=1024;Persist Security Info=False";
TecanSuppDocsDatabase.Open();
SqlCeCommand cmd = TecanSuppDocsDatabase.CreateCommand();
// Get the last DocID and add 1
cmd.CommandText = "SELECT DocID FROM SuppumentalDocs";
SqlCeDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
newRowCount = reader[0].ToString();
}
reader.Dispose();
newRowCountNum = Convert.ToInt16(newRowCount);
newRowCountNum++;
// OPen File and get all fields required to add to Supp DB
suppumentalPath = openFileDialog1.FileName;
FileInfo suppumentalFileInfo = new FileInfo(suppumentalPath);
suppumentalNumBytes = suppumentalFileInfo.Length;
FileStream suppumentalContents = new FileStream(suppumentalPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(suppumentalContents);
suppumentalData = br.ReadBytes((int)suppumentalNumBytes);
suppumentalContents.Close();
suppumentalFileName = suppumentalFileInfo.Name.ToLower();
suppumentalExt = suppumentalFileInfo.Extension.Replace(".", "").ToLower();
cmd.CommandText = "INSERT INTO SuppumentalDocs (DocID, DocExtension, Document, FileName)" +
" Values " +
"(@DocID, @DocExtension, @Document, @FileName)";
cmd.Parameters.AddWithValue("@DocId", newRowCountNum);
cmd.Parameters.AddWithValue("@DocExtension", suppumentalExt);
cmd.Parameters.AddWithValue("@Document", suppumentalData);
cmd.Parameters.AddWithValue("@FileName", suppumentalFileName);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("Please correct the Supplemental Filename \n\n " + suppumentalFileName + "\n\n" + ex.Message + "\n\n" + ex.TargetSite);
}
cmd.Parameters.Clear();
suppumentalContents.Dispose();
// br.Dispose();
// Clear and rebuild the Supp Filelist Display
allSuppDocsDataGridView.Rows.Clear();
cmd.CommandText = "SELECT DocID, FileName FROM SuppumentalDocs ORDER BY FileName";
reader = cmd.ExecuteReader();
while (reader.Read())
{
allSuppDocsDataGridView.Rows.Add(reader[0].ToString(), reader[1].ToString());
}
reader.Dispose();
TecanSuppDocsDatabase.Close();
}
}
// Rename or Delete supp doc
private void allSuppDocsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
String selectedDocID;
String selectedDocName;
DataGridViewRow row = this.allSuppDocsDataGridView.Rows[e.RowIndex];
selectedDocID = row.Cells[0].Value.ToString();
selectedDocName = row.Cells[1].Value.ToString();
currentTable = "SuppumentalDocs";
tableMaintenanceEdit EditTableForm = new tableMaintenanceEdit();
EditTableForm.SetAssociationFormInstance(this);
EditTableForm.SetMainFormInstance(mainForm);
EditTableForm.Text = "Edit or Delete Supplemental Document";
EditTableForm.LoadTableEdit("SuppumentalDocs", "Edit", selectedDocName);
EditTableForm.TopMost = true;
EditTableForm.Show();
}
// redisplay the affected listbox, grid after edit
public void returnFromEdit()
{
switch (currentTable)
{
case "Instrument":
this.instrumentTableAdapter.Fill(this.tecanPartsListDataSet.Instrument);
break;
case "Category":
this.categoryTableAdapter.Fill(this.tecanPartsListDataSet.Category);
break;
case "SubCategory":
this.subCategoryTableAdapter.Fill(this.tecanPartsListDataSet.SubCategory);
break;
case "SSPCategory":
this.sSPCategoryTableAdapter.Fill(this.tecanPartsListDataSet.SSPCategory);
break;
case "DBMembership":
this.dBMembershipTableAdapter.Fill(this.tecanPartsListDataSet.DBMembership);
break;
case "SalesType":
this.salesTypeTableAdapter.Fill(this.tecanPartsListDataSet.SalesType);
break;
case "Compatibility":
// Add Compatibilities to List
ArrayList theCompatibilities = new ArrayList();
SqlCeConnection TecanDatabase = null;
TecanDatabase = new SqlCeConnection();
// String dataPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
TecanDatabase.ConnectionString = "Data Source=|DataDirectory|\\TecanPartsList.sdf;Max Database Size=4000;Max Buffer Size=1024;Persist Security Info=False";
TecanDatabase.Open();
SqlCeCommand cmd = TecanDatabase.CreateCommand();
cmd.CommandText = "SELECT CompatibilityName, CompatibilityID FROM Compatibility ORDER BY CompatibilityName";
SqlCeDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
theCompatibilities.Add(new Compatibilities(reader[0].ToString(), reader[1].ToString()));
}
reader.Dispose();
TecanDatabase.Close();
compatibilityListBox.DataSource = theCompatibilities;
compatibilityListBox.DisplayMember = "Name";
compatibilityListBox.ValueMember = "ID";
break;
case "SuppumentalDocs":
// Clear and rebuild the Supp Filelist Display
allSuppDocsDataGridView.Rows.Clear();
SqlCeConnection TecanSuppDocsDatabase = null;
TecanSuppDocsDatabase = new SqlCeConnection();
String dataPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
TecanSuppDocsDatabase.ConnectionString = "Data Source=|DataDirectory|\\TecanSuppDocs.sdf;Max Database Size=4000;Max Buffer Size=1024;Persist Security Info=False";
TecanSuppDocsDatabase.Open();
SqlCeCommand cmd2 = TecanSuppDocsDatabase.CreateCommand();
cmd2.CommandText = "SELECT DocID, FileName FROM SuppumentalDocs ORDER BY FileName";
SqlCeDataReader reader2 = cmd2.ExecuteReader();
reader2 = cmd2.ExecuteReader();
while (reader2.Read())
{
allSuppDocsDataGridView.Rows.Add(reader2[0].ToString(), reader2[1].ToString());
}
reader2.Dispose();
TecanSuppDocsDatabase.Close();
this.suppumentalDocsTableAdapter.Fill(this.tecanPartsListDataSet.SuppumentalDocs);
break;
}
}
// get supp doc from DB and save to temp folder then display.
private void viewSuppDocButton_Click(object sender, EventArgs e)
{
// String selectedDocID;
String selectedDocName;
int rowIndex = 0;
// Get the filename and docID
Int32 selectedRowCount = this.allSuppDocsDataGridView.Rows.GetRowCount(DataGridViewElementStates.Selected);
if (selectedRowCount > 0)
{
for (int i = 0; i < selectedRowCount; i++)
{
rowIndex = allSuppDocsDataGridView.SelectedRows[i].Index;
}
}
DataGridViewRow row = this.allSuppDocsDataGridView.Rows[rowIndex];
// selectedDocID = row.Cells[0].Value.ToString();
selectedDocName = row.Cells[1].Value.ToString();
// Get the file contents from the database
SqlCeConnection TecanSuppDocsDatabase = null;
TecanSuppDocsDatabase = new SqlCeConnection();
String dataPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
TecanSuppDocsDatabase.ConnectionString = "Data Source=|DataDirectory|\\TecanSuppDocs.sdf;Max Database Size=4000;Max Buffer Size=1024;Persist Security Info=False";
TecanSuppDocsDatabase.Open();
SqlCeCommand cmd = TecanSuppDocsDatabase.CreateCommand();
cmd.CommandText = "SELECT Document FROM SuppumentalDocs WHERE FileName = '" + selectedDocName + "'";
SqlCeDataReader reader = cmd.ExecuteReader();
reader = cmd.ExecuteReader();
Byte[] documentData = new Byte[0];
while (reader.Read())
{
documentData = (byte[])reader[0];
}
reader.Dispose();
TecanSuppDocsDatabase.Close();
// Create the new file in temp directory
String tempFilePath = @AppDomain.CurrentDomain.BaseDirectory.ToString() + "temp";
System.IO.Directory.CreateDirectory(tempFilePath);
// If temp directory current contains any files, delete them
System.IO.DirectoryInfo tempFiles = new DirectoryInfo(tempFilePath);
foreach (FileInfo file in tempFiles.GetFiles())
{
try
{
file.Delete();
}
catch { }
}
String fullFilePathName = @tempFilePath + "\\" + selectedDocName;
try
{
System.IO.FileStream fs = System.IO.File.Create(fullFilePathName);
fs.Close();
// Write file contents into file
BinaryWriter Writer = null;
try
{
// Create a new stream to write to the file
Writer = new BinaryWriter(File.OpenWrite(fullFilePathName));
// Writer raw data
Writer.Write(documentData);
Writer.Flush();
Writer.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Process.Start(fullFilePathName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void assoSuppDocButton_Click(object sender, EventArgs e)
{
// String selectedDocID;
String selectedDocName;
int suppRowIndex = 0;
String partNum;
// Get the filename and docID
Int32 selectedsRowCount = this.allSuppDocsDataGridView.Rows.GetRowCount(DataGridViewElementStates.Selected);
Int32 selectedpItemCount = partsListListBox.SelectedItems.Count;
if (selectedsRowCount > 0 && selectedpItemCount > 0)
{
SqlCeConnection TecanDatabase = null;
TecanDatabase = new SqlCeConnection();
String dataPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
TecanDatabase.ConnectionString = "Data Source=|DataDirectory|\\TecanPartsList.sdf;Max Database Size=4000;Max Buffer Size=1024;Persist Security Info=False";
TecanDatabase.Open();
SqlCeCommand cmd = TecanDatabase.CreateCommand();
for (int s = 0; s < selectedsRowCount; s++)
{
suppRowIndex = allSuppDocsDataGridView.SelectedRows[s].Index;
DataGridViewRow srow = this.allSuppDocsDataGridView.Rows[suppRowIndex];
// selectedDocID = srow.Cells[0].Value.ToString();
selectedDocName = srow.Cells[1].Value.ToString();
foreach(DataRowView selectedpitem in partsListListBox.SelectedItems)
{
partNum = selectedpitem["SAPId"].ToString();
cmd.CommandText = "INSERT INTO SuppumentalDocs (SAPId, FileName) Values (@SAPId, @FileName)";
cmd.Parameters.AddWithValue("@SAPId", partNum);
cmd.Parameters.AddWithValue("@FileName", selectedDocName);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
}
TecanDatabase.Close();
this.suppumentalDocsTableAdapter.Fill(this.tecanPartsListDataSet.SuppumentalDocs);
}
}
private void suppumentalDocsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
String selectedSAPID;
String selectedDocName;
DataGridViewRow row = this.suppumentalDocsDataGridView.Rows[e.RowIndex];
selectedSAPID = row.Cells[0].Value.ToString();
selectedDocName = row.Cells[1].Value.ToString();
String msgString = "Are you certain you want to remove the SAPID - Supplemental Document association referenced below?\r\n\r\n" + selectedSAPID + " - " + selectedDocName;
if (MessageBox.Show(msgString, "Remove Assosciation",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
SqlCeConnection TecanDatabase = null;
try
{
TecanDatabase = new SqlCeConnection();
TecanDatabase.ConnectionString = "Data Source=|DataDirectory|\\TecanPartsList.sdf;Max Database Size=4000;Max Buffer Size=1024;Persist Security Info=False";
TecanDatabase.Open();
SqlCeCommand cmd = TecanDatabase.CreateCommand();
cmd.CommandText = "DELETE FROM SuppumentalDocs WHERE SAPId = '" + selectedSAPID + "' AND FileName = '" + selectedDocName + "'";
cmd.ExecuteNonQuery();
}
finally
{
TecanDatabase.Close();
}
}
}
}
}