示例#1
0
 private void AddAutoRun_TSM_Click(object sender, EventArgs e)
 {
     try
     {
         if (!String.IsNullOrEmpty(value))
         {
             using (RegistryKey registryKeyStartup = Registry.CurrentUser.OpenSubKey(pathRegistryKeyStartup, true))
             {
                 registryKeyStartup.DeleteValue(applicationName, false);
             }
             value = "";
             AddAutoRun_TSM.Text = "Добавить в автозагрузку";
         }
         else
         {
             using (RegistryKey registryKeyStartup = Registry.CurrentUser.OpenSubKey(pathRegistryKeyStartup, true))
             {
                 registryKeyStartup.SetValue(applicationName, Application.ExecutablePath);
             }
             value = "Decode";
             AddAutoRun_TSM.Text = "Удалить из автозагрузки";
         }
     }
     catch (Exception E)
     {
         MessageBox.Show("Не удалось изменить параметры автозагрузки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         SystemArgs.PrintLog(E.ToString());
     }
 }
示例#2
0
 private void AppendToTB(String Text)
 {
     Status_TB.Invoke((MethodInvoker) delegate()
     {
         Status_TB.AppendText(Text + Environment.NewLine);
         SystemArgs.PrintLog(Text);
     });
 }
示例#3
0
 private void Closing(object sender, FormClosingEventArgs e)
 {
     notifyIcon1.BalloonTipIcon  = ToolTipIcon.Info;
     notifyIcon1.BalloonTipText  = "Нажмите, чтобы отобразить окно";
     notifyIcon1.BalloonTipTitle = "Подсказка";
     notifyIcon1.ShowBalloonTip(12);
     this.WindowState   = FormWindowState.Minimized;
     this.ShowInTaskbar = false;
     e.Cancel           = true;
     SystemArgs.PrintLog("Сервер свернут в трей");
 }
示例#4
0
        public bool CreateTempDirectory()
        {
            try
            {
                String Dir = SystemArgs.Path.TempFile;

                if (!Directory.Exists(Dir))
                {
                    Directory.CreateDirectory(Dir);
                }

                return(true);
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.Message);
                return(false);
            }
        }
