Esempio n. 1
0
        void bg_DoWork(object sender, DoWorkEventArgs e)
        {
            string             fileName = (string)e.Argument;
            CSVDataLoader      csvDL    = new CSVDataLoader();
            List <RuntimeData> data     = csvDL.getRuntimeDataFromCSV(fileName, '"', '\'');
            double             progress = 5;

            bg.ReportProgress((int)progress);
            double i     = 0;
            double count = data.Count;
            BillingDataDataContext db = new BillingDataDataContext();
            int    sheetNo;
            string errorMessage = "";

            try
            {
                sheetNo = db.RuntimeDatas.Max(x => x.SheetNo) + 1;
            }
            catch (Exception)
            {
                sheetNo = 0;
            }
            foreach (RuntimeData rData in data)
            {
                try
                {
                    rData.SheetNo = sheetNo;
                    rData.UserId  = "System";
                    db.RuntimeDatas.InsertOnSubmit(rData);
                    db.SubmitChanges();
                }
                catch
                {
                    errorMessage += rData.ConsignmentNo + " ";
                }
                i++;
                int prog = (int)(progress + (i / count * 85));
                bg.ReportProgress(prog);
            }
            db.ImportFileData(sheetNo, "System", SecurityModule.currentUserName);
            e.Result = errorMessage;
            bg.ReportProgress(100);
        }