12 using System.Configuration;
14 using System.Data.SqlClient;
16 using System.Windows.Forms;
28 private static SqlConnection
cn;
43 private static string DB_Connection = ConfigurationManager.ConnectionStrings[
"BB_db_CONNECTION"].ConnectionString;
61 #endregion Constructor 100 #endregion CreateTables 159 #endregion TableInsert 161 #region DataBaseInsert 179 using (SqlBulkCopy bulkInsert =
new SqlBulkCopy(
cn))
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"));
205 pIcon.Image = Properties.Resources.error;
208 MessageBox.Show(ex.ToString());
223 using (SqlBulkCopy bulkInsert =
new SqlBulkCopy(
cn))
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"));
258 pIcon.Image = Properties.Resources.error;
259 MessageBox.Show(
"Error inserting into database",
"Database Insert", MessageBoxButtons.OK, MessageBoxIcon.Error);
264 #endregion DataBaseInsert 275 if (TotalSize >= 1073741824)
277 decimal FileSize = decimal.Divide(TotalSize, 1073741824);
278 string msg =
string.Format(
"{0:##.##} GB", FileSize);
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);
283 else if (TotalSize >= 1048576 && TotalSize < 1073741824)
285 decimal FileSize = decimal.Divide(TotalSize, 1048576);
286 return string.Format(
"{0:##.##} MB", FileSize);
288 else if (TotalSize >= 1024 && TotalSize < 1048576)
290 decimal FileSize = decimal.Divide(TotalSize, 1024);
293 return string.Format(
"{0:##.##} KB", FileSize);
301 #endregion GetFileSize 322 pIcon.Image = Properties.Resources.loading__2016_10_29_16_24_24_UTC_;
328 OpenFileDialog openXML =
new OpenFileDialog();
330 if (openXML.ShowDialog() == DialogResult.OK)
336 FileInfo F_Info =
new FileInfo(
xmlFile.Text);
341 fName.Text = F_Info.Name;
344 if (F_Info.Name.Contains(
"thermostat"))
348 if (F_Info.Name.Contains(
"presence"))
354 #endregion BrowseFile 369 StreamReader Reader =
new StreamReader(FilePath);
373 if (Directory.Exists(FilePath) ==
false)
384 while ((
line = Reader.ReadLine()) !=
null)
400 line = Reader.ReadLine();
434 pIcon.Image = Properties.Resources.pass;
439 MessageBox.Show(
"Process Canceled Successfully",
"Extraction Process", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Windows.Forms.Label fName
static DataTable BBPresenseSensorsData
System.Windows.Forms.ProgressBar xmlProgress
static string DecryptData(string SensorData)
This method decrypt the sensor data
int blockSize
Variables for bulk insert
System.Windows.Forms.Button cancelBtn
void BBPSD2DB_Load(object sender, EventArgs e)
static void CreateThermostatTable()
Setting up data table for thermostat
delegate void UpdateProgressSub(int CurrentLine)
static string DB_Connection
Initializing Connection parameters
void browseFileBtn_Click(object sender, EventArgs e)
Executes the open file command
static DataTable BBThermostatData
void SplitIt()
Calls the splitXml method and notify the user of progress success or failure
static void BB_Database(string BBData)
parse sensor's data
void insertData()
Insert data into database
static string [] BBPSensorParsedData
System.Windows.Forms.Label fSize
System.Windows.Forms.PictureBox DBConnectionStatus
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
System.Windows.Forms.Label pPerc
System.Windows.Forms.PictureBox DBTransferStatus
void startBtn_Click(object sender, EventArgs e)
Start the process
void InitializeComponent()
Required method for Designer support - do not modify the contents of this method with the code editor...
void UpdateProgress(int CurrentLine)
Display the total lines written after split
void cancelBtn_Click(object sender, EventArgs e)
Cancel the process
static void CreatePresenseSensorTable()
Setting up data table for presence sensor
static string CalculateFileSize(long TotalSize)
Calculating File size
System.Windows.Forms.Button startBtn