public void GenerateTestData(Action <EventArgs> callback)
        {
            if (NumberOfRecordsToGenerate > 0)
            {
                IsTestDataGenerationInProgress = true;

                BackgroundWorker worker = new BackgroundWorker();

                List <Employee> list = new List <Employee>();

                worker.DoWork += delegate(object sender, DoWorkEventArgs e)
                {
                    for (int i = 0; i < NumberOfRecordsToGenerate; i++)
                    {
                        initRandomGenerator();

                        Employee emp = new Employee();

                        fillWithTheRandomData(emp, i);

                        list.Add(emp);

                        TestDataGenerationPercent = ((double)i / NumberOfRecordsToGenerate) * 100;
                    }
                };

                worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
                {
                    EmployeeStatuses     = new ObservableCollection <EmployeeStatus>(STATUS.ToList());
                    EmployeePositionList = new ObservableCollection <EmployeePosition>(POSITIONS.ToList());

                    EmployeeList = new ObservableCollection <Employee>(list);

                    Employee[] tmpArray = new Employee[EmployeeList.Count];
                    EmployeeList.ToList().CopyTo(tmpArray);
                    EmployeeListCopy = new ObservableCollection <Employee>(tmpArray.ToList());

                    IsTestDataGenerationInProgress = false;

                    if (callback != null)
                    {
                        callback(EventArgs.Empty);
                    }
                };

                worker.RunWorkerAsync();
            }
        }
