示例#1
0
    public List<Mostra> VerificFile(string filepath)
    {
        var coduri = new StringBuilder();
        var mostre = new List<Mostra>();
        List<string> coduri_eronate = new List<string>();
        List<MostraAnalizata> mostreAnalizate = new List<MostraAnalizata>();

        int posOfSlash = filepath.LastIndexOf(@"\");
        string zi = filepath.Substring(posOfSlash + 1, 2);
        string luna = filepath.Substring(posOfSlash + 3, 2);
        string an = filepath.Substring(posOfSlash + 5, 2);
        string filename = filepath.Substring(posOfSlash + 1);

        bool b_file = false;
        bool c_file = false;
        bool c1_file = false;
        bool a_file = false;
        bool f_file = false;
        int lineCnt = 0;

        loggerRezultate.Info("verific fisier {0}", filepath);

        if (File.Exists(filepath))
        {
            if (filepath.ToUpper().EndsWith("B1COP.CSV") || filepath.ToUpper().EndsWith("B2COP.CSV"))
                b_file = true;
            if (filepath.ToUpper().EndsWith("C.CSV"))
                c_file = true;
            if (filepath.ToUpper().Contains("C1"))
                c1_file = true;
            if (filename.ToUpper().Contains("A"))
                a_file = true;
            if (filename.ToUpper().Contains("C2") || filename.ToUpper().Contains("C3"))
                f_file = true;
            FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);
            string linie = "";
            string[] a_linie;
            if (b_file)
            {
                linie = sr.ReadLine();
                lineCnt = 1;
                while (linie != null)
                {
                    linie = sr.ReadLine();
                    lineCnt++;
                    if (lineCnt > 6 && linie != null)
                    {
                        a_linie = linie.Split(';');
                        if (a_linie[0] != null && Utils.IsDouble(a_linie[0].Trim(), NumberStyles.Integer))// && a_linie[4].ToString().Trim() != "")
                        {
                            coduri.Append(a_linie[2].Trim() + ";");
                            mostreAnalizate.Add(new MostraAnalizata { IncrementZilnic = a_linie[0], CodBare = a_linie[2] });
                        }
                    }
                }
            }

            if (f_file)
            {
                linie = sr.ReadLine();
                lineCnt = 1;
                while (linie != null)
                {
                    linie = sr.ReadLine();
                    lineCnt++;
                    if (lineCnt > 6 && linie != null)
                    {
                        a_linie = linie.Split(';');
                        if (a_linie[0] != null && Utils.IsDouble(a_linie[0].Trim(), NumberStyles.Integer))
                        // && ((a_linie.Length > 17 && a_linie[17].Equals("VALUE")) || (a_linie.Length > 30 && a_linie[30].Equals("VALUE"))))
                        {
                            coduri.Append(a_linie[1].Trim() + ";");
                            mostreAnalizate.Add(new MostraAnalizata { IncrementZilnic = a_linie[0], CodBare = a_linie[1] });
                        }
                    }
                }
            }

            if (c_file)
            {
                linie = sr.ReadLine();
                lineCnt = 1;
                while (linie != null)
                {
                    linie = sr.ReadLine();
                    lineCnt++;
                    if (lineCnt > 4 && linie != null)
                    {
                        a_linie = linie.Split(';');
                        if (a_linie[0] != null && Utils.IsDouble(a_linie[0].Trim(), NumberStyles.Integer))
                        // && a_linie[4].ToString().Trim() != "")
                        {
                            coduri.Append(a_linie[2].Trim() + ";");
                            mostreAnalizate.Add(new MostraAnalizata { IncrementZilnic = a_linie[0], CodBare = a_linie[2] });
                        }
                    }
                }
            }

            if (c1_file)
            {
                linie = sr.ReadLine();
                lineCnt = 1;
                while (linie != null)
                {
                    linie = sr.ReadLine();
                    lineCnt++;
                    if (lineCnt > 7 && linie != null)
                    {
                        a_linie = linie.Split(';');
                        if (a_linie[0] != null && Utils.IsDouble(a_linie[0].Trim(), NumberStyles.Integer))
                        // && a_linie[5].ToString().Trim() != "")
                        {
                            coduri.Append(a_linie[3].Trim() + ";");
                            mostreAnalizate.Add(new MostraAnalizata { IncrementZilnic = a_linie[0], CodBare = a_linie[3] });
                        }
                    }
                }
            }

            bool urmeaza_cod_bare = false;
            bool urmeaza_pct_inghet = false;
            string pct_inghet = "";
            string cod_bare = "";
            string a_data_test = "";
            if (a_file)
            {
                int i = 0;
                linie = sr.ReadLine();

                while (linie != null)
                {
                    linie = sr.ReadLine();
                    if (lineCnt <= 5 && ((linie.IndexOf(" PM") >= 0) || (linie.IndexOf(" AM") >= 0)))
                    {
                        a_data_test = linie.TrimStart(' ').Substring(3, 2) + "/" + linie.TrimStart(' ').Substring(0, 2) + "/" + linie.TrimStart(' ').Substring(6, 4);
                    }
                    lineCnt++;

                    if (linie != null)
                    {
                        try
                        {
                            if (urmeaza_pct_inghet)
                            {
                                coduri.Append(cod_bare + ";");
                                pct_inghet = linie.Substring(linie.IndexOf("mC") - 4, 3);
                                urmeaza_pct_inghet = false;
                                mostreAnalizate.Add(new MostraAnalizata { IncrementZilnic = i.ToString(), CodBare = cod_bare });
                                i++;
                            }
                            if (urmeaza_cod_bare)
                            {
                                cod_bare = linie.Substring(linie.Length - 10, 10).TrimStart(' ');
                                urmeaza_pct_inghet = true;
                            }
                            int idx = linie.IndexOf("I.D.#");
                            urmeaza_cod_bare = (idx >= 0);
                        }
                        catch (Exception ex)
                        {
                            urmeaza_cod_bare = false;
                            urmeaza_pct_inghet = false;
                            loggerRezultate.Error(string.Format("VerificFile|ERROR:{0}", ex.Message));
                        }
                    }
                }
            }

            sr.Close();
            fs.Close();

            var mostreManager = new MostreManager(CopConnectionString);
            mostre = mostreManager.GetDateCoduriBare(coduri.ToString().TrimEnd(';'));

            foreach (var mostraAnalizata in mostreAnalizate)
            {
                if (mostraAnalizata.CodBare.Trim() == "")
                {
                    loggerRezultate.Info("EROARE: Cod de bare gol la pozitia ID= {0}", mostraAnalizata.IncrementZilnic.Trim());
                }
                else
                {
                    if (a_file)
                    {
                        if (!mostre.Exists(m => m.CodBare == mostraAnalizata.CodBare.Trim()) && (mostraAnalizata.CodBare.Trim() != "1111111111"))
                        {
                            loggerRezultate.Info("Codul de bare: {0} nu a fost importat din fisierul de receptie din data de: {1}/{2}/20{3}", mostraAnalizata.CodBare, zi, luna, an);
                            coduri_eronate.Add(mostraAnalizata.CodBare.Trim());
                        }
                    }
                    else
                    {
                        if (ErrorInt(mostraAnalizata.IncrementZilnic.Trim()))
                        {
                            loggerRezultate.Info("EROARE: Valoare incorecta la Incrementul Zilnic: {0}", mostraAnalizata.IncrementZilnic.Trim());
                        }
                        //else
                        //{
                        //    if (ExistaIdZilnic(a_data_test, Convert.ToInt32(mostraAnalizata.IncrementZilnic.Trim())) == 0 && (mostraAnalizata.CodBare.Trim() != "1111111111"))
                        //    {
                        //        loggerRezultate.Info("Nu exista in baza de date incrementul zilnic: {0} in ziua : {1}", mostraAnalizata.IncrementZilnic, a_data_test);
                        //        coduri_eronate.Add(mostraAnalizata.CodBare.Trim());
                        //    }
                        //}
                    }
                }
            }
            foreach (var coduriDuplicate in mostreAnalizate.GroupBy(x => x.CodBare).Where(g => g.Count() > 1).Select(y => y.Key).ToList())
            {
                loggerRezultate.Info("EROARE: Codul de bare: {0} se gaseste de mai multe ori: ", coduriDuplicate);
                coduri_eronate.Add(coduriDuplicate.Trim());
            }
            foreach (var iduriDuplicate in mostreAnalizate.GroupBy(x => x.IncrementZilnic).Where(g => g.Count() > 1).Select(y => y.Key).ToList())
            {
                loggerRezultate.Info("EROARE: Incrementul zilnic: {0} se gaseste de mai multe ori: ", iduriDuplicate);
                coduri_eronate.Add(mostreAnalizate.First(m => m.IncrementZilnic == iduriDuplicate).CodBare);
            }
        }

        return coduri_eronate.Count > 0 ? null : mostre;
    }
