public void ustawCzasTotal(string nrServiceGuard, string iloscGodzin) { Entities baza = new Entities(); ServiceGuard sg = baza.ServiceGuard.Find(nrServiceGuard); var uzytkownik = baza.AspNetUsers.Find(User.Identity.GetUserId()); Logi nowyWpis = new Logi(); nowyWpis.id_uzytkownik = User.Identity.GetUserId(); nowyWpis.co_zrobil = "Dealer o loginie " + uzytkownik.UserName + " ustawia czas total na SG o numerze " + nrServiceGuard + " na " + iloscGodzin + "."; nowyWpis.czas = DateTime.Now; baza.Logi.Add(nowyWpis); if (!port.IsOpen) { port.Open(); } port.Write("AT+CMGF=1\r"); Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + sg.nr_tel + "\"\r"); Thread.Sleep(100); port.WriteLine("F" + "\x11" + "GA" + "\x11" + iloscGodzin + '\x001a'); Biling daneDoZapisu = new Biling(); daneDoZapisu.data = DateTime.Now; daneDoZapisu.login = User.Identity.Name; daneDoZapisu.tresc = "F_GA_" + iloscGodzin; sg.aktualny_czas_temp = Convert.ToInt16(iloscGodzin); baza.Biling.Add(daneDoZapisu); baza.SaveChanges(); }
public void zmienNumerServiceManager(string nrServiceGuard, string nrServiceManager) { Entities baza = new Entities(); ServiceGuard sg = baza.ServiceGuard.Find(nrServiceGuard); var uzytkownik = baza.AspNetUsers.Find(User.Identity.GetUserId()); Logi nowyWpis = new Logi(); nowyWpis.id_uzytkownik = User.Identity.GetUserId(); nowyWpis.co_zrobil = "Dealer o loginie " + uzytkownik.UserName + " zmienia numer ServiceManager na SG o numerze " + nrServiceGuard + " na " + nrServiceManager + "."; nowyWpis.czas = DateTime.Now; baza.Logi.Add(nowyWpis); if (!port.IsOpen) { port.Open(); } port.Write("AT+CMGF=1\r"); Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + sg.nr_tel + "\"\r"); Thread.Sleep(100); port.WriteLine("F" + "\x11" + "G" + "\x11" + nrServiceManager + '\x001a'); Biling daneDoZapisu = new Biling(); daneDoZapisu.data = DateTime.Now; daneDoZapisu.login = User.Identity.Name; Guid s = Guid.NewGuid(); daneDoZapisu.ServiceGuard_id_sg = nrServiceGuard; daneDoZapisu.Id_b = s.ToString(); daneDoZapisu.tresc = "F_G_" + nrServiceManager; baza.Biling.Add(daneDoZapisu); sg.ServiceManager.nr_tel_temp = nrServiceManager; baza.SaveChanges(); }
public void ustawCzasStartowy(string nrServiceGuard, string iloscGodzin) { // UstawTrybWiadomosci(); Entities baza = new Entities(); var uzytkownik = baza.AspNetUsers.Find(User.Identity.GetUserId()); Logi nowyWpis = new Logi(); nowyWpis.id_uzytkownik = User.Identity.GetUserId(); nowyWpis.co_zrobil = "Dealer o loginie " + uzytkownik.UserName + " ustawia czas startowy na SG o numerze " + nrServiceGuard + " na " + iloscGodzin + "."; nowyWpis.czas = DateTime.Now; baza.Logi.Add(nowyWpis); ServiceGuard sg = baza.ServiceGuard.Find(nrServiceGuard); if (!port.IsOpen) { port.Open(); } port.Write("AT+CMGF=1\r"); Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + sg.nr_tel + "\"\r"); Thread.Sleep(100); port.WriteLine("F" + "\x11" + iloscGodzin + '\x001a'); Biling daneDoZapisu = new Biling(); Guid s = Guid.NewGuid(); daneDoZapisu.ServiceGuard_id_sg = nrServiceGuard; daneDoZapisu.Id_b = s.ToString(); daneDoZapisu.data = DateTime.Now; daneDoZapisu.login = User.Identity.Name; daneDoZapisu.tresc = "F_" + iloscGodzin; //wiecej w bazie nie grzebie przez design - to jest ok baza.Biling.Add(daneDoZapisu); baza.SaveChanges(); }
public void zmienPrzedzialSerwisu(string nrServiceGuard, string liczbaGodzin, string rodzajSerwisu) { // UstawTrybWiadomosci(); Entities baza = new Entities(); ServiceGuard sg = baza.ServiceGuard.Find(nrServiceGuard); var uzytkownik = baza.AspNetUsers.Find(User.Identity.GetUserId()); Logi nowyWpis = new Logi(); nowyWpis.id_uzytkownik = User.Identity.GetUserId(); nowyWpis.co_zrobil = "Dealer o loginie " + uzytkownik.UserName + " zmienia przedział serwisowy na SG o numerze " + nrServiceGuard + " na liczbe godzin " + liczbaGodzin + " i rodzaj serwisu " + rodzajSerwisu + "."; nowyWpis.czas = DateTime.Now; baza.Logi.Add(nowyWpis); string d = ViewBag.nrServiceGuard; if (!port.IsOpen) { port.Open(); } port.Write("AT+CMGF=1\r"); Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + sg.nr_tel + "\"\r"); Thread.Sleep(100); port.WriteLine("F" + "\x11" + "GS" + '\x11' + liczbaGodzin + "#" + rodzajSerwisu + '\x001a'); Biling daneDoZapisu = new Biling(); Guid s = Guid.NewGuid(); daneDoZapisu.ServiceGuard_id_sg = nrServiceGuard; daneDoZapisu.Id_b = s.ToString(); daneDoZapisu.data = DateTime.Now; daneDoZapisu.login = User.Identity.Name; daneDoZapisu.tresc = "F_GS_" + liczbaGodzin + "#" + rodzajSerwisu; baza.Biling.Add(daneDoZapisu); sg.przedzial_serwisowy_temp = liczbaGodzin + rodzajSerwisu; baza.SaveChanges(); }
public void aktualizujDane(string nrServiceGuard) { // UstawTrybWiadomosci(); Entities baza = new Entities(); ServiceGuard sg = baza.ServiceGuard.Find(nrServiceGuard); var uzytkownik = baza.AspNetUsers.Find(User.Identity.GetUserId()); // var uzytkownik = baza.AspNetUsers.Find(User.Identity.GetUserId()); Logi nowyWpis = new Logi(); nowyWpis.id_uzytkownik = User.Identity.GetUserId(); nowyWpis.co_zrobil = "Dealer o loginie " + uzytkownik.UserName + " aktualizuje dane na SG o numerze " + nrServiceGuard + "."; nowyWpis.czas = DateTime.Now; baza.Logi.Add(nowyWpis); port.Write("AT+CMGF=1\r"); Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + sg.nr_tel + "\"\r"); Thread.Sleep(100); port.WriteLine("F" + "\x11" + "C" + '\x001a'); Biling daneDoZapisu = new Biling(); Guid s = Guid.NewGuid(); daneDoZapisu.ServiceGuard_id_sg = nrServiceGuard; daneDoZapisu.tresc = "F_C"; daneDoZapisu.Id_b = s.ToString(); daneDoZapisu.data = DateTime.Now; daneDoZapisu.login = User.Identity.Name; baza.Biling.Add(daneDoZapisu); baza.SaveChanges(); }
public ActionResult DeleteConfirmed(string id) { ServiceGuard serviceGuard = db.ServiceGuard.Find(id); db.ServiceGuard.Remove(serviceGuard); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "serial_number,nr_karty,pin,nr_tel,lokalizacja,aktualny_czas,przedzial_serwisowy,do_serwisu,ostatni_serwis,ostatni_alarm,licznik_sms,ServiceManager_id_sm,user_id_u,jezyk,firma,nrSuperVisor,nrServiceCenter")] ServiceGuard serviceGuard) { if (ModelState.IsValid) { db.Entry(serviceGuard).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ServiceManager_id_sm = new SelectList(db.ServiceManager, "Id_sm", "nr_tel", serviceGuard.ServiceManager_id_sm); return(View(serviceGuard)); }
// GET: ServiceGuards/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceGuard serviceGuard = db.ServiceGuard.Find(id); if (serviceGuard == null) { return(HttpNotFound()); } return(View(serviceGuard)); }
// GET: ServiceGuards/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ServiceGuard serviceGuard = db.ServiceGuard.Find(id); if (serviceGuard == null) { return(HttpNotFound()); } ViewBag.ServiceManager_id_sm = new SelectList(db.ServiceManager, "Id_sm", "nr_tel", serviceGuard.ServiceManager_id_sm); return(View(serviceGuard)); }
public ActionResult doPaneluAdmina2() { ServiceGuard a = new ServiceGuard(); return(View("PanelAdmina2", a)); }
public static void przeczytajSMS(int wiersz) { Entities baza = new Entities(); SMS[] odpowiedz = baza.SMS.ToArray(); string aktualnalinijka = odpowiedz[wiersz].tresc_sms; string[] dane = aktualnalinijka.Split("\r\n".ToArray()); //dzielenie po enter string[] tabelaWiadomosci = new string[dane.Length + 10]; //i+2 niech nie wyjezdza int j = 0; for (int i = 0; i < dane.Length; i++) { if (dane[i].Contains("REC READ") == true || dane[i].Contains("REC UNREAD") == true) { tabelaWiadomosci[j] = dane[i]; tabelaWiadomosci[j + 1] = dane[i + 2]; //dane najpierw maja czas oraz nr, potem null a nastepnie tresc wiadomosci, dlatego +2 j = j + 2; } } //czas zapiąć pasy - switch olać w razie nowych komend, które nie będą rozpoznawane po podłodze za serial number //guziki dane = new string[10]; for (int i = 1; i < j; i = i + 2) //bylo i=1 w razie czego zmien { if (tabelaWiadomosci[i].Contains("_") == false) { dane = tabelaWiadomosci[i].Split("".ToArray()); } else { dane = tabelaWiadomosci[i].Split("_".ToArray()); } try { Entities bazaDanych = new Entities(); if (dane[1] == "ALARMM") { Alarmy nowyWpis = new Alarmy(); ServiceGuard sg = bazaDanych.ServiceGuard.Find(dane[0]); nowyWpis.data_alarmu = DateTime.Now; nowyWpis.status = "do_wykonania"; nowyWpis.typ_alarmu = "M"; nowyWpis.ServiceGuard_id_sg = sg.serial_number; nowyWpis.serial_number = dane[0]; bazaDanych.Alarmy.Add(nowyWpis); bazaDanych.SaveChanges(); Thread.Sleep(250); port.Write("AT+CMGF=1\r"); Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + sg.nr_tel + "\"\r"); Thread.Sleep(100); port.WriteLine("F" + "\x11" + "OK" + '\x001a'); Thread.Sleep(250); // Entities baza = new Entities(); // ServiceGuard sg = baza.ServiceGuard.Find(nrServiceGuard); List <AspNetUsers> listaUzytkownikow = sg.AspNetUsers.ToList(); //lista przypisanych do danego SG for (int k = 0; k < listaUzytkownikow.Count; k++) { port.Write("AT+CMGF=1\r"); Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + listaUzytkownikow[k].telefon + "\"\r"); Thread.Sleep(100); var account = new AccountController(); var rolaUzytkownika = account.UserManager.GetRoles(listaUzytkownikow[k].Id); string test = "test"; if (rolaUzytkownika.ToString() == "rolnik") { port.WriteLine("Szanowny Kliencie uprzejmie informujemy, że nadszedł czas dokonania okresowego serwisu.Prosimy o kontakt z Naszym Dealerem. Zespół GEA Polska." + '\x001a'); Thread.Sleep(250); } if (rolaUzytkownika.ToString() == "dealer") { port.WriteLine("Nadszedł czas serwisu urządzenia " + sg.serial_number + ". Zespół GEA Polska." + '\x001a'); Thread.Sleep(250); } if (rolaUzytkownika.ToString() == "admin") { } if (rolaUzytkownika.ToString() == "gea") { port.WriteLine("Urządzenie " + sg.serial_number + " wymaga serwisu." + '\x001a'); Thread.Sleep(250); } Thread.Sleep(250); } } if (dane[1] == "ALARMD") { ServiceGuard sg = bazaDanych.ServiceGuard.Find(dane[0]); port.Close(); Thread.Sleep(500); port.Open(); port.Write("AT+CMGF=1\r"); // Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + sg.nr_tel + "\"\r"); // Thread.Sleep(100); port.WriteLine("F" + "\x11" + "OK" + '\x001a'); Alarmy nowyWpis = new Alarmy(); nowyWpis.data_alarmu = DateTime.Now; nowyWpis.status = "do_wykonania"; nowyWpis.typ_alarmu = "D"; nowyWpis.ServiceGuard_id_sg = sg.serial_number; nowyWpis.serial_number = dane[0]; bazaDanych.Alarmy.Add(nowyWpis); bazaDanych.SaveChanges(); List <AspNetUsers> listaUzytkownikow = sg.AspNetUsers.ToList(); //lista przypisanych do danego SG for (int l = 0; l < listaUzytkownikow.Count; l++) { port.Write("AT+CMGF=1\r"); // Thread.Sleep(250); port.WriteLine("AT+CMGS=\"" + listaUzytkownikow[l].telefon + "\"\r"); // Thread.Sleep(100); var account = new AccountController(); var rolaUzytkownika = account.UserManager.GetRoles(listaUzytkownikow[l].Id); string test = "test"; if (rolaUzytkownika.ToString() == "rolnik") { port.WriteLine("Szanowny Kliencie uprzejmie informujemy, że nadszedł czas dokonania okresowego serwisu.Prosimy o kontakt z Naszym Dealerem. Zespół GEA Polska." + '\x001a'); // Thread.Sleep(250); } if (rolaUzytkownika.ToString() == "dealer") { port.WriteLine("Nadszedł czas serwisu urządzenia " + sg.serial_number + ". Zespół GEA Polska." + '\x001a'); // Thread.Sleep(250); } if (rolaUzytkownika.ToString() == "admin") { } if (rolaUzytkownika.ToString() == "gea") { port.WriteLine("Urządzenie " + sg.serial_number + " wymaga serwisu." + '\x001a'); // Thread.Sleep(250); } // Thread.Sleep(250); } } if (dane[1] == "OK") //jesteśmy w "zrób serwis", czyli serialnumber_OK { SerialPortController s = new SerialPortController(); var uzytkownik = bazaDanych.AspNetUsers.Find(s.User.Identity.GetUserId()); ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); var listaAlarmow = SG.Alarmy.ToList(); foreach (Alarmy a in listaAlarmow) { a.wykonal = uzytkownik.UserName; } } if (dane[1] == "RESET") { ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.ostatni_serwis = SG.ostatni_serwis_temp; bazaDanych.SaveChangesAsync(); } if (dane[1] == "C") //aktualizuj dane { string[] tmp = dane[5].Split("#".ToArray()); //np. 0750#B string przedzial = tmp[0]; //0750 string serialNumber = dane[0]; string aktualnyStanRoboczogodzin = dane[2]; string godzinyDoSerwisu = (Convert.ToInt16(przedzial) - Convert.ToInt16(dane[3])).ToString(); string lokalizacja = dane[4]; ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.aktualny_czas = Convert.ToInt16(aktualnyStanRoboczogodzin); SG.do_serwisu = Convert.ToInt32(godzinyDoSerwisu); SG.lokalizacja = lokalizacja; SG.przedzial_serwisowy = przedzial; bazaDanych.SaveChanges(); } if (dane[1] == "GSL") //zmień przedział serwisu { string serialNumber = dane[0]; ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.przedzial_serwisowy = SG.przedzial_serwisowy_temp; bazaDanych.SaveChanges(); } if (dane[1] == "LNG") //zmień język { string serialNumber = dane[0]; ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.jezyk = SG.jezyk_temp; bazaDanych.SaveChanges(); } if (dane[1] == "ZGS") //ustaw czas startowy { string serialNumber = dane[0]; //olac } if (dane[1] == "AGS") //ustaw czas total { string serialNumber = dane[0]; ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.aktualny_czas = SG.aktualny_czas_temp; bazaDanych.SaveChanges(); } if (dane[1] == "SOK") //zmień serial number { string serialNumber = dane[0]; ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.serial_number = SG.serial_number_temp; bazaDanych.SaveChanges(); } if (dane[1] == "VOK") //zmień super visor { string serialNumber = dane[0]; ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.nrSuperVisor = SG.nrSuperVisor_temp; bazaDanych.SaveChanges(); } if (dane[1] == "NOK") //zmień service center { string serialNumber = dane[0]; ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.nrServiceCenter = SG.nrServiceCenter_temp; bazaDanych.SaveChanges(); } if (dane[1] == "GOK") //zmień service manager { string serialNumber = dane[0]; ServiceGuard SG = bazaDanych.ServiceGuard.Find(dane[0]); SG.ServiceManager.nr_tel = SG.ServiceManager.nr_tel_temp; bazaDanych.SaveChanges(); } } catch (Exception ex) { string s = ex.InnerException.ToString(); //nic nie rob, jesli szukamy za daleko w podzielonym stringu, to po prostu mamy krotsza odpowiedz } } }
public async Task wyslijEmailAlarm(string nrServiceGuard) { Entities baza = new Entities(); ServiceGuard sg = baza.ServiceGuard.Find(nrServiceGuard); List <AspNetUsers> listaUzytkownikow = sg.AspNetUsers.ToList(); //lista przypisanych do danego SG string klient = @"Szanowny Panie <imię> <nazwisko> Uprzejmie informujemy ,że nadszedł czas okresowego serwisu Pańskiego urządzenia. Prosimy o kontakt z Naszym Autoryzowanym Dealerem <firma> <adres> <telefon> Z poważaniem GEA Polska."; string dealer = @"Szanowny Dealerze naszedł czas wykonania serwisu urządzenia podpiętego do ServiceGuard o numerze <serial_number> zainstalowanego u klienta: <dane klienta> Z poważaniem GEA Polska."; string gea = @"Nadszedł czas okresowego serwisu urządzenia <serial_number> Zainstalowanego u klienta <dane klienta> Obsługiwanego przez: <dane dealera>"; var account = new AccountController(); for (int i = 0; i < listaUzytkownikow.Count; i++) { var rolaUzytkownika = account.UserManager.GetRolesAsync(listaUzytkownikow[i].Id); if (rolaUzytkownika.ToString() == "rolnik") { var message = new MailMessage(); message.To.Add(new MailAddress(listaUzytkownikow[i].Email)); message.From = new MailAddress("*****@*****.**"); // DO ZMIANY message.Subject = "Witamy w serwisie GEA ServiceGuard!"; klient = klient.Replace("<imię> <nazwisko>", listaUzytkownikow[i].imie + " " + listaUzytkownikow[i].nazwisko); // klient = klient.Replace("<firma>", ); message.Body = klient; message.IsBodyHtml = false; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", Password = "******" }; smtp.Credentials = credential; smtp.Host = "ssl0.ovh.net"; smtp.Port = 25; smtp.EnableSsl = true; await smtp.SendMailAsync(message); } } if (rolaUzytkownika.ToString() == "dealer") { var message = new MailMessage(); message.To.Add(new MailAddress(listaUzytkownikow[i].Email)); message.From = new MailAddress("*****@*****.**"); // DO ZMIANY message.Subject = "Witamy w serwisie GEA ServiceGuard!"; dealer = dealer.Replace("<serial_number>", sg.serial_number); // dealer = dealer.Replace("###HASLO###", haslo); message.Body = dealer; message.IsBodyHtml = false; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", Password = "******" }; smtp.Credentials = credential; smtp.Host = "ssl0.ovh.net"; smtp.Port = 25; smtp.EnableSsl = true; await smtp.SendMailAsync(message); } } if (rolaUzytkownika.ToString() == "admin") { } if (rolaUzytkownika.ToString() == "gea") { var message = new MailMessage(); message.To.Add(new MailAddress(listaUzytkownikow[i].Email)); message.From = new MailAddress("*****@*****.**"); // DO ZMIANY message.Subject = "Witamy w serwisie GEA ServiceGuard!"; gea = gea.Replace("<serial_number>", sg.serial_number); message.Body = gea; message.IsBodyHtml = false; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", Password = "******" }; smtp.Credentials = credential; smtp.Host = "ssl0.ovh.net"; smtp.Port = 25; smtp.EnableSsl = true; await smtp.SendMailAsync(message); } } } }