//public static data_layer.QResult checkHash(string fileName) //{ // data_layer.QResult res = new data_layer.QResult(); // string controlFile = fileName.Replace(".xml", "_KONTROLA.xml"); // XmlDocument doc = new XmlDocument(); // try // { // doc.Load(controlFile); // res = HashFromFile(fileName); // if (res.ID == -1) // { // throw new Exception(res.Message); // } // if (doc.DocumentElement.SelectSingleNode("KONTROLNI_PODACI/MD5HASH").InnerText != res.Message) // { // res.ID = -1; // res.Message = "HASH fajla sa podacima nije ispravan!"; // } // else // { // res.ID = 1; // res.Message = ""; // } // } // catch (Exception ex) // { // res.ID = -1; // res.Message = ex.Message; // } // return res; //} public static QResult HashFromFile(string fileName) { QResult res = new QResult(); if (!File.Exists(Path.GetFullPath(fileName))) { res.Message = String.Format("Fajl sa imenom '{0}' ne postoji!", fileName); res.ID = -1; } string txt = File.ReadAllText(Path.GetFullPath(fileName)); System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] bs = System.Text.Encoding.UTF8.GetBytes(txt); bs = x.ComputeHash(bs); System.Text.StringBuilder s = new System.Text.StringBuilder(); foreach (byte b in bs) { s.Append(b.ToString("x2").ToLower()); } string password = s.ToString(); res.Message = password; res.ID = 1; return(res); }
public void genXML() { string path = "C:\\PD3100RazmjenaPU\\ArchiveFolder\\Export\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } DateTime LastMonthLastDate = DateTime.Today.AddDays(0 - DateTime.Today.Day); DateTime LastMonthFirstDate = LastMonthLastDate.AddDays(1 - LastMonthLastDate.Day); string datumS = LastMonthFirstDate.ToString("yyyy-MM-dd"); int slanje = 1; string FileName = DateTime.Today.ToString("yyyyMMdd") + "_0" + slanje + "_PIORS_PURS_PD3100.xml"; string NazivExport = FileName; string nf = "C:\\razmjena\\export\\" + FileName; if (File.Exists(nf)) { slanje++; FileName = DateTime.Today.ToString("yyyyMMdd") + "_0" + slanje + "_PIORS_PURS_PD3100.xml"; nf = "C:\\razmjena\\export\\" + FileName; } int count = 0; try { /*u sledecoj verziji treba ispitati da li podaci sadrze < ili > < i > */ //string nfEXP = "C:\\ArchiveFolder\\Export\\"; puniDS(dsPuni.PD3100Korisnik); count = dsPuni.PD3100Korisnik.Rows.Count; if (dsPuni.PD3100Korisnik.Rows.Count != 0) { FileStream fs = new FileStream(nf, FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); sw.WriteLine("<xml>"); sw.WriteLine("<JS_PODACI xmlns=\"\">"); sw.WriteLine("<VRSTA_PODATAKA_SIFRA>1</VRSTA_PODATAKA_SIFRA>"); sw.WriteLine("<VRSTA_PODATAKA>ПОДАЦИ О ОСИГУРАЊУ ЗА ПЕНЗИОНЕРА</VRSTA_PODATAKA>"); sw.WriteLine("<BROJ_SLOGOVA>" + count + "</BROJ_SLOGOVA>"); for (int i = 0; i < dsPuni.PD3100Korisnik.Count; i++) { sw.WriteLine("<PRIJAVA xmlns=\"\">"); sw.WriteLine("<BARKOD>" + dsPuni.PD3100Korisnik.Rows[i]["LBO"] + "</BARKOD>"); sw.WriteLine("<VRSTA_PRIJAVE_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["VRSTA_PRIJAVE_SIFRA"] + "</VRSTA_PRIJAVE_SIFRA>"); sw.WriteLine("<VRSTA_PRIJAVE>" + dsPuni.PD3100Korisnik.Rows[i]["VRSTA_PRIJAVE"] + "</VRSTA_PRIJAVE>"); sw.WriteLine("<TIP_PRIJAVE_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["TIP_PRIJAVE_SIFRA"] + "</TIP_PRIJAVE_SIFRA>"); sw.WriteLine("<TIP_PRIJAVE>" + dsPuni.PD3100Korisnik.Rows[i]["TIP_PRIJAVE"] + "</TIP_PRIJAVE>"); sw.WriteLine("<DATUM_PODNOSENJA>" + dsPuni.PD3100Korisnik.Rows[i]["DATUM_PODNOSENJA"] + "</DATUM_PODNOSENJA>"); sw.WriteLine("<DATUM_PRIJEMA>" + dsPuni.PD3100Korisnik.Rows[i]["DATUM_PRIJEMA"] + "</DATUM_PRIJEMA>"); sw.WriteLine("<UPLATIOC>"); sw.WriteLine("<JIB>" + dsPuni.PD3100Korisnik.Rows[i]["JIB"] + "</JIB>"); sw.WriteLine("<NAZIV>" + dsPuni.PD3100Korisnik.Rows[i]["NAZIV"] + "</NAZIV>"); sw.WriteLine("<ADRESA>" + dsPuni.PD3100Korisnik.Rows[i]["ADRESA"] + "</ADRESA>"); sw.WriteLine("<OPSTINA_SIFRA_ZS>" + dsPuni.PD3100Korisnik.Rows[i]["OPSTINA_SIFRA_ZS"] + "</OPSTINA_SIFRA_ZS>"); sw.WriteLine("<OPSTINA_SIFRA_PU>" + dsPuni.PD3100Korisnik.Rows[i]["OPSTINA_SIFRA_PU"] + "</OPSTINA_SIFRA_PU>"); sw.WriteLine("<OPSTINA>" + dsPuni.PD3100Korisnik.Rows[i]["OPSTINA"] + "</OPSTINA>"); sw.WriteLine("<TELEFON>" + dsPuni.PD3100Korisnik.Rows[i]["TELEFON"] + "</TELEFON>"); sw.WriteLine("<EMAIL>" + dsPuni.PD3100Korisnik.Rows[i]["EMAIL"] + "</EMAIL>"); sw.WriteLine("<OBVEZNIK>"); sw.WriteLine("<JMB>" + dsPuni.PD3100Korisnik.Rows[i]["JMB"] + "</JMB>"); sw.WriteLine("<LIB>" + dsPuni.PD3100Korisnik.Rows[i]["LIB"] + "</LIB>"); sw.WriteLine("<PREZIME>" + dsPuni.PD3100Korisnik.Rows[i]["PREZIME"] + "</PREZIME>"); sw.WriteLine("<IME>" + dsPuni.PD3100Korisnik.Rows[i]["IME"] + "</IME>"); sw.WriteLine("<DJEV_PREZIME>" + dsPuni.PD3100Korisnik.Rows[i]["DJEV_PREZIME"] + "</DJEV_PREZIME>"); sw.WriteLine("<DATUM_RODJ>" + dsPuni.PD3100Korisnik.Rows[i]["DATUM_RODJ"] + "</DATUM_RODJ>"); sw.WriteLine("<POL_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["POL_SIFRA"] + "</POL_SIFRA>"); sw.WriteLine("<POL>" + dsPuni.PD3100Korisnik.Rows[i]["POL"] + "</POL>"); sw.WriteLine("<ADRESA>" + dsPuni.PD3100Korisnik.Rows[i]["ADRESA2"] + "</ADRESA>"); sw.WriteLine("<OPSTINA>" + dsPuni.PD3100Korisnik.Rows[i]["OPSTINA3"] + "</OPSTINA>"); sw.WriteLine("<OPSTINA_SIFRA_ZS>" + dsPuni.PD3100Korisnik.Rows[i]["OPSTINA_SIFRA_ZS4"] + "</OPSTINA_SIFRA_ZS>"); sw.WriteLine("<OPSTINA_SIFRA_PU>" + dsPuni.PD3100Korisnik.Rows[i]["OPSTINA_SIFRA_PU5"] + "</OPSTINA_SIFRA_PU>"); sw.WriteLine("<KONTAKT_ADRESA_ULICA>" + dsPuni.PD3100Korisnik.Rows[i]["KONTAKT_ADRESA_ULICA"] + "</KONTAKT_ADRESA_ULICA>"); sw.WriteLine("<KONTAKT_ADRESA_PBROJ>" + dsPuni.PD3100Korisnik.Rows[i]["KONTAKT_ADRESA_PBROJ"] + "</KONTAKT_ADRESA_PBROJ>"); sw.WriteLine("<KONTAKT_ADRESA_MJESTO>" + dsPuni.PD3100Korisnik.Rows[i]["KONTAKT_ADRESA_MJESTO"] + "</KONTAKT_ADRESA_MJESTO>"); sw.WriteLine("<EMAIL>" + null + "</EMAIL>"); sw.WriteLine("<STRUCNA_SPREMA_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["STRUCNA_SPREMA_SIFRA"] + "</STRUCNA_SPREMA_SIFRA>"); sw.WriteLine("<STRUCNA_SPREMA>" + dsPuni.PD3100Korisnik.Rows[i]["STRUCNA_SPREMA"] + "</STRUCNA_SPREMA>"); sw.WriteLine("<INVALID_PIO_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["INVALID_PIO_SIFRA"] + "</INVALID_PIO_SIFRA>"); sw.WriteLine("<INVALID_PIO>" + dsPuni.PD3100Korisnik.Rows[i]["INVALID_PIO"] + "</INVALID_PIO>"); sw.WriteLine("<INVALID_ZPR_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["INVALID_ZPR_SIFRA"] + "</INVALID_ZPR_SIFRA>"); sw.WriteLine("<INVALID_ZPR>" + dsPuni.PD3100Korisnik.Rows[i]["INVALID_ZPR"] + "</INVALID_ZPR>"); sw.WriteLine("<OSNOV_UPLATE_DOPRINOSA>"); sw.WriteLine("<DATUM_DOPRINOSA>" + dsPuni.PD3100Korisnik.Rows[i]["DATUM_PROMJENE"] + "</DATUM_DOPRINOSA>"); sw.WriteLine("<OSNOV_OBAVEZE_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["OSNOV_OBAVEZE_SIFRA"] + "</OSNOV_OBAVEZE_SIFRA>"); sw.WriteLine("<OSNOV_OBAVEZE>" + dsPuni.PD3100Korisnik.Rows[i]["OSNOV_OBAVEZE"] + "</OSNOV_OBAVEZE>"); sw.WriteLine("<RAD_VRI_SATI>" + dsPuni.PD3100Korisnik.Rows[i]["RAD_VRI_SATI"] + "</RAD_VRI_SATI>"); sw.WriteLine("<RAD_VRI_MINUTE>" + dsPuni.PD3100Korisnik.Rows[i]["RAD_VRI_MINUTE"] + "</RAD_VRI_MINUTE>"); sw.WriteLine("<ZANIMANJE_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["ZANIMANJE_SIFRA"] + "</ZANIMANJE_SIFRA>"); sw.WriteLine("<ZANIMANJE>" + dsPuni.PD3100Korisnik.Rows[i]["ZANIMANJE"] + "</ZANIMANJE>"); sw.WriteLine("<STRUCNA_SPREMA_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["STRUCNA_SPREMA_SIFRA6"] + "</STRUCNA_SPREMA_SIFRA>"); sw.WriteLine("<STRUCNA_SPREMA>" + dsPuni.PD3100Korisnik.Rows[i]["STRUCNA_SPREMA7"] + "</STRUCNA_SPREMA>"); sw.WriteLine("<DOPUNSKI_RAD_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["DOPUNSKI_RAD_SIFRA"] + "</DOPUNSKI_RAD_SIFRA>"); sw.WriteLine("<DOPUNSKI_RAD>" + dsPuni.PD3100Korisnik.Rows[i]["DOPUNSKI_RAD"] + "</DOPUNSKI_RAD>"); sw.WriteLine("<BRUTO_PLATA>" + dsPuni.PD3100Korisnik.Rows[i]["BRUTO_PLATA"] + "</BRUTO_PLATA>"); sw.WriteLine("<UVECANJE_RMJESTO_SIFRA>" + dsPuni.PD3100Korisnik.Rows[i]["UVECANJE_RMJESTO_SIFRA"] + "</UVECANJE_RMJESTO_SIFRA>"); sw.WriteLine("<UVECANJE_STEPEN>" + dsPuni.PD3100Korisnik.Rows[i]["UVECANJE_STEPEN"] + "</UVECANJE_STEPEN>"); sw.WriteLine("</OSNOV_UPLATE_DOPRINOSA>"); sw.WriteLine("</OBVEZNIK>"); sw.WriteLine("</UPLATIOC>"); sw.WriteLine("</PRIJAVA>"); } sw.WriteLine("</JS_PODACI>"); sw.WriteLine("</xml>"); sw.Close(); Log.Write("==========================================================="); Log.Write("=> Generisan je XML '{0}'. Broj slogova je: {1}", nf, count); { QResult hash = HASH.HashFromFile(nf); FileName = hash.Message; string nf1 = nf.Replace(".xml", "_KONTROLA.xml"); FileStream fs1 = new FileStream(nf1, FileMode.Append, FileAccess.Write); StreamWriter sw1 = new StreamWriter(fs1); sw1.WriteLine("<?xml version=\"1.0\"?>"); sw1.WriteLine("<UCIS xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); sw1.WriteLine("<KONTROLNI_PODACI>"); sw1.WriteLine("<MD5HASH>" + hash.Message + "</MD5HASH>"); sw1.WriteLine("<UPLATIOC>"); sw1.WriteLine("<JIB>4400411170007</JIB>"); sw1.WriteLine("<BROJ_OBVEZNIKA>" + count.ToString() + "</BROJ_OBVEZNIKA>"); sw1.WriteLine("</UPLATIOC>"); sw1.WriteLine("</KONTROLNI_PODACI>"); sw1.WriteLine("<DODATNI_PODACI>"); sw1.WriteLine("<UPLATIOC_DETALJ>"); sw1.WriteLine("<JIB>4400411170007</JIB>"); sw1.WriteLine("<NAZIV_OBVEZNIKA>ФОНД ПИО РС</NAZIV_OBVEZNIKA>"); sw1.WriteLine("<ADRESA>ЊЕГОШЕВА 28 А</ADRESA>"); sw1.WriteLine("<MJESTO>БИЈЕЉИНА</MJESTO>"); sw1.WriteLine("<OPSTINA_SIFRA_ZS>10057</OPSTINA_SIFRA_ZS>"); sw1.WriteLine("<OPSTINA_SIFRA_PU>005</OPSTINA_SIFRA_PU>"); sw1.WriteLine("<OPSTINA>БИЈЕЉИНА</OPSTINA>"); sw1.WriteLine("<TELEFON>055-202-937</TELEFON>"); sw1.WriteLine("<EMAIL>[email protected]</EMAIL>"); sw1.WriteLine("<DATUM>" + DateTime.Today.ToString("dd.MM.yyyy") + "</DATUM>"); sw1.WriteLine("<DJELATNOST_SIFRA></DJELATNOST_SIFRA>"); sw1.WriteLine("<DJELATNOST></DJELATNOST>"); sw1.WriteLine("<VRSTA_UPLATIOCA_SIFRA></VRSTA_UPLATIOCA_SIFRA>"); sw1.WriteLine("<VRSTA_UPLATIOCA></VRSTA_UPLATIOCA>"); sw1.WriteLine("</UPLATIOC_DETALJ>"); sw1.WriteLine("</DODATNI_PODACI>"); sw1.WriteLine("</UCIS>"); sw1.Close(); Log.Write("==========================================================="); Log.Write("=> Generisan je kontrolni XML '{0}'", nf1); } poruka = poruka + "\r\n" + DateTime.Now.ToString("H:mm:ss") + " => Uspješno je generisan KONTROLNI fajl"; poruka = poruka + "\r\n" + DateTime.Now.ToString("H:mm:ss") + " => Broj redova koji je eksportovan u XML je " + count; File.Copy(nf.Replace(".xml", "_KONTROLA.xml"), path + NazivExport.Replace(".xml", "_KONTROLA.xml")); Log.Write("==========================================================="); Log.Write("=> XML fajl je kopiran na lokaciju '{0}'", path + NazivExport.Replace(".xml", "_KONTROLA.xml")); File.Copy(nf, path + NazivExport); Log.Write("==========================================================="); Log.Write("=> XML kontrolni fajl je kopiran na lokaciju '{0}'", path + NazivExport); //string appPath = Path.GetDirectoryName(Application.ExecutablePath); } } catch (Exception ex) { exception = true; Log.Write("->::: GREŠKA ::: Generisanje XML fajla {0} je prekinuto: {1}!", nf, ex.ToString()); poruka = poruka + "\r\n" + DateTime.Now.ToString("H:mm:ss") + " => Greška kod generisanja XML-a " + ex.Message; //throw;--komentar poslednje sto sam komentarisao } finally { if (conn.State == System.Data.ConnectionState.Open) { conn.Close(); } if (exception) { email.SendEmail(poruka); Application.Exit(); } } }