Example #1
0
        public void sqlAddAssets()
        {
            //sets up the data set for the csv file

            StreamReader sr      = new StreamReader(openFileDialog.FileName);
            String       csvData = File.ReadAllText(openFileDialog.FileName);

            String[] csvRows = csvData.Split("\r".ToCharArray());
            //set the max val
            progressBar.BeginInvoke(
                new Action(() =>
            {
                progressBar.Maximum = csvRows.Length;
            }
                           ));

            //get the asset type selected
            String assetType = "none chosen";

            assetTypetextBox.BeginInvoke(
                new Action(() =>
            {
                assetType = assetTypetextBox.Text.ToString();
            }
                           ));

            //adds the assets to the sql database
            for (int i = 0; i < csvRows.Length; i++)
            {
                String[] columnVals = csvRows[i].Split(',');

                int USERID       = 0;
                int ASSETID      = 1;
                int SERIALNUMBER = 2;

                //adding assets to database


                int errorCode = sqlTran.addAssetToSQLDatabase(assetType, columnVals[SERIALNUMBER], columnVals[ASSETID], columnVals[USERID]);

                switch (errorCode)
                {
                case 3:
                    DetailsBox.BeginInvoke(
                        new Action(() =>
                    {
                        DetailsBox.SelectionColor = System.Drawing.Color.Red;
                        DetailsBox.AppendText("ERROR! Asset was already added to the database! nothing was done with this asset" + Environment.NewLine);
                        DetailsBox.ScrollToCaret();
                        DetailsBox.SelectionColor = System.Drawing.Color.White;
                    }
                                   ));
                    break;

                case 1:
                    DetailsBox.BeginInvoke(
                        new Action(() =>
                    {
                        DetailsBox.SelectionColor = System.Drawing.Color.Yellow;
                        DetailsBox.AppendText("Added Asset ID: " + columnVals[ASSETID] + " Serial Number: " + columnVals[SERIALNUMBER] + "However, the asset was left unassigned because there was no User ID specified" + Environment.NewLine);
                        DetailsBox.ScrollToCaret();
                        DetailsBox.SelectionColor = System.Drawing.Color.White;
                    }
                                   ));
                    break;

                case 2:
                    DetailsBox.BeginInvoke(
                        new Action(() =>
                    {
                        DetailsBox.SelectionColor = System.Drawing.Color.Red;
                        DetailsBox.AppendText("ERROR! Asset could not be added!" + Environment.NewLine);
                        DetailsBox.ScrollToCaret();
                        DetailsBox.SelectionColor = System.Drawing.Color.White;
                    }
                                   ));
                    break;

                case 5:
                    DetailsBox.BeginInvoke(
                        new Action(() =>
                    {
                        DetailsBox.SelectionColor = System.Drawing.Color.Green;
                        DetailsBox.AppendText("Added Asset ID: " + columnVals[ASSETID] + " Serial Number: " + columnVals[SERIALNUMBER] + "AND Asset was linked!" + Environment.NewLine);
                        DetailsBox.ScrollToCaret();
                        DetailsBox.SelectionColor = System.Drawing.Color.White;
                    }
                                   ));
                    break;

                case 4:
                    DetailsBox.BeginInvoke(
                        new Action(() =>
                    {
                        DetailsBox.SelectionColor = System.Drawing.Color.Yellow;
                        DetailsBox.AppendText("Added Asset ID: " + columnVals[ASSETID] + " Serial Number: " + columnVals[SERIALNUMBER] + "However, ASSET COULD NOT BE LINKED TO SPECIFIED USER!!" + Environment.NewLine);
                        DetailsBox.ScrollToCaret();
                        DetailsBox.SelectionColor = System.Drawing.Color.White;
                    }
                                   ));
                    break;

                default:
                    DetailsBox.BeginInvoke(
                        new Action(() =>
                    {
                        DetailsBox.SelectionColor = System.Drawing.Color.Red;
                        DetailsBox.AppendText("UNKNOWN ERROR CHECK SOURCE CODE!" + Environment.NewLine);
                        DetailsBox.ScrollToCaret();
                        DetailsBox.SelectionColor = System.Drawing.Color.White;
                    }
                                   ));
                    break;
                }



                progressBar.BeginInvoke(
                    new Action(() =>
                {
                    progressBar.Value = i;
                }
                               ));

                Thread.Sleep(10);
            }
            VictoryPlayer.Play();
        }
 private void TrapCountermeasureForm_Shown(object sender, EventArgs e)
 {
     DetailsBox.Focus();
     DetailsBox.SelectAll();
 }