‪Black Box
Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
BBPSensorData2DataBase.BBSD2DB Class Reference
Inheritance diagram for BBPSensorData2DataBase.BBSD2DB:

Public Member Functions

delegate void UpdateProgressSub (int CurrentLine)
 
 BBSD2DB ()
 
void SplitXML (string FilePath, int LineCount, int MaxXlmFiles, UpdateProgressSub Status, ref bool IsAbort)
 ‪Stream the encrypted file and decrypt it. If file too large, file is split More...
 
void SplitIt ()
 ‪Calls the splitXml method and notify the user of progress success or failure More...
 
void UpdateProgress (int CurrentLine)
 ‪Display the total lines written after split More...
 

Protected Member Functions

override void Dispose (bool disposing)
 ‪Clean up any resources being used. More...
 

Private Member Functions

void insertData ()
 ‪Insert data into database More...
 
void BBPSD2DB_Load (object sender, EventArgs e)
 
void browseFileBtn_Click (object sender, EventArgs e)
 ‪Executes the open file command More...
 
void cancelBtn_Click (object sender, EventArgs e)
 ‪Cancel the process More...
 
void startBtn_Click (object sender, EventArgs e)
 ‪Start the process More...
 
void InitializeComponent ()
 ‪Required method for Designer support - do not modify the contents of this method with the code editor. More...
 

Static Private Member Functions

static void CreatePresenseSensorTable ()
 ‪Setting up data table for presence sensor More...
 
static void CreateThermostatTable ()
 ‪Setting up data table for thermostat More...
 
static void BB_Database (string BBData)
 ‪parse sensor's data More...
 
static string CalculateFileSize (long TotalSize)
 ‪Calculating File size More...
 

Private Attributes

bool abortXmlProcess
 
int FileIndex = 0
 
string OutputFolder
 
int linesWritten = 0
 
long Results
 
int blockSize = 0
 ‪Variables for bulk insert More...
 
System.ComponentModel.IContainer components = null
 ‪Required designer variable. More...
 
System.Windows.Forms.TextBox xmlFile
 
System.Windows.Forms.Button browseFileBtn
 
System.Windows.Forms.Label fName
 
System.Windows.Forms.Label fSize
 
System.Windows.Forms.Button cancelBtn
 
System.Windows.Forms.Button startBtn
 
System.Windows.Forms.ProgressBar xmlProgress
 
System.Windows.Forms.GroupBox groupBox1
 
System.Windows.Forms.GroupBox groupBox2
 
System.Windows.Forms.GroupBox groupBox3
 
System.Windows.Forms.PictureBox DBConnectionStatus
 
System.Windows.Forms.GroupBox groupBox4
 
System.Windows.Forms.PictureBox DBTransferStatus
 
System.Windows.Forms.PictureBox pIcon
 
System.Windows.Forms.GroupBox groupBox5
 
System.Windows.Forms.GroupBox groupBox6
 
System.Windows.Forms.Label pPerc
 

Static Private Attributes

static string line
 
static string [] BBPSensorParsedData
 
static DataTable BBPresenseSensorsData = new DataTable("dbo.BBPresenseSensorsData")
 
static DataTable BBThermostatData = new DataTable("dbo.BBThermostatData")
 
static SqlConnection cn
 
static string tableType
 
static int linePerFile = 100
 
static int maxFileCount = 100
 
static string DB_Connection = ConfigurationManager.ConnectionStrings["BB_db_CONNECTION"].ConnectionString
 ‪Initializing Connection parameters More...
 

Detailed Description

Definition at line 20 of file BBSD2DB.cs.

Constructor & Destructor Documentation

◆ BBSD2DB()

BBPSensorData2DataBase.BBSD2DB.BBSD2DB ( )

Definition at line 56 of file BBSD2DB.cs.

57  {
59  }
‪void InitializeComponent()
‪Required method for Designer support - do not modify the contents of this method with the code editor...

Member Function Documentation

◆ BB_Database()

static void BBPSensorData2DataBase.BBSD2DB.BB_Database ( string  BBData)
staticprivate

‪parse sensor's data

Parameters
BBData

Getting Sensor Data parsed from string

Getting Sensor Data parsed from string

Definition at line 108 of file BBSD2DB.cs.

109  {
110  ‪BBPSensorParsedData = BBData.Split(',');
111 
112  if (‪tableType == "BBPSD")
113  {
115  try
116  {
124  ‪BBPresenseSensorsData.AcceptChanges();
125  }
126  catch (Exception)
127  {
128  //MessageBox.Show("Error inserting into data table", "Data Table Insert", MessageBoxButtons.OK, MessageBoxIcon.Error);
129  }
130  }
131  if (‪tableType == "BBTD")
132  {
134  try
135  {
150  ‪BBThermostatData.AcceptChanges();
151  }
152  catch (Exception)
153  {
154  //MessageBox.Show("Error inserting into data table", "Data Table Insert", MessageBoxButtons.OK, MessageBoxIcon.Error);
155  }
156  }
157  }
‪static DataTable BBPresenseSensorsData
Definition: BBSD2DB.cs:26
‪static DataTable BBThermostatData
Definition: BBSD2DB.cs:27
‪static string [] BBPSensorParsedData
Definition: BBSD2DB.cs:25
‪static string tableType
Definition: BBSD2DB.cs:29

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitXML().

