Exemplo n.º 1
0
        /// <summary>
        /// allocate size bytes starting at a particular address
        /// </summary>
        /// <param name="start"></param>
        /// <param name="size"></param>
        public MemoryBlock(ulong start, ulong size)
        {
#if !MONO
            Start = (ulong)Kernel32.VirtualAlloc(Z.UU(start), Z.UU(size),
                                                 Kernel32.AllocationType.RESERVE | Kernel32.AllocationType.COMMIT,
                                                 Kernel32.MemoryProtection.NOACCESS);
            if (Start == 0)
            {
                throw new InvalidOperationException("VirtualAlloc() returned NULL");
            }
            if (start != 0)
            {
                End = start + size;
            }
            else
            {
                End = Start + size;
            }
            Size = End - Start;
#else
            Start = (ulong)LibC.mmap(ZC.U(start), ZC.U(size), 0, LibC.MapType.MAP_ANONYMOUS, -1, IntPtr.Zero);
            if (Start == 0)
            {
                throw new InvalidOperationException("mmap() returned NULL");
            }
            End  = Start + size;
            Size = End - Start;
#endif
        }
Exemplo n.º 2
0
 public void InitEndpoint()
 {
     Local4ZCPoint  = Local4ZC.GetEndPoint();
     Local4CBIPoint = Local4CBI.GetEndPoint();
     ZCEndPoint     = ZC.GetEndPoint();
     for (int i = 0; i < CBIs.Count; i++)
     {
         CBIEndPoints.Add(CBIs[i].GetEndPoint());
     }
 }
Exemplo n.º 3
0
        private void Dispose(bool disposing)
        {
            if (Start != 0)
            {
#if !MONO
                Kernel32.VirtualFree(Z.UU(Start), UIntPtr.Zero, Kernel32.FreeType.RELEASE);
#else
                LibC.munmap(ZC.U(Start), (UIntPtr)Size);
#endif
                Start = 0;
            }
        }
Exemplo n.º 4
0
        public static bool polaczenieClient(ref UdpClient klient)
        {
            byte[]     data;
            int        port;
            DateTime   ZC;
            string     dec;
            IPEndPoint ip = new IPEndPoint(IPAddress.Any, 11000);

            Console.WriteLine("Podaj adres IP odbiorcy: ");
            string IP = Console.ReadLine();

            Console.WriteLine("Podaj port odbiorcy: ");
            try { port = Convert.ToInt32(Console.ReadLine()); }
            catch (FormatException e) { Console.WriteLine(e.Message); port = 0; }
            string[] spr = IP.Split('.');
            while (true)
            {
                if (port < 65535 && port > 1023 && spr.Length == 4 && IP != "0.0.0.0") //Sprawdzenie poprawności formy podanych parametrów
                {
                    string wiadomosc = string.Empty;
                    ZC         = DateTime.Now;
                    wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: BRAK%NS: 0%OP: POLACZ%";  // komunikat poczatkowy przed nadaniem ID sesji
                    klient     = new UdpClient(IP, port);
                    data       = Encoding.ASCII.GetBytes(wiadomosc);
                    klient.Send(data, data.Length);
                    return(true);
                }
                else
                {
                    Console.WriteLine("Nie udalo sie nawiazac polaczenia. Czy chcesz spróbować ponownie?(0/1)");
                    dec = Console.ReadLine();
                    if (dec == "1")
                    {
                        return(polaczenieClient(ref klient));
                    }
                    else if (dec == "0")
                    {
                        return(false);
                    }
                    else
                    {
                        Console.WriteLine("Niepoprawna odpowiedz");
                    }
                }
            }
        }
Exemplo n.º 5
0
    /// <summary>
    /// “修改”按钮单击事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnChag_ServerClick(object sender, EventArgs e)
    {
        ArrayList selectedZC = GetSelected();
        ZC        zc         = new ZC();

        if (selectedZC.Count != 1)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择一个职称!');</script>");
            return;
        }
        string zcbh = selectedZC[0].ToString();

        zc.LoadData(zcbh);
        txtZcbh.Value  = zc.Zcbh;
        txtZcmc.Value  = zc.Zcmc;
        txtBzgzl.Value = Convert.ToString(zc.Bzgzl);
        foreach (ListItem item in selZclx.Items)
        {
            if (item.Selected == true)
            {
                item.Selected = false;
            }
            if (item.Value == zc.Zclx)
            {
                item.Selected = true;
            }
        }


        txtZcmc.Disabled   = false;
        txtBzgzl.Disabled  = false;
        selZclx.Enabled    = true;
        txtZcbh.Disabled   = true;
        btnChag.Disabled   = true;
        btnAdd.Disabled    = false;
        btnSave.Disabled   = false;
        btnCancel.Disabled = false;
    }