示例#5
0
 private void Decode_F_Load(object sender, EventArgs e)
 {
     try
     {
         SystemArgs.Decode = new Decode();
         SystemArgs.Path   = new PathProgramm();
         SystemArgs.Server = new Server();
         if (SystemArgs.Server.GetParametersConnect())
         {
             if (SystemArgs.Server.Start())
             {
                 SystemArgs.Server.Load += AppendToTB;
                 SystemArgs.PrintLog(Directory.GetCurrentDirectory());
                 using (RegistryKey registryKeyStartup = Registry.CurrentUser.OpenSubKey(pathRegistryKeyStartup, true))
                 {
                     value = (String)registryKeyStartup.GetValue("Decode");
                 }
                 if (!String.IsNullOrEmpty(value))
                 {
                     AddAutoRun_TSM.Text = "Удалить из автозагрузки";
                 }
             }
             else
             {
                 MessageBox.Show("Сервер не был запущен", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 SystemArgs.PrintLog("Ошибка запуска сервера");
                 Environment.Exit(0);
             }
         }
         else
         {
             MessageBox.Show("Не удалось прочитать данные для запуска сервера", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             SystemArgs.PrintLog("Не удалось прочитать данные для запуска сервера");
         }
     }
     catch (Exception E)
     {
         MessageBox.Show(E.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         SystemArgs.PrintLog(E.ToString());
     }
 }
示例#6
0
        public bool GetParametersConnect()
        {
            try
            {
                if (!File.Exists(SystemArgs.Path.ConnectApplicationPath))
                {
                    throw new Exception();
                }

                using (StreamReader sr = new StreamReader(File.Open(SystemArgs.Path.ConnectApplicationPath, FileMode.Open)))
                {
                    _Port = sr.ReadLine();
                }

                return(true);
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.Message);
                return(false);
            }
        }
示例#7
0
        private void OK_B_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(IP_TB.Text))
                {
                    IP_TB.Focus();
                    throw new Exception("Необходимо ввести IP - адрес");
                }

                if (String.IsNullOrEmpty(Port_TB.Text))
                {
                    Port_TB.Focus();
                    throw new Exception("Необходимо ввести порт");
                }
                Int32 Port = Convert.ToInt32(Port_TB.Text);

                SystemArgs.Server._Port = Port_TB.Text.Trim();

                if (SystemArgs.Server.SetParametersConnect())
                {
                    SystemArgs.PrintLog("Обновлены параметры сервера порт: " + SystemArgs.Server._Port + " " + DateTime.Now.ToString());
                    MessageBox.Show("Параметры подключения успешно обновлены", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (FormatException)
            {
                Port_TB.Focus();
                MessageBox.Show("Порт подключения должен состоять из целых цифр", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            catch (Exception E)
            {
                SystemArgs.PrintLog(E.Message);
                MessageBox.Show(E.Message, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#8
0
 public bool Start()
 {
     try
     {
         if (CreateTempDirectory())
         {
             listener = new TcpListener(IPAddress.Any, Convert.ToInt32(SystemArgs.Server._Port));
             listener.Start();
             ListeningAsync();
             SystemArgs.PrintLog("Запущено слушание клиентов и найдена директория темповых файлов");
             return(true);
         }
         else
         {
             SystemArgs.PrintLog("Ошибка создания директории темповых файлов");
             return(false);
         }
     }
     catch (Exception e)
     {
         SystemArgs.PrintLog(e.Message);
         return(false);
     }
 }
示例#9
0
        public bool SetParametersConnect()
        {
            try
            {
                String Dir = SystemArgs.Path.GetDirectory(SystemArgs.Path.ConnectApplicationPath);

                if (!Directory.Exists(Dir))
                {
                    Directory.CreateDirectory(Dir);
                }

                using (StreamWriter sw = new StreamWriter(File.Open(SystemArgs.Path.ConnectApplicationPath, FileMode.Create)))
                {
                    sw.WriteLine(_Port);
                }

                return(true);
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.Message);
                return(false);
            }
        }
示例#10
0
        public String TIFF(string path)
        {
            try
            {
                using (Reader reader = new Reader())
                {
                    reader.BarcodeTypesToFind.DataMatrix = true;
                    Image  myImage = Image.FromFile(path);
                    Bitmap source  = new Bitmap(myImage);
                    myImage.Dispose();

                    int imgw = 0;
                    int imgh = 0;

                    string cash = null;

                    for (int i = 250; i < source.Width; i = i + 20)
                    {
                        for (int j = 300; j < source.Height; j = j + 20)
                        {
                            imgw = i; imgh = j;

                            Bitmap bmp = source.Clone(new System.Drawing.Rectangle(source.Width - imgw, source.Height - imgh, 250, 300), source.PixelFormat);

                            FoundBarcode[] barcodes = reader.ReadFrom(bmp);

                            foreach (FoundBarcode code in barcodes)
                            {
                                if (code.Value.Split('_').Length == 6)
                                {
                                    cash = code.Value;
                                }
                            }

                            if (cash != null)
                            {
                                var fromEncodind = Encoding.GetEncoding("ISO-8859-1"); //из какой кодировки
                                var bytes        = fromEncodind.GetBytes(cash);
                                var toEncoding   = Encoding.GetEncoding(1251);         //в какую кодировку

                                cash = toEncoding.GetString(bytes);

                                while (cash.IndexOf("<FNC1>") != -1)
                                {
                                    cash = cash.Replace("<FNC1>", "и");
                                }

                                cash = cash.Remove(cash.IndexOf('>'), cash.IndexOf('<') - cash.IndexOf('>') + 1);

                                String[] ExistingCharaterEnglish = new String[] { "A", "a", "B", "C", "c", "E", "e", "H", "K", "M", "O", "o", "P", "p", "T" };

                                String[] ExistingCharaterRussia = new String[] { "А", "а", "В", "С", "с", "Е", "е", "Н", "К", "М", "О", "о", "Р", "р", "Т" };

                                String[] Temp = cash.Split('_');

                                String ReplaceMark = "";

                                for (int k = 0; k < ExistingCharaterRussia.Length; k++)
                                {
                                    ReplaceMark = Temp[2].Replace(ExistingCharaterRussia[k], ExistingCharaterEnglish[k]);
                                }

                                String[] Splitter = Temp[1].Split('и');

                                while (Splitter[0][0] == '0')
                                {
                                    Splitter[0] = Splitter[0].Remove(0, 1);
                                }

                                if (Splitter.Length != 1)
                                {
                                    Temp[1] = Splitter[0] + "и" + Splitter[1];
                                }
                                else
                                {
                                    Temp[1] = Splitter[0];
                                }

                                cash = Temp[0] + "_" + Temp[1] + "_" + ReplaceMark + "_" + Temp[3] + "_" + Temp[4] + "_" + Temp[5];

                                source.Dispose();
                                bmp.Dispose();

                                return(cash);
                            }
                            bmp.Dispose();
                        }
                    }
                    source.Dispose();
                    cash = "Не правильно";
                    return(cash);
                }
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.ToString());
                return(e.Message);
            }
        }
示例#11
0
        private void Listening()
        {
            try
            {
                while (true)
                {
                    String    User   = "";
                    TcpClient client = listener.AcceptTcpClient();
                    using (NetworkStream inputStream = client.GetStream())
                    {
                        using (BinaryReader reader = new BinaryReader(inputStream))
                        {
                            if (reader.ReadBoolean())
                            {
                                Load?.Invoke("Была проведена проверка соединения пользователем " + reader.ReadString());
                                client.Close();
                                continue;
                            }
                            else
                            {
                                User = reader.ReadString();
                                Load?.Invoke("Был присоединен пользователь " + User);
                            }
                            string OldFilename = reader.ReadString();
                            string FileName    = reader.ReadString();
                            long   lenght      = reader.ReadInt64();
                            using (FileStream outputStream = File.Open(Path.Combine(SystemArgs.Path.TempFile, Index + ".png"), FileMode.Create))
                            {
                                long   totalBytes = 0;
                                int    readBytes  = 0;
                                byte[] buffer     = new byte[8192];

                                do
                                {
                                    readBytes = inputStream.Read(buffer, 0, buffer.Length);
                                    outputStream.Write(buffer, 0, readBytes);
                                    totalBytes += readBytes;
                                } while (client.Connected && totalBytes < lenght);
                                Load?.Invoke("Был получен файл: " + OldFilename);
                            }
                            String Data         = SystemArgs.Decode.TIFF(SystemArgs.Path.TempFile + @"\" + Index + ".png");
                            Byte[] responseData = Encoding.UTF8.GetBytes(Data);
                            inputStream.Write(responseData, 0, responseData.Length);
                            Load?.Invoke("Были отправлены данные: " + Data);
                            Index++;
                        }
                    }
                    client.Close();
                    DirectoryInfo TempFiles = new DirectoryInfo(SystemArgs.Path.TempFile);
                    if (TempFiles.GetFiles().Length >= 50)
                    {
                        foreach (FileInfo File in TempFiles.GetFiles())
                        {
                            File.Delete();
                        }
                    }
                    Load?.Invoke("Был отключен пользователь " + User);
                }
            }
            catch (Exception e)
            {
                SystemArgs.PrintLog(e.Message);
                ListeningAsync();
            }
        }
示例#12
0
 private void notifyIcon1_Click(object sender, EventArgs e)
 {
     this.ShowInTaskbar = true;
     this.WindowState   = FormWindowState.Normal;
     SystemArgs.PrintLog("Сервер развернут из трея");
 }
示例#13
0
 private void Exit_TSM_Click(object sender, EventArgs e)
 {
     SystemArgs.PrintLog("Закрытие сервера");
     Environment.Exit(0);
 }