private List <Mamg0> ReadDataFromTextFile()
        {
            List <Mamg0> mamgoList = new List <Mamg0>();

            //Mamg0 mamgo = new Mamg0();
            //string lineCheck = "";
            try
            {
                string[] lines = File.ReadAllLines(filePathTxt);
                foreach (string line in lines)
                {
                    if (line.Trim().StartsWith("LISTINO"))
                    {
                        continue;
                    }

                    //lineCheck = line;
                    Mamg0 mamgo = new Mamg0();
                    mamgo.CodArt        = line.Substring(0, 19).Trim() == "" ? "" : line.Substring(0, 19).Trim();
                    mamgo.Desc          = line.Substring(32, 43).Trim() == "" ? "" : line.Substring(32, 43).Trim();
                    mamgo.Pezzo         = line.Substring(75, 5).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(75, 5).Trim());
                    mamgo.PrezzoListino = line.Substring(97, 11).Replace("-", "").Trim() == "" ? 0 : Convert.ToDecimal($"{Convert.ToInt32(line.Substring(97, 9).Replace("-", "").Trim())},{Convert.ToInt32(line.Substring(106, 2).Replace("-", "").Trim())}");
                    mamgo.PrezzoNetto   = line.Substring(108, 11).Replace("-", "").Trim() == "" ? 0 : Convert.ToDecimal($"{Convert.ToInt32(line.Substring(108, 9).Replace("-", "").Trim())},{Convert.ToInt32(line.Substring(117, 2).Replace("-", "").Trim())}");
                    //mamgo.AA_CODF = line.Substring(0, 16).Trim() == "" ? "" : line.Substring(0, 16).Trim(); // OLD
                    //mamgo.AA_IVA = line.Substring(3, 16).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(3, 16).Trim());
                    //mamgo.AA_IVA = line.Substring(19, 13).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(19, 13).Trim());
                    //mamgo.AA_DES = line.Substring(32, 43).Trim() == "" ? "" : line.Substring(32, 43).Trim(); // OLD
                    //mamgo.AA_PZ = line.Substring(75, 5).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(75, 5).Trim()); //OLD
                    //mamgo.AA_IVA = line.Substring(80, 5).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(80, 5).Trim());
                    //mamgo.AA_IVA = line.Substring(85, 5).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(85, 5).Trim());
                    //mamgo.AA_IVA = line.Substring(90, 6).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(90, 6).Trim());
                    //mamgo.AA_IVA = line.Substring(96, 1).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(96, 1).Trim());
                    //mamgo.AA_PRZ1 = line.Substring(97, 11).Trim() == "" ? 0 : Convert.ToInt32($"{Convert.ToInt32(line.Substring(97, 9).Trim())},{Convert.ToInt32(line.Substring(106, 2).Trim())}"); // OLD
                    //mamgo.AA_PRZ = line.Substring(108, 11).Trim() == "" ? 0 : Convert.ToInt32($"{Convert.ToInt32(line.Substring(108, 9).Trim())},{Convert.ToInt32(line.Substring(117, 2).Trim())}"); // OLD
                    //mamgo.AA_IVA = line.Substring(119, 6).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(119, 6).Trim());
                    //mamgo.AA_IVA = line.Substring(125, 3).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(125, 3).Trim());
                    //mamgo.AA_IVA = line.Substring(128, 3).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(128, 3).Trim());
                    //mamgo.AA_IVA = line.Substring(131, 1).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(131, 1).Trim());
                    //mamgo.AA_IVA = line.Substring(132, 1).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(132, 1).Trim());
                    //mamgo.AA_IVA = line.Substring(133, 8).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(133, 8).Trim());
                    //mamgo.AA_IVA = line.Substring(141, 18).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(141, 18).Trim());
                    //mamgo.AA_IVA = line.Substring(159, 18).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(159, 18).Trim());
                    //mamgo.AA_IVA = line.Substring(177, 21).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(177, 21).Trim());
                    //mamgo.AA_IVA = line.Substring(198, 7).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(198, 7).Trim());
                    //mamgo.AA_IVA = line.Substring(205, 4).Trim() == "" ? 0 : Convert.ToInt32(line.Substring(205, 4).Trim());
                    //mamgo.AA_IVA = line.Substring(209, 11).Trim() == "" ? 0 : Convert.ToInt32($"{Convert.ToInt32(line.Substring(209, 8).Trim())},{Convert.ToInt32(line.Substring(217, 3).Trim())}");
                    mamgoList.Add(mamgo);
                }
            }
            catch (Exception ex)
            {
                //var x = mamgo;
                //var y = lineCheck;
                throw new Exception("Errore durante il popolamento dei listini Mef da ddt.txt", ex);
            }
            return(mamgoList);
        }
Example #2
0
        public static Mamg0 GetSingle(string codiceListinoUnivoco)
        {
            Mamg0         ret = new Mamg0();
            StringBuilder sql = new StringBuilder();

            sql.AppendLine($"SELECT (AA_SIGF + AA_COD) AS CodArt, AA_DES AS 'Desc', AA_UM AS UnitMis, AA_PZ AS Pezzo, AA_PRZ AS PrezzoListino,");
            sql.AppendLine($"AA_SCONTO1 AS Sconto1, AA_SCONTO2 AS Sconto2, AA_SCONTO3 AS Sconto3, AA_PRZ1 AS PrezzoNetto, CodiceListinoUnivoco");
            sql.AppendLine($"FROM MAMG0");
            sql.AppendLine($"WHERE (AA_COD + AA_SIGF) = @codiceListinoUnivoco");
            sql.AppendLine($"ORDER BY CodArt ASC");
            try
            {
                using (SqlConnection cn = GetConnection())
                {
                    ret = cn.Query <Mamg0>(sql.ToString(), new { codiceListinoUnivoco }).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Errore durante il recupero del listino", ex);
            }
            return(ret);
        }