Exemplo n.º 6
0
    /// <summary>
    /// 初始化页面数据
    /// </summary>
    private void InitData()
    {
        string loginName = Session["login_name"].ToString();

        userMessage01.InnerText = "你好!" + loginName;
        labelXnd.Text           = Session["xnd"].ToString() + "学年度";

        Hashtable ht = new Hashtable();

        ht.Add("yxbz", 1);
        DataTable dt = YX.QueryYX(ht);

        foreach (DataRow dr in dt.Rows)
        {
            selSsyx.Items.Add(new ListItem(dr["Yxmc"].ToString(), dr["Yxbh"].ToString()));
        }

        DataTable dt1 = ZC.QueryZC(new Hashtable());

        foreach (DataRow dr1 in dt1.Rows)
        {
            selJszc.Items.Add(new ListItem(dr1["zcmc"].ToString(), dr1["zcbh"].ToString()));
        }
    }
Exemplo n.º 7
0
        public static void operacje(UdpClient client, IPEndPoint ip, byte[] data, int ID)
        {
            string OP = string.Empty, ST = string.Empty, ER = string.Empty, OH = string.Empty;
            int    NS = 0, count = 0, n = 0, bigbrain = 0;
            double liczba1 = 0;
            double wynik = 0;
            double liczba2 = 0;
            string operacja = string.Empty, wiadomosc = string.Empty;

            string[][] AllSplits = new string[100][];
            Console.WriteLine("Podaj operację: "); //zapytanie o operację
            operacja = Console.ReadLine();
            DateTime    ZC;
            List <Wpis> Historia = new List <Wpis>();
            Wpis        noname   = new Wpis();

            try //zapytanie o liczby w zależności od wybranej operacji
            {
                //w przypadku silni i hisid potrzebujemy tylko 1 liczby
                if (operacja.ToLower() == "silnia" || operacja.ToLower() == "hisid")
                {
                    Console.WriteLine("Podaj liczbę 1: ");
                    liczba1 = Convert.ToDouble(Console.ReadLine());
                    NS      = 2;
                }
                //podawanie liczb
                else if (operacja.ToLower() == "mnozenie" || operacja.ToLower() == "dzielenie" || operacja.ToLower() == "odejmowanie" || operacja.ToLower() == "dodawanie" || operacja.ToLower() == "hisido")
                {
                    Console.WriteLine("Podaj liczbę 1: ");
                    liczba1 = Convert.ToDouble(Console.ReadLine());

                    Console.WriteLine("Podaj liczbę 2: ");
                    liczba2 = Convert.ToDouble(Console.ReadLine());

                    NS = 3;
                }

                else
                {
                    throw new Exception("Nieznana operacja!!!");
                }
            }
            //wysyłanie komunikatów
            catch (Exception ex) { Console.WriteLine($"Wystąpił błąd: {ex.Message}, typ: {ex.GetType()}"); operacje(client, ip, data, ID); return; }
            ZC         = DateTime.Now;
            wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%OP: " + operacja.ToLower() + "%"; //operacja
            data       = Encoding.ASCII.GetBytes(wiadomosc);
            client.Send(data, data.Length);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%ST: brak%"; //status
            data       = Encoding.ASCII.GetBytes(wiadomosc);
            client.Send(data, data.Length);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%L1: " + liczba1 + "%"; //liczba 1
            data       = Encoding.ASCII.GetBytes(wiadomosc);
            client.Send(data, data.Length);
            wiadomosc = string.Empty;

            NS--;

            if (NS == 0)
            {
                ZC         = DateTime.Now;
                wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%L2: " + liczba2 + "%"; //liczba 2
                data       = Encoding.ASCII.GetBytes(wiadomosc);
                client.Send(data, data.Length);
                wiadomosc = string.Empty;
            }



            while (true) //oczekiwanie na zwrotne informacje
            {
                data = client.Receive(ref ip);

                string   dane  = Encoding.ASCII.GetString(data, 0, data.Length);
                string[] split = dane.Split(new char[] { ':', '%' });
                AllSplits[count] = split;
                count++;
                if (Convert.ToInt32(split[5]) == 0)
                {
                    break;
                }
            }
            foreach (string[] i in AllSplits) //segregacja informacji z komunikatów
            {
                if (OH.ToLower() == " hisid" || OH.ToLower() == " hisido")
                {
                    if (i[6] == "OP")
                    {
                        noname.operacja = i[7];
                    }
                    else if (i[6] == "ST")
                    {
                        ST = i[7];
                    }
                    else if (i[6] == "L1")
                    {
                        noname.liczba1 = i[7]; n++;
                    }
                    else if (i[6] == "L2")
                    {
                        noname.liczba2 = i[7]; n++;
                    }
                    else if (i[6] == "LW")
                    {
                        noname.wynik = i[7]; n++;
                    }
                    else if (i[6] == "IDO")
                    {
                        noname.IDO = Convert.ToInt32(i[7]); n++;
                    }
                    else if (i[6] == "ER")
                    {
                        ER = i[7];
                    }
                    if ((noname.operacja == " silnia" && n == 3) || n == 4)
                    {
                        n = 0; Historia.Add(noname); noname = new Wpis();
                    }
                }
                else
                {
                    if (i == null)
                    {
                        break;
                    }
                    if (i[6] == "OP")
                    {
                        OP = i[7]; if (OP.ToLower() == " hisid" || OP.ToLower() == " hisido")
                        {
                            OH = OP;
                        }
                    }
                    else if (i[6] == "ST")
                    {
                        ST = i[7];
                    }
                    else if (i[6] == "L1")
                    {
                        liczba1 = Convert.ToInt32(i[7]);
                    }
                    else if (i[6] == "L2")
                    {
                        liczba2 = Convert.ToInt32(i[7]);
                    }
                    else if (i[6] == "LW")
                    {
                        wynik = Convert.ToDouble(i[7]);
                    }
                }
                bigbrain++;
                if (bigbrain == count)
                {
                    bigbrain = 0; break;
                }
            }
            if (ST == " ERROR_0")
            {
                Console.WriteLine("Wystapil blad : [Niepoprawny format]");
            }
            else if (ST == " ERROR_1")
            {
                Console.WriteLine("Wystapil blad : [Dzielenie przez zero]");
            }
            else if (ST == " ERROR_2")
            {
                Console.WriteLine("Wystapil blad : [Brak dostępu]");
            }
            else if (ST == " ERROR_3")
            {
                Console.WriteLine("Wystapil blad : [Brak operacji]");
            }
            else if (ST == " ERROR_4")
            {
                Console.WriteLine("Wystapil blad : [Przekroczono rozmiar stosu]");
            }
            else if (OH.ToLower() == " hisid" || OH.ToLower() == " hisido")
            {
                Console.WriteLine("");
                Console.WriteLine("Historia obliczen dla sesji {0}.:", ID); //Wyświetlanie Historii obliczeń
                foreach (var i in Historia)
                {
                    Console.WriteLine("----------------Obliczenie {0}.------------------", i.IDO);
                    Console.WriteLine("Operacja :{0}", i.operacja);
                    Console.WriteLine("Liczba 1: {0}", i.liczba1);
                    if (i.operacja.ToLower() != "  silnia")
                    {
                        Console.WriteLine("Liczba 2: {0}", i.liczba2);
                    }
                    Console.WriteLine("Wynik: {0}", i.wynik);
                }
                Console.WriteLine("---------------------------------------------");
                OH = String.Empty;
            }
            else
            {
                Console.WriteLine("---------------------------------------------");
                Console.WriteLine("Operacja: {0}", OP);
                Console.WriteLine("Wynik: {0} ", wynik); //Wyświetlenie wyniku obliczeń
                Console.WriteLine("---------------------------------------------");
            }
        }