◆ BBPSD2DB_Load()

void BBPSensorData2DataBase.BBSD2DB.BBPSD2DB_Load ( object  sender,
EventArgs  e 
)
private

Parameters
sender
e

Definition at line 307 of file BBSD2DB.cs.

308  {
311  }
‪static void CreateThermostatTable()
‪Setting up data table for thermostat
Definition: BBSD2DB.cs:82
‪static void CreatePresenseSensorTable()
‪Setting up data table for presence sensor
Definition: BBSD2DB.cs:68

Referenced by BBPSensorData2DataBase.BBSD2DB.InitializeComponent().

◆ browseFileBtn_Click()

void BBPSensorData2DataBase.BBSD2DB.browseFileBtn_Click ( object  sender,
EventArgs  e 
)
private

‪Executes the open file command

Parameters
sender
e

Getting file info

Definition at line 320 of file BBSD2DB.cs.

321  {
322  ‪pIcon.Image = Properties.Resources.loading__2016_10_29_16_24_24_UTC_;
323  ‪DBConnectionStatus.Image = Properties.Resources.trafficlight_yellow;
324  ‪DBTransferStatus.Image = Properties.Resources.trafficlight_yellow;
325  ‪xmlProgress.Value = 0;
326  ‪pPerc.Text = Convert.ToString((‪xmlProgress.Value / ‪xmlProgress.Maximum) * 100) + "%";
327 
328  OpenFileDialog openXML = new OpenFileDialog();
329 
330  if (openXML.ShowDialog() == DialogResult.OK)
331  {
332  ‪xmlFile.Text = openXML.FileName;
333  }
334 
336  FileInfo F_Info = new FileInfo(‪xmlFile.Text);
337  ‪Results = F_Info.Length;
338 
339  //Calculation file size and displaying file info
341  ‪fName.Text = F_Info.Name;
342 
343  // Determine which table to insert data
344  if (F_Info.Name.Contains("thermostat"))
345  {
346  ‪tableType = "BBTD";
347  }
348  if (F_Info.Name.Contains("presence"))
349  {
350  ‪tableType = "BBPSD";
351  }
352  }
‪System.Windows.Forms.Label fName
‪System.Windows.Forms.ProgressBar xmlProgress
‪System.Windows.Forms.Label fSize
‪System.Windows.Forms.PictureBox DBConnectionStatus
‪System.Windows.Forms.PictureBox pIcon
‪System.Windows.Forms.TextBox xmlFile
‪System.Windows.Forms.Label pPerc
‪System.Windows.Forms.PictureBox DBTransferStatus
‪static string tableType
Definition: BBSD2DB.cs:29
‪static string CalculateFileSize(long TotalSize)
‪Calculating File size
Definition: BBSD2DB.cs:273

Referenced by BBPSensorData2DataBase.BBSD2DB.InitializeComponent().

◆ CalculateFileSize()

static string BBPSensorData2DataBase.BBSD2DB.CalculateFileSize ( long  TotalSize)
staticprivate

‪Calculating File size

Parameters
TotalSize
Returns

Definition at line 273 of file BBSD2DB.cs.

274  {
275  if (TotalSize >= 1073741824)
276  {
277  decimal FileSize = decimal.Divide(TotalSize, 1073741824);
278  string msg = string.Format("{0:##.##} GB", FileSize);
279  ‪linePerFile = 1000;
280  MessageBox.Show("Application may show Not Responding due to file size \n " + "Current File Size: " + msg + ". During operation \n you may open log folder to check operation progress", "XML2SQL", MessageBoxButtons.OK, MessageBoxIcon.Information);
281  return string.Format("{0:##.##} GB", FileSize);
282  }
283  else if (TotalSize >= 1048576 && TotalSize < 1073741824)
284  {
285  decimal FileSize = decimal.Divide(TotalSize, 1048576);
286  return string.Format("{0:##.##} MB", FileSize);
287  }
288  else if (TotalSize >= 1024 && TotalSize < 1048576)
289  {
290  decimal FileSize = decimal.Divide(TotalSize, 1024);
291  //maxFileCount = 1;
292  //linePerFile = 10;
293  return string.Format("{0:##.##} KB", FileSize);
294  }
295  else
296  {
297  return "0 Bytes";
298  }
299  }

Referenced by BBPSensorData2DataBase.BBSD2DB.browseFileBtn_Click().

◆ cancelBtn_Click()

void BBPSensorData2DataBase.BBSD2DB.cancelBtn_Click ( object  sender,
EventArgs  e 
)
private

‪Cancel the process

Parameters
sender
e

Definition at line 467 of file BBSD2DB.cs.

468  {
469  ‪abortXmlProcess = true;
470  }

Referenced by BBPSensorData2DataBase.BBSD2DB.InitializeComponent().

◆ CreatePresenseSensorTable()

static void BBPSensorData2DataBase.BBSD2DB.CreatePresenseSensorTable ( )
staticprivate

‪Setting up data table for presence sensor

Definition at line 68 of file BBSD2DB.cs.

