Exemple #1
0
        public static void ElaboraMovimenti(int IDConto)
        {
            MyMoneyManagerEntities context = new MyMoneyManagerEntities();
            DataSet ds;

            ds = LeggiFile(IDConto);
            bool start = false;


            #region Import Movimenti
            foreach (DataRowView item in ds.Tables[0].DefaultView)
            {
                int i = 0;
                foreach (DataRow row in item.DataView.Table.Rows)
                {
                    i++;
                    if (i <= 23)
                    {
                        ;
                    }
                    else if (start)
                    {
                        Movimenti mov = new Movimenti();
                        //OPERAZ.PAGOBANCOMAT DEL 25 / 04 / 2018 ALLE 18.02 TES.N.04823278 PRESSO 5172973 / 00001(ABI 03069)
                        //FASHION & HOME LECCO CORSO CARLO ALBERTO -CAT.MERC. (5651) N.CRO / RRN 811551753363 - ID CARTA 04823278
                        //Tessera: Carta di credito padre (la mia). IDCarta chi ha effettivamente usato.
                        if (!row.IsNull(1))
                        {
                            mov.DataContabile   = DateTime.Parse(row[1].ToString()).Date;
                            mov.DataValuta      = DateTime.Parse(row[2].ToString()).Date;
                            mov.IDContoCorrente = IDConto;
                            mov.Importo         = Decimal.Parse(row[3].ToString().Replace(".", ","));
                            mov.Divisa          = row[4].ToString();
                            mov.Descrizione     = row[5].ToString();
                            mov.Causale         = row[6].ToString();

                            #region Categorie UBI
                            Regex _regex = new Regex(@"CAT.\s*MERC.\s*\(\d+");
                            // This calls the static method specified.
                            Match match = _regex.Match(mov.Descrizione);
                            if (match.Success)
                            {
                                //Console.WriteLine("Value:" + match.Groups[0].Value.ToString().Replace("CAT.MERC. (", ""));
                                string id  = Regex.Replace(match.Groups[0].Value.ToString(), "CAT.\\s*MERC.\\s*\\(", "");
                                int    iid = int.Parse(id);
                                if (iid > 0)
                                {
                                    mov.IDCategoria = iid;
                                    if (context.CategorieUbiBanca.Where(q => q.ID == mov.IDCategoria).Count() <= 0 && context.CategorieUbiBanca.Local.Where(q => q.ID == mov.IDCategoria).Count() <= 0)
                                    {
                                        CategorieUbiBanca ubicat = new CategorieUbiBanca();
                                        ubicat.ID = mov.IDCategoria.Value;
                                        context.CategorieUbiBanca.Add(ubicat);
                                    }
                                }
                            }
                            #endregion

                            #region Tes. N.
                            Regex _regex2 = new Regex(@"TES.\s*N.\s*\s*([^\s]+)");
                            // This calls the static method specified.
                            Match match2 = _regex2.Match(mov.Descrizione);
                            if (match2.Success)
                            {
                                //Console.WriteLine("Value:" + match.Groups[0].Value.ToString().Replace("CAT.MERC. (", ""));
                                string id = Regex.Replace(match2.Groups[0].Value.ToString(), "TES.\\s*N.\\s*", "");

                                if (!String.IsNullOrEmpty(id))
                                {
                                    mov.IDCarta = id;
                                }
                            }
                            #endregion
                            if (mov.Causale.Contains("Prelievi"))
                            {
                                mov.IDCategoriaIphase = 90;
                            }
                            else if (context.Keywords.Where(q => mov.Descrizione.ToLower().Trim().Contains(q.Keyword.Trim().ToLower())).Count() == 1)
                            {
                                mov.IDCategoriaIphase = context.Keywords.Where(q => mov.Descrizione.Trim().ToLower().Contains(q.Keyword.Trim().ToLower())).First().IDVoce_Code;
                            }
                            else if (mov.Causale.Contains("Pagamenti POS"))
                            {
                                mov.IDCategoriaIphase = 92;
                            }
                            else
                            {
                                mov.IDCategoriaIphase = -1;
                            }

                            context.Movimenti.Add(mov);
                        }
                    }
                    else if (row[1].ToString().Trim().ToLower().Equals("data contabile"))
                    {
                        start = true;
                    }
                }
                break;
            }
            #endregion
            context.SaveChanges();
        }
Exemple #2
0
        public IEnumerable <Movimenti> Get()
        {
            MyMoneyManagerEntities context = new MyMoneyManagerEntities();

            return(context.Movimenti.ToList());
        }