Exemplo n.º 8
0
        public static void obliczenia(UdpClient server, IPEndPoint ip, byte[] data, int ID, ref int IDO, List <Wpis> Historia) //Funkcja odbierająca komunikaty dotyczące obliczeń i przeprowadzająca je
        {
            //zmiennie niezbedne do wykonania
            DateTime ZC;
            string   wiadomosc = string.Empty, OP = string.Empty, dane, ST = "OK";
            int      l1 = 0, l2 = 0;
            double   wynik = 0;

            string[][] AllSplits = new string[4][];
            int        n = 0, NS;
            Wpis       temp = new Wpis();

            temp.ID = ID;
            while (true)  //oczekiwanie na komunikaty okreslajace operacje oraz liczby na których ma ona być przeprowadzona
            {
                data = server.Receive(ref ip);
                dane = Encoding.ASCII.GetString(data, 0, data.Length);
                string[] split = dane.Split(new char[] { ':', '%' });
                AllSplits[n] = split;
                Console.WriteLine(dane);
                n++;
                if (Convert.ToInt32(split[5]) <= 0)
                {
                    break;
                }
            }
            foreach (string[] i in AllSplits) //interpretacja komunikatow
            {
                if (i == null)
                {
                    break;
                }
                if (i[6] == "OP")
                {
                    temp.operacja = OP = i[7];
                }
                else if (i[6] == "L1")
                {
                    try
                    {
                        temp.liczba1 = i[7];
                        l1           = Convert.ToInt32(i[7]);
                    }
                    catch (Exception e)
                    {
                        if (OP.ToLower() != " hisid" && OP.ToLower() != " hisido")
                        {
                            temp.IDO = IDO++;
                            obslugaBledow.ObslugaBledow(server, e, ref ID, OP, ip, temp, ref Historia, 0);
                        }
                        else
                        {
                            obslugaBledow.ObslugaBledow(server, e, ref ID, OP, ip, 0);
                        }
                        return;
                    }
                }
                else if (i[6] == "L2")
                {
                    try
                    {
                        temp.liczba2 = i[7];
                        l2           = Convert.ToInt32(i[7]);
                    }
                    catch (Exception e)
                    {
                        if (OP.ToLower() != " hisid" && OP.ToLower() != " hisido")
                        {
                            temp.IDO = IDO++;
                            obslugaBledow.ObslugaBledow(server, e, ref ID, OP, ip, temp, ref Historia, 0);
                        }
                        else
                        {
                            obslugaBledow.ObslugaBledow(server, e, ref ID, OP, ip, 0);
                        }
                        return;
                    }
                }
            }

            // obliczanie wynikow
            if (OP.ToLower() == " mnozenie")
            {
                wynik    = Mnozenie(l1, l2);
                temp.IDO = IDO++;
            }
            else if (OP.ToLower() == " dzielenie")
            {
                try
                {
                    wynik    = l1 / l2;
                    temp.IDO = IDO++;
                }
                catch (DivideByZeroException e)
                {
                    temp.IDO = IDO++;
                    obslugaBledow.ObslugaBledow(server, e, ref ID, OP, ip, temp, ref Historia, 1);
                    return;
                }
            }
            else if (OP.ToLower() == " dodawanie")
            {
                wynik    = Dodawanie(l1, l2);
                temp.IDO = IDO++;
            }
            else if (OP.ToLower() == " odejmowanie")
            {
                wynik    = Odejmowanie(l1, l2);
                temp.IDO = IDO++;
            }
            // wywolanie przez uzytkownika podania calej historii
            else if (OP.ToLower() == " hisid")
            {
                try
                {
                    if (l1 != ID)
                    {
                        throw new Exception("brakDostepu!");
                    }
                    else
                    {
                        His.HisID(Historia, l1, server, ip);
                        return;
                    }
                }
                catch (Exception e)
                {
                    obslugaBledow.ObslugaBledow(server, e, ref ID, OP, ip, 2);
                    return;
                }
            }
            //wywolanie przez uzytkownika podania historii obliczenia
            else if (OP.ToLower() == " hisido")
            {
                try
                {
                    if (l1 != ID)
                    {
                        throw new Exception("2");
                    }
                    else if (l2 > IDO - 1)
                    {
                        throw new Exception("3");
                    }
                    else
                    {
                        His.HisIDO(Historia, l1, l2, server, ip);
                        return;
                    }
                }
                catch (Exception e)
                {
                    obslugaBledow.ObslugaBledow(server, e, ref ID, OP, ip, Convert.ToInt32(e.Message));
                    return;
                }
            }
            else if (OP.ToLower() == " silnia")
            {
                try
                {
                    temp.IDO = IDO++;
                    if (l1 >= 12 || l1 < 0)
                    {
                        throw new Exception("4");
                    }
                    wynik = Silnia(l1);
                }
                catch (Exception e)
                {
                    obslugaBledow.ObslugaBledow(server, e, ref ID, OP, ip, temp, ref Historia, 4);
                    return;
                }
            }
            temp.wynik = Convert.ToString(wynik);
            if (OP.ToLower() != " hisido" || OP.ToLower() != " hisid")
            {
                Historia.Add(temp);
            }
            NS = 2;
            //przygotowanie komunikatow
            Console.WriteLine(wynik);
            ZC         = DateTime.Now;
            wiadomosc  = string.Empty;
            wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%OP: " + OP.ToLower() + "%"; //odsyłanie komunikatu z rodzajem operacji , jej statusem i wynikiem
            data       = Encoding.ASCII.GetBytes(wiadomosc);
            server.Send(data, data.Length, ip);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%ST: " + ST + "%";
            data       = Encoding.ASCII.GetBytes(wiadomosc);
            server.Send(data, data.Length, ip);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%LW: " + wynik + "%";
            data       = Encoding.ASCII.GetBytes(wiadomosc);
            server.Send(data, data.Length, ip);
            wiadomosc = string.Empty;
        }