69  {
70  ‪BBPresenseSensorsData.Columns.Add("pLocation", typeof(string));
71  ‪BBPresenseSensorsData.Columns.Add("pStatus", typeof(string));
72  ‪BBPresenseSensorsData.Columns.Add("pTemperature", typeof(float));
73  ‪BBPresenseSensorsData.Columns.Add("pHumidity", typeof(float));
74  ‪BBPresenseSensorsData.Columns.Add("pTime", typeof(string));
75  ‪BBPresenseSensorsData.Columns.Add("pDate", typeof(DateTime));
76  ‪BBPresenseSensorsData.Columns.Add("pDateTimeStamp", typeof(DateTime));
77  }
‪static DataTable BBPresenseSensorsData
Definition: BBSD2DB.cs:26

Referenced by BBPSensorData2DataBase.BBSD2DB.BBPSD2DB_Load().

◆ CreateThermostatTable()

static void BBPSensorData2DataBase.BBSD2DB.CreateThermostatTable ( )
staticprivate

‪Setting up data table for thermostat

Definition at line 82 of file BBSD2DB.cs.

83  {
84  ‪BBThermostatData.Columns.Add("tHumidity", typeof(float));
85  ‪BBThermostatData.Columns.Add("tTemperature", typeof(float));
86  ‪BBThermostatData.Columns.Add("tT_heat", typeof(float));
87  ‪BBThermostatData.Columns.Add("tT_cool", typeof(float));
88  ‪BBThermostatData.Columns.Add("tTmode", typeof(string));
89  ‪BBThermostatData.Columns.Add("tFmode", typeof(string));
90  ‪BBThermostatData.Columns.Add("tHold", typeof(string));
91  ‪BBThermostatData.Columns.Add("tTstate", typeof(string));
92  ‪BBThermostatData.Columns.Add("tTtarget", typeof(string));
93  ‪BBThermostatData.Columns.Add("tProgramMode", typeof(string));
94  ‪BBThermostatData.Columns.Add("tFstate", typeof(string));
95  ‪BBThermostatData.Columns.Add("tTime", typeof(string));
96  ‪BBThermostatData.Columns.Add("tDate", typeof(DateTime));
97  ‪BBThermostatData.Columns.Add("tDateTimeStamp", typeof(string));
98  }
‪static DataTable BBThermostatData
Definition: BBSD2DB.cs:27

Referenced by BBPSensorData2DataBase.BBSD2DB.BBPSD2DB_Load().

◆ Dispose()

override void BBPSensorData2DataBase.BBSD2DB.Dispose ( bool  disposing)
protected

‪Clean up any resources being used.

Parameters
disposing‪true if managed resources should be disposed; otherwise, false.

Definition at line 14 of file BBSD2DB.Designer.cs.

15  {
16  if (disposing && (‪components != null))
17  {
18  ‪components.Dispose();
19  }
20  base.Dispose(disposing);
21  }
‪System.ComponentModel.IContainer components
‪Required designer variable.

◆ InitializeComponent()

void BBPSensorData2DataBase.BBSD2DB.InitializeComponent ( )
private

‪Required method for Designer support - do not modify the contents of this method with the code editor.

Definition at line 29 of file BBSD2DB.Designer.cs.