示例#2
0
	public List<Mostra> VerificFile(string filepath)
	{
		var coduri = new StringBuilder();
		var mostre = new List<Mostra>();
		FileStream fs;
		string linie = "";
		string[] a_linie;
		string[] coduri_eronate = new string[1000];
		string[,] fisier = new string[1000, 3];

		int posOfSlash = filepath.LastIndexOf(@"\");
		string zi = filepath.Substring(posOfSlash + 1, 2);
		string luna = filepath.Substring(posOfSlash + 3, 2);
		string an = filepath.Substring(posOfSlash + 5, 2);
		string filename = filepath.Substring(posOfSlash + 1);

		int i, j;
		int z;
		int b_file = 0;
		int c_file = 0;
		int c1_file = 0;
		int a_file = 0;
		int f_file = 0;
		int lineCnt = 0;
		int ff;
		bool primul = false;

		loggerRezultate.Info("verific fisier {0}", filepath);
		bool isNum;
		string job;
		double jobid;

		if (File.Exists(filepath))
		{
			if (filepath.ToUpper().EndsWith("B1.CSV") || filepath.ToUpper().EndsWith("B2.CSV"))
				b_file = 1;
			if (filepath.ToUpper().EndsWith("C.CSV"))
				c_file = 1;
			if (filepath.ToUpper().Contains("C1"))
				c1_file = 1;
			if (filename.ToUpper().Contains("A"))
				a_file = 1;
			if (filename.ToUpper().Contains("C2") || filename.ToUpper().Contains("C3"))
				f_file = 1;
			fs = new FileStream(filepath, FileMode.OpenOrCreate);
			StreamReader sr = new StreamReader(fs);
			if (b_file == 1)
			{
				linie = sr.ReadLine();
				lineCnt = 1;
				i = 0;
				while (linie != null)
				{
					linie = sr.ReadLine();
					lineCnt++;
					if (lineCnt > 6)
					{
						if (linie != null)
						{
							a_linie = linie.Split(';');
							if (a_linie[0] != null)
							{
								job = a_linie[0].ToString().Trim();
								isNum = double.TryParse(job, NumberStyles.Integer, CultureInfo.CurrentCulture, out jobid);
								if (isNum)//&& a_linie[4].ToString().Trim() != "")
								{
									coduri.Append(a_linie[2].Trim() + ";");
									fisier[i, 0] = a_linie[0];
									fisier[i, 1] = a_linie[2];
									fisier[i, 2] = "0";
									i++;
								}
							}
						}
					}
				}
			}
			// f_file
			if (f_file == 1)
			{
				linie = sr.ReadLine();
				lineCnt = 1;
				i = 0;
				while (linie != null)
				{
					linie = sr.ReadLine();
					lineCnt++;
					if (lineCnt > 6)
					{
						if (linie != null)
						{
							a_linie = linie.Split(';');
							if (a_linie[0] != null)
							{
								job = a_linie[0].ToString().Trim();
								isNum = double.TryParse(job, NumberStyles.Integer, CultureInfo.CurrentCulture, out jobid);
								if (isNum)// && ((a_linie.Length > 17 && a_linie[17].Equals("VALUE")) || (a_linie.Length > 30 && a_linie[30].Equals("VALUE"))))
								{
									coduri.Append(a_linie[1].Trim() + ";");
									fisier[i, 0] = a_linie[0];
									fisier[i, 1] = a_linie[1];
									fisier[i, 2] = "0";
									i++;
								}
							}
						}
					}
				}
			}


			//end f_file
			if (c_file == 1)
			{
				linie = sr.ReadLine();
				lineCnt = 1;
				i = 0;
				while (linie != null)
				{
					linie = sr.ReadLine();
					lineCnt++;
					if (lineCnt > 4)
					{
						if (linie != null)
						{
							a_linie = linie.Split(';');
							if (a_linie[0] != null)
							{
								job = a_linie[0].ToString().Trim();
								isNum = double.TryParse(job, NumberStyles.Integer, CultureInfo.CurrentCulture, out jobid);
								if (isNum)// && a_linie[4].ToString().Trim() != "")
								{
									coduri.Append(a_linie[2].Trim() + ";");
									fisier[i, 0] = a_linie[0];
									fisier[i, 1] = a_linie[2];
									fisier[i, 2] = "0";
									i++;
								}
							}
						}
					}
				}
			}

			if (c1_file == 1)
			{
				linie = sr.ReadLine();
				lineCnt = 1;
				i = 0;
				while (linie != null)
				{
					linie = sr.ReadLine();
					lineCnt++;
					if (lineCnt > 7)
					{
						if (linie != null)
						{
							a_linie = linie.Split(';');
							if (a_linie[0] != null)
							{
								job = a_linie[0].ToString().Trim();
								isNum = double.TryParse(job, NumberStyles.Integer, CultureInfo.CurrentCulture, out jobid);
								if (isNum)// && a_linie[5].ToString().Trim() != "")
								{
									coduri.Append(a_linie[3].Trim() + ";");
									fisier[i, 0] = a_linie[0];
									fisier[i, 1] = a_linie[3];
									fisier[i, 2] = "0";
									i++;
								}
							}
						}
					}
				}
			}


			bool urmeaza_cod_bare = false;
			bool urmeaza_pct_inghet = false;
			string pct_inghet = "";
			int idx = 0;
			string cod_bare = "";
			string a_data_test = "";
			if (a_file == 1)
			{
				i = 0;
				linie = sr.ReadLine();

				while (linie != null)
				{
					linie = sr.ReadLine();
					if (lineCnt <= 5 && ((linie.IndexOf(" PM") >= 0) || (linie.IndexOf(" AM") >= 0)))
						a_data_test = linie.TrimStart(' ').Substring(3, 2) + "/" + linie.TrimStart(' ').Substring(0, 2) + "/" + linie.TrimStart(' ').Substring(6, 4);
					lineCnt++;

					if (linie != null)
					{
						try
						{
							if (urmeaza_pct_inghet)
							{
								coduri.Append(cod_bare + ";");
								pct_inghet = linie.Substring(linie.IndexOf("mC") - 4, 3);
								urmeaza_pct_inghet = false;
								fisier[i, 0] = Convert.ToString(i);
								fisier[i, 1] = cod_bare;
								fisier[i, 2] = "0";
								i++;
							}
							if (urmeaza_cod_bare)
							{
								cod_bare = linie.Substring(linie.Length - 10, 10).TrimStart(' ');
								urmeaza_pct_inghet = true;
							}
							idx = linie.IndexOf("I.D.#");
							if (idx >= 0)
								urmeaza_cod_bare = true;
							else
								urmeaza_cod_bare = false;
						}
						catch (Exception ex)
						{
							loggerRezultate.Info(string.Format("VerificFile|EROARE: Cod de bare gol la pozitia ID={0} ERROR:{1}", fisier[i, 0].Trim(), ex.Message));
							urmeaza_cod_bare = false;
							urmeaza_pct_inghet = false;
						}
					}
				}
			}
			sr.Close();
			fs.Close();

			var mostreManager = new MostreManager(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString);
			mostre = mostreManager.GetDateCoduriBare(coduri.ToString().TrimEnd(';'));

			i = 0;
			z = 0;
			while (fisier[i, 0] != null)
			{

				if (fisier[i, 1].Trim() == "")
				{
					loggerRezultate.Info("EROARE: Cod de bare gol la pozitia ID=" + fisier[i, 0].Trim());
				}
				else
				{
					if (a_file == 0)
					{
						foreach (var cod in coduri.ToString().TrimEnd(';').Split(';'))
						{
							var mostra = mostre.FirstOrDefault(x => x.CodBare == cod);
							if (mostra == null)
							{
								loggerRezultate.Info("Codul de bare:" + fisier[i, 1] + " nu a fost importat din fisierul de receptie din data de:" + zi + "/" + luna + "/20" + an);
							}
						}
					}
					else
					{
						if (ErrorInt(fisier[i, 1].Trim()))
						{
							loggerRezultate.Info("EROARE: Valoare incorecta la Incrementul Zilnic: " + fisier[i, 1].Trim());
						}
						else
						{
							if (ExistaIdZilnic(a_data_test, Convert.ToInt32(fisier[i, 1].Trim())) == 0 && (fisier[i, 1].Trim() != "1111111111"))
							{
								loggerRezultate.Info("Nu exista incrementul zilnic:" + fisier[i, 1] + "in ziua : " + a_data_test);
								coduri_eronate[z++] = fisier[i, 1].Trim();
							}
						}

					}


					j = i + 1;
					primul = true;
					while (fisier[j, 0] != null)
					{

						ff = fisier[j, 2].Trim().CompareTo("0");
						if ((fisier[i, 1] == fisier[j, 1]) && (ff == 0))
						{
							if (primul)
							{
								loggerRezultate.Info("EROARE: Codul de bare:" + fisier[i, 1] + " se gaseste de mai multe ori: ");
								loggerRezultate.Info("                 Pozitia: " + fisier[i, 0].Trim());
								coduri_eronate[z++] = fisier[i, 1].Trim();
								primul = false;
							}
							loggerRezultate.Info("EROARE: Codul de bare:" + fisier[i, 1] + " se gaseste de mai multe ori: ");
							loggerRezultate.Info("                 Pozitia: " + fisier[j, 0].Trim());
							fisier[j, 2] = "1";
						}
						j++;
					}
				}
				i++;
			}
		}
		return mostre;
	}