Exemplo n.º 9
0
        static void obliczenia(UdpClient server, IPEndPoint ip, byte[] data, int ID) //Funkcja odbierająca komunikaty dotyczące obliczeń i przeprowadzająca je
        {
            DateTime ZC;
            string   wiadomosc = string.Empty, OP = string.Empty, dane, ST = "OK";
            int      l1 = 0, l2 = 0;
            double   wynik = 0;

            string[][] AllSplits = new string[4][];
            int        n = 0, NS;

            while (true)  //oczekiwanie na komunikaty okreslajace operacje oraz liczby na których ma ona być przeprowadzona
            {
                data = server.Receive(ref ip);
                dane = Encoding.Unicode.GetString(data, 0, data.Length);
                string[] split = dane.Split(new char[] { ':', '%' });
                AllSplits[n] = split;
                Console.WriteLine(dane);
                n++;
                if (Convert.ToInt32(split[5]) <= 0)
                {
                    break;
                }
            }
            foreach (string[] i in AllSplits) //interpretacja komunikatow
            {
                if (i == null)
                {
                    break;
                }
                if (i[6] == "OP")
                {
                    OP = i[7];
                }
                else if (i[6] == "L1")
                {
                    try { l1 = Convert.ToInt32(i[7]); }
                    catch (FormatException e) { ObslugaBledow(server, e, ID, OP, ip); return; }
                }
                else if (i[6] == "L2")
                {
                    try { l2 = Convert.ToInt32(i[7]); }
                    catch (FormatException e) { ObslugaBledow(server, e, ID, OP, ip); return; }
                }
            }
            if (OP.ToLower() == "mnozenie")
            {
                wynik = Mnozenie(l1, l2);
            }
            else if (OP.ToLower() == "dzielenie")
            {
                try { wynik = l1 / l2; }
                catch (DivideByZeroException e) { ObslugaBledow(server, e, ID, OP, ip); return; }
            }
            else if (OP.ToLower() == "dodawanie")
            {
                wynik = Dodawanie(l1, l2);
            }
            else if (OP.ToLower() == "odejmowanie")
            {
                wynik = Odejmowanie(l1, l2);
            }
            else if (OP.ToLower() == "silnia")
            {
                try { wynik = Silnia(l1); }
                catch (StackOverflowException e) { ObslugaBledow(server, e, ID, OP, ip); return; }
            }
            NS = 2;

            Console.WriteLine(wynik);
            ZC         = DateTime.Now;
            wiadomosc  = string.Empty;
            wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:" + NS + "%OP:" + OP.ToLower() + "%"; //odsyłanie komunikatu z rodzajem operacji , jej statusem i wynikiem
            data       = Encoding.Unicode.GetBytes(wiadomosc);
            server.Send(data, data.Length, ip);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:" + NS + "%ST:" + ST + "%";
            data       = Encoding.Unicode.GetBytes(wiadomosc);
            server.Send(data, data.Length, ip);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:" + NS + "%LW:" + wynik + "%";
            data       = Encoding.Unicode.GetBytes(wiadomosc);
            server.Send(data, data.Length, ip);
            wiadomosc = string.Empty;
        }