30  {
31  System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(‪BBSD2DB));
32  this.‪xmlFile = new System.Windows.Forms.TextBox();
33  this.‪fName = new System.Windows.Forms.Label();
34  this.‪fSize = new System.Windows.Forms.Label();
35  this.‪xmlProgress = new System.Windows.Forms.ProgressBar();
36  this.‪groupBox1 = new System.Windows.Forms.GroupBox();
37  this.‪browseFileBtn = new System.Windows.Forms.Button();
38  this.‪groupBox2 = new System.Windows.Forms.GroupBox();
39  this.‪pPerc = new System.Windows.Forms.Label();
40  this.‪pIcon = new System.Windows.Forms.PictureBox();
41  this.‪groupBox3 = new System.Windows.Forms.GroupBox();
42  this.‪DBConnectionStatus = new System.Windows.Forms.PictureBox();
43  this.‪groupBox4 = new System.Windows.Forms.GroupBox();
44  this.‪DBTransferStatus = new System.Windows.Forms.PictureBox();
45  this.‪cancelBtn = new System.Windows.Forms.Button();
46  this.‪startBtn = new System.Windows.Forms.Button();
47  this.‪groupBox5 = new System.Windows.Forms.GroupBox();
48  this.‪groupBox6 = new System.Windows.Forms.GroupBox();
49  this.‪groupBox1.SuspendLayout();
50  this.‪groupBox2.SuspendLayout();
51  ((System.ComponentModel.ISupportInitialize)(this.‪pIcon)).BeginInit();
52  this.‪groupBox3.SuspendLayout();
53  ((System.ComponentModel.ISupportInitialize)(this.‪DBConnectionStatus)).BeginInit();
54  this.‪groupBox4.SuspendLayout();
55  ((System.ComponentModel.ISupportInitialize)(this.‪DBTransferStatus)).BeginInit();
56  this.‪groupBox5.SuspendLayout();
57  this.‪groupBox6.SuspendLayout();
58  this.SuspendLayout();
59  //
60  // xmlFile
61  //
62  this.‪xmlFile.Location = new System.Drawing.Point(18, 28);
63  this.‪xmlFile.Name = "xmlFile";
64  this.‪xmlFile.Size = new System.Drawing.Size(231, 20);
65  this.‪xmlFile.TabIndex = 0;
66  //
67  // fName
68  //
69  this.‪fName.AutoSize = true;
70  this.‪fName.Location = new System.Drawing.Point(8, 16);
71  this.‪fName.Name = "fName";
72  this.‪fName.Size = new System.Drawing.Size(67, 13);
73  this.‪fName.TabIndex = 3;
74  this.‪fName.Text = "__________";
75  //
76  // fSize
77  //
78  this.‪fSize.AutoSize = true;
79  this.‪fSize.Location = new System.Drawing.Point(8, 41);
80  this.‪fSize.Name = "fSize";
81  this.‪fSize.Size = new System.Drawing.Size(67, 13);
82  this.‪fSize.TabIndex = 5;
83  this.‪fSize.Text = "__________";
84  //
85  // xmlProgress
86  //
87  this.‪xmlProgress.Location = new System.Drawing.Point(6, 19);
88  this.‪xmlProgress.Name = "xmlProgress";
89  this.‪xmlProgress.Size = new System.Drawing.Size(223, 16);
90  this.‪xmlProgress.TabIndex = 8;
91  //
92  // groupBox1
93  //
94  this.‪groupBox1.Controls.Add(this.‪browseFileBtn);
95  this.‪groupBox1.Controls.Add(this.‪xmlFile);
96  this.‪groupBox1.Location = new System.Drawing.Point(12, 12);
97  this.‪groupBox1.Name = "groupBox1";
98  this.‪groupBox1.Size = new System.Drawing.Size(299, 67);
99  this.‪groupBox1.TabIndex = 9;
100  this.‪groupBox1.TabStop = false;
101  this.‪groupBox1.Text = "Browse File";
102  //
103  // browseFileBtn
104  //
105  this.‪browseFileBtn.BackgroundImage = global::BBPSensorData2DataBase.Properties.Resources.open_file;
106  this.‪browseFileBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
107  this.‪browseFileBtn.Location = new System.Drawing.Point(255, 21);
108  this.‪browseFileBtn.Name = "browseFileBtn";
109  this.‪browseFileBtn.Size = new System.Drawing.Size(32, 32);
110  this.‪browseFileBtn.TabIndex = 1;
111  this.‪browseFileBtn.UseVisualStyleBackColor = true;
112  this.‪browseFileBtn.Click += new System.EventHandler(this.‪browseFileBtn_Click);
113  //
114  // groupBox2
115  //
116  this.‪groupBox2.Controls.Add(this.‪pPerc);
117  this.‪groupBox2.Controls.Add(this.‪pIcon);
118  this.‪groupBox2.Controls.Add(this.‪xmlProgress);
119  this.‪groupBox2.Location = new System.Drawing.Point(13, 238);
120  this.‪groupBox2.Name = "groupBox2";
121  this.‪groupBox2.Size = new System.Drawing.Size(299, 50);
122  this.‪groupBox2.TabIndex = 10;
123  this.‪groupBox2.TabStop = false;
124  this.‪groupBox2.Text = "Progress";
125  //
126  // pPerc
127  //
128  this.‪pPerc.AutoSize = true;
129  this.‪pPerc.Location = new System.Drawing.Point(236, 20);
130  this.‪pPerc.Name = "pPerc";
131  this.‪pPerc.Size = new System.Drawing.Size(21, 13);
132  this.‪pPerc.TabIndex = 10;
133  this.‪pPerc.Text = "0%";
134  //
135  // pIcon
136  //
137  this.‪pIcon.Image = global::BBPSensorData2DataBase.Properties.Resources.excl2;
138  this.‪pIcon.Location = new System.Drawing.Point(271, 19);
139  this.‪pIcon.Name = "pIcon";
140  this.‪pIcon.Size = new System.Drawing.Size(16, 16);
141  this.‪pIcon.TabIndex = 9;
142  this.‪pIcon.TabStop = false;
143  //
144  // groupBox3
145  //
146  this.‪groupBox3.Controls.Add(this.‪DBConnectionStatus);
147  this.‪groupBox3.Location = new System.Drawing.Point(12, 82);
148  this.‪groupBox3.Name = "groupBox3";
149  this.‪groupBox3.Size = new System.Drawing.Size(148, 72);
150  this.‪groupBox3.TabIndex = 11;
151  this.‪groupBox3.TabStop = false;
152  this.‪groupBox3.Text = "DB Connection Status";
153  //
154  // DBConnectionStatus
155  //
156  this.‪DBConnectionStatus.Image = global::BBPSensorData2DataBase.Properties.Resources.trafficlight_yellow;
157  this.‪DBConnectionStatus.Location = new System.Drawing.Point(23, 19);
158  this.‪DBConnectionStatus.Name = "DBConnectionStatus";
159  this.‪DBConnectionStatus.Size = new System.Drawing.Size(100, 47);
160  this.‪DBConnectionStatus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
161  this.‪DBConnectionStatus.TabIndex = 0;
162  this.‪DBConnectionStatus.TabStop = false;
163  //
164  // groupBox4
165  //
166  this.‪groupBox4.Controls.Add(this.‪DBTransferStatus);
167  this.‪groupBox4.Location = new System.Drawing.Point(12, 160);
168  this.‪groupBox4.Name = "groupBox4";
169  this.‪groupBox4.Size = new System.Drawing.Size(148, 72);
170  this.‪groupBox4.TabIndex = 12;
171  this.‪groupBox4.TabStop = false;
172  this.‪groupBox4.Text = "DB Transfer Status";
173  //
174  // DBTransferStatus
175  //
176  this.‪DBTransferStatus.Image = global::BBPSensorData2DataBase.Properties.Resources.trafficlight_yellow;
177  this.‪DBTransferStatus.Location = new System.Drawing.Point(23, 19);
178  this.‪DBTransferStatus.Name = "DBTransferStatus";
179  this.‪DBTransferStatus.Size = new System.Drawing.Size(100, 47);
180  this.‪DBTransferStatus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
181  this.‪DBTransferStatus.TabIndex = 0;
182  this.‪DBTransferStatus.TabStop = false;
183  //
184  // cancelBtn
185  //
186  this.‪cancelBtn.BackgroundImage = global::BBPSensorData2DataBase.Properties.Resources.Stop_icon;
187  this.‪cancelBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
188  this.‪cancelBtn.Location = new System.Drawing.Point(80, 19);
189  this.‪cancelBtn.Name = "cancelBtn";
190  this.‪cancelBtn.Size = new System.Drawing.Size(52, 46);
191  this.‪cancelBtn.TabIndex = 6;
192  this.‪cancelBtn.UseVisualStyleBackColor = true;
193  this.‪cancelBtn.Click += new System.EventHandler(this.‪cancelBtn_Click);
194  //
195  // startBtn
196  //
197  this.‪startBtn.BackgroundImage = global::BBPSensorData2DataBase.Properties.Resources.player_play;
198  this.‪startBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
199  this.‪startBtn.Location = new System.Drawing.Point(6, 18);
200  this.‪startBtn.Name = "startBtn";
201  this.‪startBtn.Size = new System.Drawing.Size(53, 47);
202  this.‪startBtn.TabIndex = 7;
203  this.‪startBtn.UseVisualStyleBackColor = true;
204  this.‪startBtn.Click += new System.EventHandler(this.‪startBtn_Click);
205  //
206  // groupBox5
207  //
208  this.‪groupBox5.Controls.Add(this.‪startBtn);
209  this.‪groupBox5.Controls.Add(this.‪cancelBtn);
210  this.‪groupBox5.Location = new System.Drawing.Point(167, 83);
211  this.‪groupBox5.Name = "groupBox5";
212  this.‪groupBox5.Size = new System.Drawing.Size(144, 71);
213  this.‪groupBox5.TabIndex = 13;
214  this.‪groupBox5.TabStop = false;
215  this.‪groupBox5.Text = "Controls";
216  //
217  // groupBox6
218  //
219  this.‪groupBox6.Controls.Add(this.‪fName);
220  this.‪groupBox6.Controls.Add(this.‪fSize);
221  this.‪groupBox6.Location = new System.Drawing.Point(166, 160);
222  this.‪groupBox6.Name = "groupBox6";
223  this.‪groupBox6.Size = new System.Drawing.Size(145, 72);
224  this.‪groupBox6.TabIndex = 14;
225  this.‪groupBox6.TabStop = false;
226  this.‪groupBox6.Text = "File Information";
227  //
228  // BBSD2DB
229  //
230  this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
231  this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
232  this.ClientSize = new System.Drawing.Size(324, 297);
233  this.Controls.Add(this.‪groupBox6);
234  this.Controls.Add(this.‪groupBox5);
235  this.Controls.Add(this.‪groupBox4);
236  this.Controls.Add(this.‪groupBox3);
237  this.Controls.Add(this.‪groupBox2);
238  this.Controls.Add(this.‪groupBox1);
239  this.DoubleBuffered = true;
240  this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
241  this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
242  this.MaximizeBox = false;
243  this.MinimizeBox = false;
244  this.Name = "BBSD2DB";
245  this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
246  this.Text = "Data 2 DataBase";
247  this.Load += new System.EventHandler(this.‪BBPSD2DB_Load);
248  this.‪groupBox1.ResumeLayout(false);
249  this.‪groupBox1.PerformLayout();
250  this.‪groupBox2.ResumeLayout(false);
251  this.‪groupBox2.PerformLayout();
252  ((System.ComponentModel.ISupportInitialize)(this.‪pIcon)).EndInit();
253  this.‪groupBox3.ResumeLayout(false);
254  ((System.ComponentModel.ISupportInitialize)(this.‪DBConnectionStatus)).EndInit();
255  this.‪groupBox4.ResumeLayout(false);
256  ((System.ComponentModel.ISupportInitialize)(this.‪DBTransferStatus)).EndInit();
257  this.‪groupBox5.ResumeLayout(false);
258  this.‪groupBox6.ResumeLayout(false);
259  this.‪groupBox6.PerformLayout();
260  this.ResumeLayout(false);
261 
262  }
‪System.Windows.Forms.Label fName
‪System.Windows.Forms.GroupBox groupBox2
‪System.Windows.Forms.ProgressBar xmlProgress
‪System.Windows.Forms.Button cancelBtn
‪void BBPSD2DB_Load(object sender, EventArgs e)
Definition: BBSD2DB.cs:307
‪void browseFileBtn_Click(object sender, EventArgs e)
‪Executes the open file command
Definition: BBSD2DB.cs:320
‪System.Windows.Forms.GroupBox groupBox1
‪System.Windows.Forms.GroupBox groupBox5
‪System.Windows.Forms.Label fSize
‪System.Windows.Forms.GroupBox groupBox4
‪System.Windows.Forms.PictureBox DBConnectionStatus
‪System.Windows.Forms.PictureBox pIcon
‪System.Windows.Forms.TextBox xmlFile
‪System.Windows.Forms.Label pPerc
‪System.Windows.Forms.PictureBox DBTransferStatus
‪System.Windows.Forms.GroupBox groupBox3
‪System.Windows.Forms.Button browseFileBtn
‪void startBtn_Click(object sender, EventArgs e)
‪Start the process
Definition: BBSD2DB.cs:477
‪void cancelBtn_Click(object sender, EventArgs e)
‪Cancel the process
Definition: BBSD2DB.cs:467
‪System.Windows.Forms.GroupBox groupBox6
‪System.Windows.Forms.Button startBtn