示例#2
0
        public void GenerateTestData(Action <EventArgs> callback)
        {
            if (NumberOfRecordsToGenerate > 0)
            {
                IsTestDataGenerationInProgress = true;

                BackgroundWorker worker = new BackgroundWorker();

                List <DataItem> list = new List <DataItem>();

                worker.DoWork += delegate(object sender, DoWorkEventArgs e)
                {
                    // ********************************************************************
                    // Code Generated by Ideal Tools Organizer at http://idealautomate.com
                    // ********************************************************************
                    // Define Query String
                    //  "Select * from jobapplications  where dateadded >  cast('06/20/2020' as date)" +
                    string queryString =
                        "Select * from jobapplications where dateadded >  cast('07/01/2020' as date) -- and applicationstatus is null -- where jobboard = 'dice' and location <> 'remote' and applicationstatus is null" +
                        "";
                    // Define Connection String
                    string strConnectionString = null;
                    strConnectionString = @"Data Source=.\SQLEXPRESS02;Initial Catalog=IdealAutomateDB;Integrated Security=SSPI";
                    // Define .net fields to hold each column selected in query
                    String   str_jobapplications_JobUrl;
                    String   str_jobapplications_JobBoard;
                    String   str_jobapplications_JobTitle;
                    String   str_jobapplications_CompanyTitle;
                    DateTime dt_jobapplications_DateAdded;
                    DateTime dt_jobapplications_DateLastModified;
                    DateTime dt_jobapplications_DateApplied;
                    String   str_jobapplications_ApplicationStatus;
                    String   str_jobapplications_Keyword;
                    String   str_jobapplications_Location;
                    String   str_jobapplications_Comments;
                    // Define a datatable that we will define columns in to match the columns
                    // selected in the query. We will use sqldatareader to read the results
                    // from the sql query one row at a time. Then we will add each of those
                    // rows to the datatable - this is where you can modify the information
                    // returned from the sql query one row at a time. Finally, we will
                    // bind the table to the gridview.
                    DataTable dt = new DataTable();

                    using (SqlConnection connection = new SqlConnection(strConnectionString))
                    {
                        SqlCommand command = new SqlCommand(queryString, connection);

                        connection.Open();

                        SqlDataReader reader = command.ExecuteReader();
                        // Define a column in the table for each column that was selected in the sql query
                        // We do this before the sqldatareader loop because the columns only need to be
                        // defined once.

                        DataColumn column = null;
                        column = new DataColumn("jobapplications_JobUrl", Type.GetType("System.String"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_JobBoard", Type.GetType("System.String"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_JobTitle", Type.GetType("System.String"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_CompanyTitle", Type.GetType("System.String"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_DateAdded", Type.GetType("System.DateTime"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_DateLastModified", Type.GetType("System.DateTime"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_DateApplied", Type.GetType("System.DateTime"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_ApplicationStatus", Type.GetType("System.String"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_Keyword", Type.GetType("System.String"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_Location", Type.GetType("System.String"));
                        dt.Columns.Add(column);
                        column = new DataColumn("jobapplications_Comments", Type.GetType("System.String"));
                        dt.Columns.Add(column);
                        // Read the results from the sql query one row at a time
                        while (reader.Read())
                        {
                            // define a new datatable row to hold the row read from the sql query
                            DataRow dataRow = dt.NewRow();
                            // Move each field from the reader to a holding field in .net
                            // ********************************************************************
                            // The holding field in .net is where you can alter the contents of the
                            // field
                            // ********************************************************************
                            // Then, you move the contents of the holding .net field to the column in
                            // the datarow that you defined above
                            if (!(reader.IsDBNull(0)))
                            {
                                str_jobapplications_JobUrl        = reader.GetString(0);
                                dataRow["jobapplications_JobUrl"] = str_jobapplications_JobUrl;
                            }
                            if (!(reader.IsDBNull(1)))
                            {
                                str_jobapplications_JobBoard        = reader.GetString(1);
                                dataRow["jobapplications_JobBoard"] = str_jobapplications_JobBoard;
                            }
                            if (!(reader.IsDBNull(2)))
                            {
                                str_jobapplications_JobTitle        = reader.GetString(2);
                                dataRow["jobapplications_JobTitle"] = str_jobapplications_JobTitle;
                            }
                            if (!(reader.IsDBNull(3)))
                            {
                                str_jobapplications_CompanyTitle        = reader.GetString(3);
                                dataRow["jobapplications_CompanyTitle"] = str_jobapplications_CompanyTitle;
                            }
                            if (!(reader.IsDBNull(4)))
                            {
                                dt_jobapplications_DateAdded         = reader.GetDateTime(4);
                                dataRow["jobapplications_DateAdded"] = dt_jobapplications_DateAdded;
                            }
                            if (!(reader.IsDBNull(5)))
                            {
                                dt_jobapplications_DateLastModified         = reader.GetDateTime(5);
                                dataRow["jobapplications_DateLastModified"] = dt_jobapplications_DateLastModified;
                            }
                            if (!(reader.IsDBNull(6)))
                            {
                                dt_jobapplications_DateApplied         = reader.GetDateTime(6);
                                dataRow["jobapplications_DateApplied"] = dt_jobapplications_DateApplied;
                            }
                            if (!(reader.IsDBNull(7)))
                            {
                                str_jobapplications_ApplicationStatus        = reader.GetString(7);
                                dataRow["jobapplications_ApplicationStatus"] = str_jobapplications_ApplicationStatus;
                            }
                            if (!(reader.IsDBNull(8)))
                            {
                                str_jobapplications_Keyword        = reader.GetString(8);
                                dataRow["jobapplications_Keyword"] = str_jobapplications_Keyword;
                            }
                            if (!(reader.IsDBNull(9)))
                            {
                                str_jobapplications_Location        = reader.GetString(9);
                                dataRow["jobapplications_Location"] = str_jobapplications_Location;
                            }
                            if (!(reader.IsDBNull(10)))
                            {
                                str_jobapplications_Comments        = reader.GetString(10);
                                dataRow["jobapplications_Comments"] = str_jobapplications_Comments;
                            }
                            // Add the row to the datatable
                            dt.Rows.Add(dataRow);
                        }



                        // Call Close when done reading.
                        reader.Close();
                        //  SampleGrid.ItemsSource = dt.DefaultView;


                        int ctr = 0;
                        foreach (DataRow item in dt.Rows)
                        {
                            DataItem dataItem = new DataItem(ctr++);
                            dataItem.str_jobapplications_JobUrl       = item["jobapplications_JobUrl"].ToString();
                            dataItem.str_jobapplications_JobBoard     = item["jobapplications_JobBoard"].ToString();
                            dataItem.str_jobapplications_JobTitle     = item["jobapplications_JobTitle"].ToString();
                            dataItem.str_jobapplications_CompanyTitle = item["jobapplications_CompanyTitle"].ToString();
                            if (item["jobapplications_DateAdded"] != null && item["jobapplications_DateAdded"].ToString() != "")
                            {
                                dataItem.dt_jobapplications_DateAdded = DateTime.Parse(item["jobapplications_DateAdded"].ToString());
                            }
                            if (item["jobapplications_DateLastModified"] != null && item["jobapplications_DateLastModified"].ToString() != "")
                            {
                                dataItem.dt_jobapplications_DateLastModified = DateTime.Parse(item["jobapplications_DateLastModified"].ToString());
                            }
                            if (item["jobapplications_DateApplied"] != null && item["jobapplications_DateApplied"].ToString() != "")
                            {
                                dataItem.dt_jobapplications_DateApplied = DateTime.Parse(item["jobapplications_DateApplied"].ToString());
                            }
                            dataItem.str_jobapplications_ApplicationStatus = item["jobapplications_ApplicationStatus"].ToString();
                            dataItem.str_jobapplications_Keyword           = item["jobapplications_Keyword"].ToString();
                            dataItem.str_jobapplications_Location          = item["jobapplications_Location"].ToString();
                            dataItem.str_jobapplications_Comments          = item["jobapplications_Comments"].ToString();
                            list.Add(dataItem);
                        }
                    }
                };

                worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
                {
                    EmployeeStatuses     = new ObservableCollection <EmployeeStatus>(STATUS.ToList());
                    EmployeePositionList = new ObservableCollection <EmployeePosition>(POSITIONS.ToList());

                    JobApplicationList = new ObservableCollection <DataItem>(list);



                    IsTestDataGenerationInProgress = false;

                    if (callback != null)
                    {
                        callback(EventArgs.Empty);
                    }
                };

                worker.RunWorkerAsync();
            }
        }