Exemplo n.º 10
0
        static void Main(string[] args)                                                                         //TU JEST MAIN TU JEST MAIN TU JEST MAIN TU JEST MAIN
        {
            UdpClient client = new UdpClient();

            if (Pol.polaczenieClient(ref client) == false)
            {
                return;                                           // użytkownik podaje IP oraz port
            }
            IPEndPoint ip = new IPEndPoint(IPAddress.Any, 11000);

            int    n  = 0;
            int    ID = 0;
            string odp;

            byte[]     data;
            string[][] AllSplits = new string[4][];
            DateTime   ZC;

            while (true) //oczekiwanie na nadanie ID
            {
                data = client.Receive(ref ip);

                string   dane  = Encoding.ASCII.GetString(data, 0, data.Length);
                string[] split = dane.Split(new char[] { ':', '%' });
                AllSplits[n] = split;
                n++;
                if (Convert.ToInt32(split[5]) <= 0)
                {
                    n = 0;

                    try //Potwierdzenie nadania ID
                    {
                        ID = Convert.ToInt32(split[3]);
                        ZC = DateTime.Now;
                        Console.WriteLine("ID Twojej sesji to: {0}", ID);
                        Console.WriteLine("");
                        string temp = "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: 1%OP: NadanieID%";
                        data = Encoding.ASCII.GetBytes(temp);
                        client.Send(data, data.Length);
                        temp = string.Empty;
                        ZC   = DateTime.Now;
                        temp = "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: 0%ST: OK%";
                        data = Encoding.ASCII.GetBytes(temp);
                        client.Send(data, data.Length);
                    }
                    catch (Exception) { }
                    break;
                }
            }
            Op.operacje(client, ip, data, ID); //wybranie operacji i wysłanie odpowiednich komunikatów do serwera

            do                                 //zapytanie o kontynuacje pracy
            {
                Console.WriteLine("Czy chcesz wykonać ponowne obliczenia ? (0/1)");
                odp = Console.ReadLine();
                if (odp == "1")
                {
                    ZC = DateTime.Now;
                    string wiadomosc = string.Empty;
                    wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: 1%OP: PONOW% ";
                    data       = Encoding.ASCII.GetBytes(wiadomosc);
                    client.Send(data, data.Length);

                    wiadomosc = string.Empty;
                    ZC        = DateTime.Now;
                    wiadomosc = "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: 0%ST: BRAK%";
                    data      = Encoding.ASCII.GetBytes(wiadomosc);
                    client.Send(data, data.Length);
                    wiadomosc = string.Empty;

                    Op.operacje(client, ip, data, ID);
                }
                else if (odp == "0")
                {
                    string wiadomosc = string.Empty;
                    ZC         = DateTime.Now;
                    wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: 1%OP: KONIEC%";
                    data       = Encoding.ASCII.GetBytes(wiadomosc);
                    client.Send(data, data.Length);

                    wiadomosc = string.Empty;
                    ZC        = DateTime.Now;
                    wiadomosc = "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: 0%ST: BRAK%";
                    data      = Encoding.ASCII.GetBytes(wiadomosc);
                    client.Send(data, data.Length);
                    wiadomosc = string.Empty;
                    client.Close();
                }
                else
                {
                    Console.WriteLine("Niepoprawna odpowiedź");
                }
            } while (odp != "0");
        }