Referenced by BBPSensorData2DataBase.BBSD2DB.BBSD2DB().

◆ insertData()

void BBPSensorData2DataBase.BBSD2DB.insertData ( )
private

‪Insert data into database

Definition at line 166 of file BBSD2DB.cs.

167  {
168  // Presence Sensor table
169  if (‪tableType == "BBPSD")
170  {
171  try
172  {
173  ‪cn = new SqlConnection(‪DB_Connection);
174  //Open connection to do bulk insert
175  ‪cn.Open();
176  ‪DBConnectionStatus.Image = Properties.Resources.trafficlight_green;
177  ‪DBTransferStatus.Image = Properties.Resources.trafficlight_green;
178 
179  using (SqlBulkCopy bulkInsert = new SqlBulkCopy(‪cn))
180  {
181  // Destination and source table have to have the same name and column name
182  // and data type.
183  bulkInsert.DestinationTableName = ‪BBPresenseSensorsData.TableName;
184 
185  // The layout for the bulk insert is DataTable Column name , DataBase Column name
186  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("pLocation", "pLocation"));
187  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("pStatus", "pStatus"));
188  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("pTemperature", "pTemperature"));
189  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("pHumidity", "pHumidity"));
190  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("pTime", "pTime"));
191  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("pDate", "pDate"));
192  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("pDateTimeStamp", "pDateTimeStamp"));
193  bulkInsert.WriteToServer(‪BBPresenseSensorsData);
194  bulkInsert.Close();
195  }
196 
197  //If successful the DataTable is cleared and is ready for new data
198  ‪BBPresenseSensorsData.Rows.Clear();
199 
200  //Close connection after insertion
201  ‪cn.Close();
202  }
203  catch (Exception ex)
204  {
205  ‪pIcon.Image = Properties.Resources.error;
206  ‪DBConnectionStatus.Image = Properties.Resources.trafficlight_red;
207  ‪DBTransferStatus.Image = Properties.Resources.trafficlight_red;
208  MessageBox.Show(ex.ToString());
209  }
210  }
211  // Thermostat Table
212  if (‪tableType == "BBTD")
213  {
214  ‪DBConnectionStatus.Image = Properties.Resources.trafficlight_green;
215  try
216  {
217  ‪cn = new SqlConnection(‪DB_Connection);
218  //Open connection to do bulk insert
219  ‪cn.Open();
220 
221  ‪DBTransferStatus.Image = Properties.Resources.trafficlight_green;
222 
223  using (SqlBulkCopy bulkInsert = new SqlBulkCopy(‪cn))
224  {
225  // Destination and source table have to have the same name and column name
226  // and data type.
227  bulkInsert.DestinationTableName = ‪BBThermostatData.TableName;
228 
229  // The layout for the bulk insert is DataTable Column name , DataBase Column name
230  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tHumidity", "tHumidity"));
231  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tTemperature", "tTemperature"));
232  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tT_heat", "tT_heat"));
233  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tT_cool", "tT_cool"));
234  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tTmode", "tTmode"));
235  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tFmode", "tFmode"));
236  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tHold", "tHold"));
237  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tTstate", "tTstate"));
238  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tTtarget", "tTtarget"));
239  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tProgramMode", "tProgramMode"));
240  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tFstate", "tFstate"));
241  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tTime", "tTime"));
242  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tDate", "tDate"));
243  bulkInsert.ColumnMappings.Add(new SqlBulkCopyColumnMapping("tDateTimeStamp", "tDateTimeStamp"));
244  bulkInsert.WriteToServer(‪BBThermostatData);
245  bulkInsert.Close();
246  }
247 
248  //If successful the DataTable is cleared and is ready for new data
249  ‪BBThermostatData.Rows.Clear();
250 
251  //Close connection after insertion
252  ‪cn.Close();
253  }
254  catch
255  {
256  ‪DBConnectionStatus.Image = Properties.Resources.trafficlight_red;
257  ‪DBTransferStatus.Image = Properties.Resources.trafficlight_red;
258  ‪pIcon.Image = Properties.Resources.error;
259  MessageBox.Show("Error inserting into database", "Database Insert", MessageBoxButtons.OK, MessageBoxIcon.Error);
260  }
261  }
262  }
‪static DataTable BBPresenseSensorsData
Definition: BBSD2DB.cs:26
‪static string DB_Connection
‪Initializing Connection parameters
Definition: BBSD2DB.cs:43
‪static DataTable BBThermostatData
Definition: BBSD2DB.cs:27
‪System.Windows.Forms.PictureBox DBConnectionStatus
‪System.Windows.Forms.PictureBox pIcon
‪System.Windows.Forms.PictureBox DBTransferStatus
‪static string tableType
Definition: BBSD2DB.cs:29
‪static SqlConnection cn
Definition: BBSD2DB.cs:28

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitXML().

