Ejemplo n.º 1
0
        public static void parralelFunc()
        {
            using (var dc = new DAL.TargetFinancialDataContext())
            {
                // Get all the ids of interest.
                // I assume you mark successfully updated rows in some way
                // in the update transaction.
                List <int> ids = new List <int>();
                ids.Add(1);
                ids.Add(2);
                ids.Add(3);
                ids.Add(4);
                ids.Add(5);
                ids.Add(6);
                ids.Add(7);
                ids.Add(8);

                var problematicIds = new List <ErrorType>();

                // Either allow the TaskParallel library to select what it considers
                // as the optimum degree of parallelism by omitting the
                // ParallelOptions parameter, or specify what you want.
                //Parallel.ForEach(ids, new ParallelOptions {MaxDegreeOfParallelism = 8},
                //                    id => CalculateDetails(id));
                Parallel.ForEach(ids, i =>
                {
                    //this.Update(i);
                    // commented out because you'll probably want to Invoke it
                    // depending on what it does exactly.
                    CalculateDetails(i);
                });
            }
        }
Ejemplo n.º 2
0
        private static void CalculateDetails(int id)
        {
            try
            {
                // Creating a new DeviceContext is not expensive.
                // No need to create outside of this method.
                using (var dc = new DAL.TargetFinancialDataContext())
                {
                    Init(dc);
                    // work done here

                    dc.SubmitChanges();
                }
            }
            catch (Exception e) {
                var a = e;
            }
        }
Ejemplo n.º 3
0
        public static void Init()
        {
            var CompanyList    = new List <DAL.Company>();
            var CompanyDetails = new DAL.Company();

            var db = new DAL.TargetFinancialDataContext();

            var CheckData = new List <CVTemp>();
            //vid_na_rabota_550.xlsx
            //listing
            var res = Workbook.Worksheets(@"C:\Nix\Project_Dev\Bonitet.ConsoleCSV\bin\Debug\vid_na_rabota_550.xlsx");

            foreach (var worksheet in res)
            {
                var AOP       = false;
                var Tekovna   = 0;
                var Prethodna = 0;
                var Oznaka    = 0;

                foreach (var row in worksheet.Rows)
                {
                    var cellCounter = 0;
                    foreach (var cell in row.Cells)
                    {
                        if (cell != null)
                        {
                            if (cell.Text == "*******")
                            //if (cell.Text == "ПРЕГЛЕД НА ПОДАТОЦИ ОД ГОДИШНА СМЕТКА ЗА 2016 ГОДИНА - ВИД НА РАБОТА 550")
                            {
                                CompanyList.Add(CompanyDetails);

                                if (CompanyDetails.EMBS != null)
                                {
                                    Console.WriteLine(CompanyList.Count());

                                    if (CheckData != null)
                                    {
                                        break;
                                    }
                                    DALHelper.InsertCompanyValues1Temp(CompanyDetails);
                                }

                                CompanyDetails = new DAL.Company();

                                CompanyDetails.CYTemps.Add(new DAL.CYTemp
                                {
                                    Company = CompanyDetails,
                                    Year    = 2014
                                });
                                CompanyDetails.CYTemps.Add(new DAL.CYTemp
                                {
                                    Company = CompanyDetails,
                                    Year    = 2013
                                });


                                AOP       = false;
                                Tekovna   = 0;
                                Prethodna = 0;
                                Oznaka    = 0;
                            }

                            if (cell.Text == "Назив на правното лице:")
                            {
                                CompanyDetails.Name = row.Cells[cellCounter + 1].Text;
                            }

                            if (cell.Text == "Место:")
                            {
                                CompanyDetails.Mesto = row.Cells[cellCounter + 1].Text;
                            }

                            if (cell.Text == "Матичен Број:")
                            {
                                CompanyDetails.EMBS = row.Cells[cellCounter + 1].Text.TrimStart('0');

                                CheckData = DALHelper.GetCompanyValuesByEMBSTemp(CompanyDetails.EMBS);
                                if (CheckData != null)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                if (CheckData != null)
                                {
                                    break;
                                }
                            }

                            if (cell.Text == "Ознака за АОП")
                            {
                                Oznaka = cell.ColumnIndex;
                            }

                            if (cell.Text == "Тековна година")
                            {
                                Tekovna = cell.ColumnIndex;
                            }

                            if (cell.Text == "Претходна година")
                            {
                                Prethodna = cell.ColumnIndex;
                            }

                            if (AOP)
                            {
                                if (CompanyDetails.CYTemps.First().ID == 0)
                                {
                                    CompanyDetails        = DALHelper.InsertCompanyWithYearsTemp(CompanyDetails);
                                    CompanyDetails.CVTemp = new List <CVTemp>();
                                }

                                if (row.Cells[Oznaka] != null)
                                {
                                    var curOznaka = row.Cells[Oznaka].Text;

                                    var newValID = db.Values.Where(c => c.Type == 1 && c.Name == curOznaka).Select(c => c.ID).FirstOrDefault();

                                    var year4 = CompanyDetails.CYTemps.Where(c => c.Year == 2014).Select(c => c.ID).FirstOrDefault();
                                    var year3 = CompanyDetails.CYTemps.Where(c => c.Year == 2013).Select(c => c.ID).FirstOrDefault();

                                    if (CompanyDetails.CVTemp.Where(c => c.ValueID == newValID && c.YearID == year4).FirstOrDefault() == null)
                                    {
                                        if (row.Cells[Tekovna] != null)
                                        {
                                            var curValue = row.Cells[Tekovna].Text;

                                            if (string.IsNullOrEmpty(curValue) == false)
                                            {
                                                curValue = curValue.Replace(".", "");

                                                var newCompanyValue = new DAL.CVTemp();

                                                newCompanyValue.CompanyID = CompanyDetails.ID;
                                                newCompanyValue.YearID    = year4;


                                                double tmpVal = 0;
                                                if (double.TryParse(curValue, out tmpVal))
                                                {
                                                    newCompanyValue.Value = tmpVal;

                                                    newCompanyValue.ValueID = newValID;


                                                    CompanyDetails.CVTemp.Add(newCompanyValue);
                                                }
                                            }
                                        }
                                    }

                                    if (CompanyDetails.CVTemp.Where(c => c.ValueID == newValID && c.YearID == year3).FirstOrDefault() == null)
                                    {
                                        if (row.Cells[Prethodna] != null)
                                        {
                                            var curValue = row.Cells[Prethodna].Text;

                                            if (string.IsNullOrEmpty(curValue) == false)
                                            {
                                                curValue = curValue.Replace(".", "");

                                                var newCompanyValue = new DAL.CVTemp();

                                                newCompanyValue.CompanyID = CompanyDetails.ID;
                                                newCompanyValue.YearID    = year3;


                                                double tmpVal = 0;
                                                if (double.TryParse(curValue, out tmpVal))
                                                {
                                                    newCompanyValue.Value = tmpVal;

                                                    newCompanyValue.ValueID = newValID;


                                                    CompanyDetails.CVTemp.Add(newCompanyValue);
                                                }
                                            }
                                        }
                                    }
                                }
                            }



                            if (Tekovna > 0 && Prethodna > 0 && Oznaka > 0)
                            {
                                AOP = true;
                            }
                        }
                        cellCounter++;
                    }
                }
            }

            db.Dispose();
            db = null;
        }