Exemplo n.º 11
0
    /// <summary>
    /// “保存”按钮单击事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_ServerClick(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            if (btnAdd.Disabled == true)
            {
                if (ZC.HasZC(txtZcbh.Value))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('已存在相同的职称编号!');</script>");
                    return;
                }
                if (ZC.HasZCMC(txtZcmc.Value))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('已存在相同的职称名称!');</script>");
                    return;
                }

                //构造user信息哈希表
                Hashtable hash = new Hashtable();
                hash.Add("zcbh", SqlStringConstructor.GetQuotedString(txtZcbh.Value.Trim()));
                hash.Add("zcmc", SqlStringConstructor.GetQuotedString(txtZcmc.Value.Trim()));
                hash.Add("zclx", SqlStringConstructor.GetQuotedString(selZclx.SelectedValue));
                hash.Add("bzgzl", Convert.ToInt32(txtBzgzl.Value.Trim()));
                Gzl.BusinessLogicLayer.ZC.Add(hash);
                txtZcbh.Value      = "";
                txtZcmc.Value      = "";
                txtBzgzl.Value     = "";
                txtZcbh.Disabled   = true;
                txtZcmc.Disabled   = true;
                txtBzgzl.Disabled  = true;
                selZclx.Enabled    = false;
                btnAdd.Disabled    = false;
                btnCancel.Disabled = true;
                btnSave.Disabled   = true;
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功');</script>");
                Query();
            }

            if (btnChag.Disabled == true)
            {
                Hashtable ht = new Hashtable();
                ht.Add("zcmc", SqlStringConstructor.GetQuotedString(txtZcmc.Value.Trim()));
                ht.Add("zclx", SqlStringConstructor.GetQuotedString(selZclx.SelectedValue));
                ht.Add("bzgzl", Convert.ToInt32(txtBzgzl.Value.Trim()));

                string where = "Where zcbh = " + SqlStringConstructor.GetQuotedString(txtZcbh.Value.Trim());
                Gzl.BusinessLogicLayer.ZC.Update(ht, where);
                txtZcbh.Value     = "";
                txtZcmc.Value     = "";
                txtBzgzl.Value    = "";
                txtZcbh.Disabled  = true;
                txtZcmc.Disabled  = true;
                txtBzgzl.Disabled = true;
                selZclx.Enabled   = false;
                btnSave.Disabled  = true;
                btnChag.Disabled  = false;
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功');</script>");
                Query();
            }
        }
    }