◆ SplitIt()

void BBPSensorData2DataBase.BBSD2DB.SplitIt ( )

‪Calls the splitXml method and notify the user of progress success or failure

Definition at line 423 of file BBSD2DB.cs.

424  {
425  ‪startBtn.Enabled = false;
426  ‪cancelBtn.Enabled = true;
427 
428  try
429  {
431 
432  if (!‪abortXmlProcess)
433  {
434  ‪pIcon.Image = Properties.Resources.pass;
435  }
436  else
437  {
438  ‪abortXmlProcess = false;
439  MessageBox.Show("Process Canceled Successfully", "Extraction Process", MessageBoxButtons.OK, MessageBoxIcon.Error);
440  }
441  }
442  catch (Exception)
443  {
444  //MessageBox.Show(ex.Message, "Splitting Process", MessageBoxButtons.OK, MessageBoxIcon.Error);
445  }
446  finally
447  {
448  ‪startBtn.Enabled = true;
449  ‪cancelBtn.Enabled = false;
450  }
451  }
‪System.Windows.Forms.Button cancelBtn
‪System.Windows.Forms.PictureBox pIcon
‪System.Windows.Forms.TextBox xmlFile
‪void SplitXML(string FilePath, int LineCount, int MaxXlmFiles, UpdateProgressSub Status, ref bool IsAbort)
‪Stream the encrypted file and decrypt it. If file too large, file is split
Definition: BBSD2DB.cs:366
‪void UpdateProgress(int CurrentLine)
‪Display the total lines written after split
Definition: BBSD2DB.cs:457
‪System.Windows.Forms.Button startBtn

