public string PopulateXmlfile(TrunkStaticTestDataSet ProgramData, int TotalTables, string ProgramName)
        {
            DataSet DataTables = new DataSet();

            string UserId;
            if (GlobalVariables.LoggedInUser != null)
            {
                UserId = GlobalVariables.LoggedInUser.id.ToString();
            }
            else
            {
                UserId = "0";
            }

            string directory = "C:\\XmlData\\" + UserId;
            //string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\XmlData\\" + UserId;
            if (!System.IO.Directory.Exists(directory))
                System.IO.Directory.CreateDirectory(directory);

            string timeStamp = DateTime.Now.ToString("yyyyMMddHHmm");
            string FileName = directory + "\\" + ProgramName + timeStamp + ".xml";
            if (!System.IO.File.Exists(FileName))
            {
                System.IO.FileStream fs = System.IO.File.Create(FileName);
                fs.Close();
            }
            else
            {
                System.IO.File.Delete(FileName);
                System.IO.FileStream fs = System.IO.File.Create(FileName);
                fs.Close();
            }

            //Copy DataTables to Main DataSet
            for (int jj = 0; jj < TotalTables; jj++)
            {
                if (ProgramData.Tables[jj].Rows.Count == 0)
                {
                    for (int kk = 0; kk < 50; kk++)
                    {
                        ProgramData.AddNewRow(jj, 0, 0);
                    }
                }
                DataTable dtCopy = ProgramData.Tables[jj].Copy();
                DataTables.Tables.Add(dtCopy);
            }

            try
            {
                DataTables.WriteXml(FileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception caught in WriteXML: {0}", ex.ToString());
            }

            return FileName;
        }
        private void backgroundWorkerSaveData_DoWork(object sender, DoWorkEventArgs e)
        {
            DialogResult saveDataToFile = (DialogResult)e.Argument;

            Structs.StoreDataResult result = new Structs.StoreDataResult();

            if (GlobalVariables.UserMode == GlobalVariables.UserIdentityMode.ProfileMode)
                result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(GlobalVariables.LoggedInUser.id, testMode.ToString(), (float)DataSample.MaxUserTorqueArray.Average(), DataSample.TotalReps);
            else
                result.IsSuccess = true;

            if (saveDataToFile == System.Windows.Forms.DialogResult.OK)
            {
                string stringUserId;
                if (GlobalVariables.LoggedInUser != null)
                {
                    stringUserId = GlobalVariables.LoggedInUser.id.ToString();
                }
                else
                {
                    stringUserId = "0";
                }


                Classes.TrunkStaticTestDataSet torqueDataSet = new Classes.TrunkStaticTestDataSet();

                for (int ii = 0; ii < DataSample.UserTorqueArray.Count; ii++)
                    torqueDataSet.AddNewRow(0, DataSample.UserTorqueArray[ii], DataSample.angleArray[ii]/2);

                if (torqueDataSet != null)
                {
                    string programName = "TrunkTorque_" + stringUserId + "_" + DataSample.ProgramSelector.ToString() + "_" + DataSample.SelectedTorque.ToString() + "_" + Math.Round(DataSample.SelectedStartAngle/2,2).ToString() + "_";
                    string filePath = torqueDataSet.PopulateXmlfile(torqueDataSet, 1, programName);
                    //torqueDataSet.EmailFile(filePath);
                }
            }

            e.Result = result;
        }