Exemplo n.º 12
0
        //KLIENT
        // ZC:czas%ID:0%NS:2%OP:hisid%
        // ZC:czas%ID:0%NS:1%ST:BRAK%
        // ZC:czas%ID:0%NS:0%L1:1%

        //SERWER
        // ZC:czas%ID:0%NS:0%OP:hisid%
        // ZC:czas%ID:0%NS:0%ST:OK% /  // ZC:czas%ID:0%NS:0%ST:bdost%
        // ZC:czas%ID:0%NS:0%OP:mnozenie%
        // ZC:czas%ID:0%NS:0%IDO:0%
        // ZC:czas%ID:0%NS:0%L1:2%
        // ZC:czas%ID:0%NS:0%L2:3%
        // ZC:czas%ID:0%NS:0%LW:6%
        public static void HisID(List <Wpis> Historia, int ID, UdpClient server, IPEndPoint ip)
        {
            int      NS;
            DateTime ZC;
            string   wiadomosc;

            byte[]      data;
            int         silnia = 0;
            List <Wpis> temp   = new List <Wpis>();

            foreach (var i in Historia) //odczyt historii danej sesji
            {
                if (i.ID == ID)
                {
                    temp.Add(i);
                    if (i.operacja == "silnia")
                    {
                        silnia++;
                    }
                }
            }
            NS         = (temp.Count() * 5) - silnia + 1; //obliczenie ilosci komunikatow do wyslania
            ZC         = DateTime.Now;
            wiadomosc  = string.Empty;
            wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%OP: HISID%"; //odsyłanie komunikatu sygnalizujacego przeslanie historii po id sesji
            data       = Encoding.ASCII.GetBytes(wiadomosc);
            server.Send(data, data.Length, ip);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc  = string.Empty;
            wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%ST: OK%"; //odsyłanie komunikatu ze statusem
            data       = Encoding.ASCII.GetBytes(wiadomosc);
            server.Send(data, data.Length, ip);
            wiadomosc = string.Empty;

            NS--;
            foreach (var i in temp)
            {
                ZC         = DateTime.Now;
                wiadomosc  = string.Empty;
                wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%OP: " + i.operacja + "%"; //odsyłanie komunikatu z rodzajem operacji
                data       = Encoding.ASCII.GetBytes(wiadomosc);
                server.Send(data, data.Length, ip);
                wiadomosc = string.Empty;

                NS--;

                ZC         = DateTime.Now;
                wiadomosc  = string.Empty;
                wiadomosc += "ZC:" + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%IDO: " + i.IDO + "%"; //odsyłanie komunikatu z ID operacji
                data       = Encoding.ASCII.GetBytes(wiadomosc);
                server.Send(data, data.Length, ip);
                wiadomosc = string.Empty;

                NS--;

                ZC         = DateTime.Now;
                wiadomosc  = string.Empty;
                wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%L1: " + i.liczba1 + "%"; //odsyłanie komunikatu z 1. liczba
                data       = Encoding.ASCII.GetBytes(wiadomosc);
                server.Send(data, data.Length, ip);
                wiadomosc = string.Empty;

                NS--;
                if (i.operacja != "silnia")
                {
                    ZC         = DateTime.Now;
                    wiadomosc  = string.Empty;
                    wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%L2: " + i.liczba2 + "%"; //odsyłanie komunikatu z 2. liczba
                    server.Send(data, data.Length, ip);
                    wiadomosc = string.Empty;

                    NS--;
                }
                ZC         = DateTime.Now;
                wiadomosc  = string.Empty;
                wiadomosc += "ZC: " + ZC.ToString("dd/MM/yyyy HH-mm-sstt") + "%ID: " + ID + "%NS: " + NS + "%LW: " + i.wynik + "%"; //odsyłanie komunikatu z wynikiem
                data       = Encoding.ASCII.GetBytes(wiadomosc);
                server.Send(data, data.Length, ip);
                wiadomosc = string.Empty;

                NS--;
            }
        }
Exemplo n.º 13
0
        static void Main(string[] args)                                                                         //TU JEST MAIN TU JEST MAIN TU JEST MAIN TU JEST MAIN
        {
            UdpClient client = polaczenieClient();

            if (client == new UdpClient("110.0.0.0", 2137))
            {
                return;
            }
            IPEndPoint ip = new IPEndPoint(IPAddress.Any, 11000);

            //client.Connect("127.0.0.1", 11000);
            int    n  = 0;
            int    ID = 0;
            string odp;

            byte[]     data;
            string[][] AllSplits = new string[4][];
            DateTime   ZC;

            while (true)
            {
                data = client.Receive(ref ip);

                string   dane  = Encoding.Unicode.GetString(data, 0, data.Length);
                string[] split = dane.Split(new char[] { ':', '%' });
                AllSplits[n] = split;
                Console.WriteLine(dane);
                n++;
                if (Convert.ToInt32(split[5]) <= 0)
                {
                    n = 0;

                    try
                    {
                        ID = Convert.ToInt32(split[3]);
                        ZC = DateTime.Now;
                        string temp = "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:1%OP:NadanieID%";
                        data = Encoding.Unicode.GetBytes(temp);
                        client.Send(data, data.Length);
                        temp = string.Empty;
                        ZC   = DateTime.Now;
                        temp = "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:0%ST:OK%";
                        data = Encoding.Unicode.GetBytes(temp);
                        client.Send(data, data.Length);
                    }
                    catch (Exception) { }
                    break;
                }
            }
            operacje(client, ip, data, ID);

            do
            {
                Console.WriteLine("Czy chcesz wykonać ponowne obliczenia ? (0/1)");
                odp = Console.ReadLine();
                if (odp == "1")
                {
                    ZC = DateTime.Now;
                    string wiadomosc = string.Empty;
                    wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:1%OP:PONOW%";
                    data       = Encoding.Unicode.GetBytes(wiadomosc);
                    client.Send(data, data.Length);

                    wiadomosc = string.Empty;
                    ZC        = DateTime.Now;
                    wiadomosc = "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:0%ST:BRAK%";
                    data      = Encoding.Unicode.GetBytes(wiadomosc);
                    client.Send(data, data.Length);
                    wiadomosc = string.Empty;

                    operacje(client, ip, data, ID);
                }
                else if (odp == "0")
                {
                    string wiadomosc = string.Empty;
                    ZC         = DateTime.Now;
                    wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:1%OP:KONIEC%";
                    data       = Encoding.Unicode.GetBytes(wiadomosc);
                    client.Send(data, data.Length);

                    wiadomosc = string.Empty;
                    ZC        = DateTime.Now;
                    wiadomosc = "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:0%OST:BRAK%";
                    data      = Encoding.Unicode.GetBytes(wiadomosc);
                    client.Send(data, data.Length);
                    wiadomosc = string.Empty;
                    client.Close();
                }
                else
                {
                    Console.WriteLine("Niepoprawna odpowiedź");
                }
            } while (odp != "0");
        }