Referenced by BBPSensorData2DataBase.BBSD2DB.startBtn_Click().

◆ SplitXML()

void BBPSensorData2DataBase.BBSD2DB.SplitXML ( string  FilePath,
int  LineCount,
int  MaxXlmFiles,
UpdateProgressSub  Status,
ref bool  IsAbort 
)

‪Stream the encrypted file and decrypt it. If file too large, file is split

Parameters
FilePath
LineCount
MaxXlmFiles
Status
IsAbort

Definition at line 366 of file BBSD2DB.cs.

367  {
368  // Open the XML file for reading
369  StreamReader Reader = new StreamReader(FilePath);
370 
371  // Create the output directory
372  ‪OutputFolder = FilePath + "_Log";
373  if (Directory.Exists(FilePath) == false)
374  {
375  Directory.CreateDirectory(‪OutputFolder);
376  }
377 
378  //Initializing progress bar parameters
379  ‪xmlProgress.Maximum = MaxXlmFiles;
380  ‪xmlProgress.Step = 1;
381 
382  ‪blockSize = 0;
383 
384  while ((‪line = Reader.ReadLine()) != null)
385  {
386  //Update progress bar
387  ‪xmlProgress.PerformStep();
388 
389  ‪pPerc.Text = Convert.ToString((‪xmlProgress.Value / ‪xmlProgress.Maximum) * 100) + "%";
390 
391  ‪blockSize++;
392 
393  // Update progress
394  ‪FileIndex += 1;
395  if (Status != null)
396  {
397  Status.Invoke((‪FileIndex - 1) * LineCount);
398  }
399 
400  ‪line = Reader.ReadLine();
401 
402  //XLM extraction
404 
405  ‪blockSize++;
406 
407  if (‪blockSize == 1000)
408  {
409  ‪blockSize = 0;
410  ‪insertData();
411  }
412  }
413 
414  Reader.Close();
415  ‪insertData();
416  }
‪System.Windows.Forms.ProgressBar xmlProgress
‪static string DecryptData(string SensorData)
‪This method decrypt the sensor data
‪int blockSize
‪Variables for bulk insert
Definition: BBSD2DB.cs:50
‪static void BB_Database(string BBData)
‪parse sensor's data
Definition: BBSD2DB.cs:108
‪void insertData()
‪Insert data into database
Definition: BBSD2DB.cs:166
‪System.Windows.Forms.Label pPerc

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitIt().

◆ startBtn_Click()

void BBPSensorData2DataBase.BBSD2DB.startBtn_Click ( object  sender,
EventArgs  e 
)
private

‪Start the process

Parameters
sender
e

Definition at line 477 of file BBSD2DB.cs.

478  {
479  ‪SplitIt();
480  }
‪void SplitIt()
‪Calls the splitXml method and notify the user of progress success or failure
Definition: BBSD2DB.cs:423

Referenced by BBPSensorData2DataBase.BBSD2DB.InitializeComponent().

◆ UpdateProgress()

void BBPSensorData2DataBase.BBSD2DB.UpdateProgress ( int  CurrentLine)