Exemplo n.º 14
0
        static void operacje(UdpClient client, IPEndPoint ip, byte[] data, int ID)
        {
            string OP, ST = string.Empty, ER = string.Empty;
            int    NS = 0, count = 0;
            double liczba1 = 0;
            double wynik = 0;
            double liczba2 = 0;
            string operacja = string.Empty, wiadomosc = string.Empty;

            string[][] AllSplits = new string[4][];
            Console.WriteLine("Podaj operację: ");
            operacja = Console.ReadLine();
            DateTime ZC;

            try
            {
                if (operacja.ToLower() == "silnia")
                {
                    Console.WriteLine("Podaj liczbę 1: ");
                    liczba1 = Convert.ToDouble(Console.ReadLine());
                    NS      = 2;
                }

                else if (operacja.ToLower() == "mnozenie" || operacja.ToLower() == "dzielenie" || operacja.ToLower() == "odejmowanie" || operacja.ToLower() == "dodawanie")
                {
                    Console.WriteLine("Podaj liczbę 1: ");
                    liczba1 = Convert.ToDouble(Console.ReadLine());

                    Console.WriteLine("Podaj liczbę 2: ");
                    liczba2 = Convert.ToDouble(Console.ReadLine());

                    NS = 3;
                }

                else
                {
                    throw new Exception("Nieznana operacja!!!");
                }
            }

            catch (Exception ex) { Console.WriteLine($"Wystąpił błąd: {ex.Message}, typ: {ex.GetType()}"); operacje(client, ip, data, ID); return; }
            ZC         = DateTime.Now;
            wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:" + NS + "%OP:" + operacja.ToLower() + "%";
            data       = Encoding.Unicode.GetBytes(wiadomosc);
            client.Send(data, data.Length);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:" + NS + "%ST:brak%";
            data       = Encoding.Unicode.GetBytes(wiadomosc);
            client.Send(data, data.Length);
            wiadomosc = string.Empty;

            NS--;
            ZC         = DateTime.Now;
            wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:" + NS + "%L1:" + liczba1 + "%";
            data       = Encoding.Unicode.GetBytes(wiadomosc);
            client.Send(data, data.Length);
            wiadomosc = string.Empty;

            NS--;

            if (NS == 0)
            {
                ZC         = DateTime.Now;
                wiadomosc += "ZC:" + ZC.ToString("HH-mm-sstt") + "%ID:" + ID + "%NS:" + NS + "%L2:" + liczba2 + "%";
                data       = Encoding.Unicode.GetBytes(wiadomosc);
                client.Send(data, data.Length);
                wiadomosc = string.Empty;
            }



            while (true)
            {
                data = client.Receive(ref ip);

                string   dane  = Encoding.Unicode.GetString(data, 0, data.Length);
                string[] split = dane.Split(new char[] { ':', '%' });
                AllSplits[count] = split;
                count++;
                Console.WriteLine(dane);
                if (Convert.ToInt32(split[5]) == 0)
                {
                    count = 0; break;
                }
            }
            foreach (string[] i in AllSplits)
            {
                if (i == null)
                {
                    break;
                }
                if (i[6] == "OP")
                {
                    OP = i[7];
                }
                else if (i[6] == "ST")
                {
                    ST = i[7];
                }
                else if (i[6] == "LW")
                {
                    wynik = Convert.ToDouble(i[7]);
                }
                else if (i[6] == "ER")
                {
                    ER = i[7];
                }
            }
            if (ST.ToLower() == "error")
            {
                Console.WriteLine("Wystapil blad {0}", ER);
            }
            else
            {
                Console.WriteLine("Wynik to: {0} ", wynik);
            }
        }