‪Display the total lines written after split

Parameters
CurrentLine

Definition at line 457 of file BBSD2DB.cs.

458  {
459  ‪linesWritten = CurrentLine;
460  }

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitIt().

◆ UpdateProgressSub()

delegate void BBPSensorData2DataBase.BBSD2DB.UpdateProgressSub ( int  CurrentLine)

Field Documentation

◆ abortXmlProcess

bool BBPSensorData2DataBase.BBSD2DB.abortXmlProcess
private

◆ BBPresenseSensorsData

DataTable BBPSensorData2DataBase.BBSD2DB.BBPresenseSensorsData = new DataTable("dbo.BBPresenseSensorsData")
staticprivate

◆ BBPSensorParsedData

string [] BBPSensorData2DataBase.BBSD2DB.BBPSensorParsedData
staticprivate

Definition at line 25 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.BB_Database().

◆ BBThermostatData

DataTable BBPSensorData2DataBase.BBSD2DB.BBThermostatData = new DataTable("dbo.BBThermostatData")
staticprivate

◆ blockSize

int BBPSensorData2DataBase.BBSD2DB.blockSize = 0
private

‪Variables for bulk insert

Definition at line 50 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitXML().

◆ browseFileBtn

System.Windows.Forms.Button BBPSensorData2DataBase.BBSD2DB.browseFileBtn
private

◆ cancelBtn

System.Windows.Forms.Button BBPSensorData2DataBase.BBSD2DB.cancelBtn
private

◆ cn

SqlConnection BBPSensorData2DataBase.BBSD2DB.cn
staticprivate

Definition at line 28 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.insertData().

◆ components

System.ComponentModel.IContainer BBPSensorData2DataBase.BBSD2DB.components = null
private

‪Required designer variable.

Definition at line 8 of file BBSD2DB.Designer.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.Dispose().

◆ DB_Connection

string BBPSensorData2DataBase.BBSD2DB.DB_Connection = ConfigurationManager.ConnectionStrings["BB_db_CONNECTION"].ConnectionString
staticprivate

‪Initializing Connection parameters

Definition at line 43 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.insertData().

◆ DBConnectionStatus

System.Windows.Forms.PictureBox BBPSensorData2DataBase.BBSD2DB.DBConnectionStatus
private

◆ DBTransferStatus

System.Windows.Forms.PictureBox BBPSensorData2DataBase.BBSD2DB.DBTransferStatus
private

◆ FileIndex

int BBPSensorData2DataBase.BBSD2DB.FileIndex = 0
private

Definition at line 34 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitXML().

◆ fName

System.Windows.Forms.Label BBPSensorData2DataBase.BBSD2DB.fName
private

◆ fSize

System.Windows.Forms.Label BBPSensorData2DataBase.BBSD2DB.fSize
private

◆ groupBox1

System.Windows.Forms.GroupBox BBPSensorData2DataBase.BBSD2DB.groupBox1
private

◆ groupBox2

System.Windows.Forms.GroupBox BBPSensorData2DataBase.BBSD2DB.groupBox2
private

◆ groupBox3

System.Windows.Forms.GroupBox BBPSensorData2DataBase.BBSD2DB.groupBox3
private

◆ groupBox4

System.Windows.Forms.GroupBox BBPSensorData2DataBase.BBSD2DB.groupBox4
private

◆ groupBox5

System.Windows.Forms.GroupBox BBPSensorData2DataBase.BBSD2DB.groupBox5
private

◆ groupBox6

System.Windows.Forms.GroupBox BBPSensorData2DataBase.BBSD2DB.groupBox6
private

◆ line

string BBPSensorData2DataBase.BBSD2DB.line
staticprivate

Definition at line 24 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitXML().

◆ linePerFile

int BBPSensorData2DataBase.BBSD2DB.linePerFile = 100
staticprivate

◆ linesWritten

int BBPSensorData2DataBase.BBSD2DB.linesWritten = 0
private

Definition at line 36 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.UpdateProgress().

◆ maxFileCount

int BBPSensorData2DataBase.BBSD2DB.maxFileCount = 100
staticprivate

Definition at line 38 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitIt().

◆ OutputFolder

string BBPSensorData2DataBase.BBSD2DB.OutputFolder
private

Definition at line 35 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.SplitXML().

◆ pIcon

System.Windows.Forms.PictureBox BBPSensorData2DataBase.BBSD2DB.pIcon
private

◆ pPerc

System.Windows.Forms.Label BBPSensorData2DataBase.BBSD2DB.pPerc
private

◆ Results

long BBPSensorData2DataBase.BBSD2DB.Results
private

Definition at line 45 of file BBSD2DB.cs.

Referenced by BBPSensorData2DataBase.BBSD2DB.browseFileBtn_Click().

◆ startBtn

System.Windows.Forms.Button BBPSensorData2DataBase.BBSD2DB.startBtn
private

◆ tableType

string BBPSensorData2DataBase.BBSD2DB.tableType
staticprivate

◆ xmlFile

System.Windows.Forms.TextBox BBPSensorData2DataBase.BBSD2DB.xmlFile
private

◆ xmlProgress

System.Windows.Forms.ProgressBar BBPSensorData2DataBase.BBSD2DB.xmlProgress
private

The documentation for this class was generated from the following files: