Ejemplo n.º 1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     this.tmrUsb.Stop();
     try
     {
         this.btnSave.Enabled = false;
         this.lblUsbHint.Text = formMain.ML.GetStr("USB_SavingData");
         Thread.Sleep(500);
         this.lblUsbHint.ForeColor = System.Drawing.Color.Black;
         if (this.cboUsb.SelectedIndex == -1)
         {
             MessageBox.Show(this, formMain.ML.GetStr("Prompt_NoFlashDisk"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
         }
         else
         {
             this.panel.ButtonFunctionType = (LedButtonFunctionType)this.cboOption.SelectedIndex;
             base.Enabled = false;
             ProcessUSB processUSB = new ProcessUSB();
             processUSB.PanelBytes          = this.panel.ToLBytes();
             processUSB.ButtonFunctionBytes = this.panel.ToButtonFunctionBytes();
             processUSB.ProtocolVersion     = (byte)this.panel.GetProtocolType();
             protocol_data_integration protocol_data_integration = new protocol_data_integration();
             byte[] array = protocol_data_integration.WritingData_USB_Pack(processUSB, false, true);
             if (array == null)
             {
                 base.Enabled = true;
                 this.lblUsbHint.ForeColor = System.Drawing.Color.Red;
                 this.lblUsbHint.Text      = formMain.ML.GetStr("USB_Save_Failed");
                 this.btnSave.Enabled      = true;
                 Thread.Sleep(1000);
                 this.tmrUsb.Start();
                 this.LastMessage = "save";
             }
             else if (array.Length > this.panel.GetFlashCapacity())
             {
                 MessageBox.Show(this, formMain.ML.GetStr("Prompt_MemeoryOverSize"));
                 base.Enabled         = true;
                 this.btnSave.Enabled = true;
                 Thread.Sleep(1000);
                 this.tmrUsb.Start();
                 this.LastMessage = "save";
             }
             else
             {
                 int i = 10;
                 while (i > 0)
                 {
                     try
                     {
                         i--;
                         FileStream fileStream = new FileStream(this.UsbDeviceList[this.cboUsb.SelectedIndex] + "ledV3.zh3", FileMode.Create, FileAccess.Write);
                         fileStream.Write(array, 0, array.Length);
                         fileStream.Close();
                         break;
                     }
                     catch (Exception ex)
                     {
                         if (i == 0)
                         {
                             this.btnSave.Enabled      = true;
                             this.lblUsbHint.ForeColor = System.Drawing.Color.Red;
                             this.lblUsbHint.Text      = formMain.ML.GetStr("USB_Save_Failed") + "(" + ex.Message + ")";
                             base.Enabled = true;
                             Thread.Sleep(1000);
                             this.tmrUsb.Start();
                             this.LastMessage = "save";
                             return;
                         }
                         Thread.Sleep(200);
                     }
                 }
                 Thread.Sleep(500);
                 if (!File.Exists(this.UsbDeviceList[this.cboUsb.SelectedIndex] + "\\ledV3.zh3"))
                 {
                     MessageBox.Show(this, formMain.ML.GetStr("Prompt_DataDownloadFailed"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
                 }
                 this.lblUsbHint.ForeColor = System.Drawing.Color.Blue;
                 this.lblUsbHint.Text      = formMain.ML.GetStr("USB_Save_Success");
                 this.btnSave.Enabled      = true;
                 base.Enabled = true;
                 Thread.Sleep(1000);
                 this.tmrUsb.Start();
                 this.LastMessage = "save";
             }
         }
     }
     catch (Exception ex2)
     {
         this.btnSave.Enabled      = true;
         this.lblUsbHint.ForeColor = System.Drawing.Color.Red;
         this.lblUsbHint.Text      = formMain.ML.GetStr("USB_Save_Failed") + "(" + ex2.Message + ")";
         base.Enabled = true;
         Thread.Sleep(1000);
         this.tmrUsb.Start();
         this.LastMessage = "save";
     }
 }
Ejemplo n.º 2
0
        private void btnCloudServerSave_Click(object sender, EventArgs e)
        {
            this.tmrUsb.Stop();
            string text = this.txtCloudServerUserName.Text;

            if (string.IsNullOrEmpty(text))
            {
                MessageBox.Show(this, formMain.ML.GetStr("Message_CloudServer_UserName_Cannot_Be_Empty"));
                this.txtCloudServerUserName.Focus();
                this.tmrUsb.Start();
                return;
            }
            if (Encoding.Default.GetByteCount(text) > 30)
            {
                MessageBox.Show(this, formMain.ML.GetStr("Message_CloudServer_UserName_Cannot_Be_More_Than_30_Characters"));
                this.txtCloudServerUserName.Focus();
                this.tmrUsb.Start();
                return;
            }
            bool flag = true;

            for (int i = 0; i < text.Length; i++)
            {
                int num = (int)text[i];
                if (num > 127 || num < 8 || (num > 8 && num < 21))
                {
                    flag = false;
                    break;
                }
            }
            if (!flag)
            {
                MessageBox.Show(this, formMain.ML.GetStr("Message_CloudServer_UserName_Can_Only_Support_Alphabet_Numbers_And_Special_Characters"));
                this.txtCloudServerUserName.Focus();
                this.tmrUsb.Start();
                return;
            }
            string text2 = this.txtAPN.Text;

            if (this.chkAPN.Checked)
            {
                if (string.IsNullOrEmpty(text2))
                {
                    MessageBox.Show(this, formMain.ML.GetStr("Message_APN_Cannot_Be_Empty"));
                    this.txtAPN.Focus();
                    this.tmrUsb.Start();
                    return;
                }
                if (Encoding.Default.GetByteCount(text2) > 31)
                {
                    MessageBox.Show(this, formMain.ML.GetStr("Message_APN_Cannot_Be_More_Than_31_Characters"));
                    this.txtAPN.Focus();
                    this.tmrUsb.Start();
                    return;
                }
                bool flag2 = true;
                for (int j = 0; j < text2.Length; j++)
                {
                    int num2 = (int)text2[j];
                    if (num2 > 122 || num2 < 46 || (num2 > 46 && num2 < 48) || (num2 > 57 && num2 < 65) || (num2 > 90 && num2 < 97))
                    {
                        break;
                    }
                }
                if (!flag2)
                {
                    MessageBox.Show(this, formMain.ML.GetStr("Message_APN_Can_Only_Support_Alphabet_And_Decimal"));
                    this.txtAPN.Focus();
                    this.tmrUsb.Start();
                    return;
                }
            }
            try
            {
                this.btnCloudServerSave.Enabled = false;
                this.lblUsbHint.Text            = formMain.ML.GetStr("USB_SavingData");
                Thread.Sleep(500);
                this.lblUsbHint.ForeColor = System.Drawing.Color.Black;
                if (this.cboUsb.SelectedIndex == -1)
                {
                    MessageBox.Show(this, formMain.ML.GetStr("Prompt_NoFlashDisk"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
                    this.tmrUsb.Start();
                }
                else
                {
                    LedCardCommunication ledCardCommunication = new LedCardCommunication();
                    ledCardCommunication.CloudServerMode          = LedCloudServerMode.Enabled;
                    ledCardCommunication.CloudServerUserName      = text;
                    ledCardCommunication.CloudServerHeartbeatTime = 0;
                    if (this.chkAPN.Checked)
                    {
                        ledCardCommunication.GPRSAPN = text2;
                    }
                    base.Enabled = false;
                    LedCommunicationSetting ledCommunicationSetting = LedCommunicationSetting.CloudServer;
                    if (this.chkAPN.Checked)
                    {
                        ledCommunicationSetting |= LedCommunicationSetting.GPRSAPN;
                    }
                    ProcessUSB processUSB = new ProcessUSB();
                    processUSB.PanelBytes = this.panel.ToLBytes();
                    processUSB.CloudServerUserNameBytes = ledCardCommunication.ToCloudServerUserNameBytes();
                    processUSB.CommunicationBytes       = ledCardCommunication.ToCommunicationBytes(ledCommunicationSetting);
                    processUSB.ProtocolVersion          = (byte)this.panel.GetProtocolType();
                    protocol_data_integration protocol_data_integration = new protocol_data_integration();
                    byte[] array = protocol_data_integration.WritingData_USB_Pack(processUSB, false, false);
                    if (array == null)
                    {
                        base.Enabled = true;
                        this.lblUsbHint.ForeColor       = System.Drawing.Color.Red;
                        this.lblUsbHint.Text            = formMain.ML.GetStr("USB_Save_Failed");
                        this.btnCloudServerSave.Enabled = true;
                        Thread.Sleep(1000);
                        this.tmrUsb.Start();
                        this.LastMessage = "save";
                    }
                    else if (array.Length > this.panel.GetFlashCapacity())
                    {
                        MessageBox.Show(this, formMain.ML.GetStr("Prompt_MemeoryOverSize"));
                        base.Enabled = true;
                        this.btnCloudServerSave.Enabled = true;
                        Thread.Sleep(1000);
                        this.tmrUsb.Start();
                        this.LastMessage = "save";
                    }
                    else
                    {
                        int k = 10;
                        while (k > 0)
                        {
                            try
                            {
                                k--;
                                FileStream fileStream = new FileStream(this.UsbDeviceList[this.cboUsb.SelectedIndex] + "ledV3.zh3", FileMode.Create, FileAccess.Write);
                                fileStream.Write(array, 0, array.Length);
                                fileStream.Close();
                                break;
                            }
                            catch (Exception ex)
                            {
                                if (k == 0)
                                {
                                    this.btnCloudServerSave.Enabled = true;
                                    this.lblUsbHint.ForeColor       = System.Drawing.Color.Red;
                                    this.lblUsbHint.Text            = formMain.ML.GetStr("USB_Save_Failed") + "(" + ex.Message + ")";
                                    base.Enabled = true;
                                    Thread.Sleep(1000);
                                    this.tmrUsb.Start();
                                    this.LastMessage = "save";
                                    return;
                                }
                                Thread.Sleep(200);
                            }
                        }
                        Thread.Sleep(500);
                        if (!File.Exists(this.UsbDeviceList[this.cboUsb.SelectedIndex] + "\\ledV3.zh3"))
                        {
                            MessageBox.Show(this, formMain.ML.GetStr("Prompt_DataDownloadFailed"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
                        }
                        this.lblUsbHint.ForeColor       = System.Drawing.Color.Blue;
                        this.lblUsbHint.Text            = formMain.ML.GetStr("USB_Save_Success");
                        this.btnCloudServerSave.Enabled = true;
                        this.panel.CloudServerMode      = LedCloudServerMode.Enabled;
                        this.panel.CloudServerUserName  = ledCardCommunication.CloudServerUserName;
                        if (this.chkAPN.Checked)
                        {
                            this.panel.GPRSAPN = ledCardCommunication.GPRSAPN;
                        }
                        this.isModified = false;
                        base.Enabled    = true;
                        Thread.Sleep(1000);
                        this.tmrUsb.Start();
                        this.LastMessage = "save";
                    }
                }
            }
            catch (Exception ex2)
            {
                this.btnCloudServerSave.Enabled = true;
                this.lblUsbHint.ForeColor       = System.Drawing.Color.Red;
                this.lblUsbHint.Text            = formMain.ML.GetStr("USB_Save_Failed") + "(" + ex2.Message + ")";
                base.Enabled = true;
                Thread.Sleep(1000);
                this.tmrUsb.Start();
                this.LastMessage = "save";
            }
        }
Ejemplo n.º 3
0
 private void UsbSaveButton_Click(object sender, EventArgs e)
 {
     this.timer1.Stop();
     try
     {
         this.UsbSaveButton.Enabled = false;
         this.label_Remind.Text     = formMain.ML.GetStr("USB_SavingData");
         Thread.Sleep(500);
         this.label_Remind.ForeColor = System.Drawing.Color.Black;
         this.WarningLevel           = 0;
         if (this.UsbListComboBox.SelectedIndex == -1)
         {
             MessageBox.Show(this, formMain.ML.GetStr("Prompt_NoFlashDisk"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
         }
         else
         {
             base.Enabled = false;
             ProcessUSB processUSB = new ProcessUSB();
             if (this.panel.IsLSeries())
             {
                 processUSB.PanelBytes       = this.panel.ToLBytes();
                 processUSB.ItemStartLBytes  = this.panel.ToItemStartLBytes();
                 processUSB.ItemLBytes       = this.panel.ToItemLBytes();
                 processUSB.ItemTimerLBytes  = this.panel.ToItemTimerLByte();
                 processUSB.TimerSwitchBytes = this.panel.TimerSwitch.ToLBytes();
                 processUSB.LuminanceBytes   = this.panel.Luminance.ToLBytes();
             }
             else
             {
                 processUSB.PanelBytes       = this.panel.ToBytes();
                 processUSB.BmpDataBytes     = this.panel.ToItemBmpDataBytes();
                 processUSB.ItemBytes        = this.panel.ToItemBytes();
                 processUSB.TimerSwitchBytes = this.panel.TimerSwitch.ToBytes();
                 processUSB.LuminanceBytes   = this.panel.Luminance.ToBytes();
             }
             processUSB.ProtocolVersion = (byte)this.panel.GetProtocolType();
             if (this.TimingCheckBox.Checked)
             {
                 processUSB.SetTimingBytes(this.TimingDateTimePicker.Value);
             }
             protocol_data_integration protocol_data_integration = new protocol_data_integration();
             byte[] array = protocol_data_integration.WritingData_USB_Pack(processUSB, false, false);
             if (array == null)
             {
                 this.UsbDataMessagePrompt("USB_Save_Failed", 2, System.Drawing.Color.Red);
             }
             else if (array.Length > this.panel.GetFlashCapacity())
             {
                 this.UsbDataMessagePrompt("Prompt_MemeoryOverSize", 2, System.Drawing.Color.Red);
             }
             else
             {
                 int i = 10;
                 while (i > 0)
                 {
                     try
                     {
                         i--;
                         FileStream fileStream = new FileStream(this.UdiskDirList[this.UsbListComboBox.SelectedIndex] + "ledV3.zh3", FileMode.Create, FileAccess.Write);
                         DriveInfo  driveInfo  = new DriveInfo(this.UdiskDirList[this.UsbListComboBox.SelectedIndex]);
                         if ((long)array.Length > driveInfo.TotalFreeSpace)
                         {
                             fileStream.Close();
                             this.UsbDataMessagePrompt("formUSBWrite_Message_FileOverUsbSize", 2, System.Drawing.Color.Red);
                             return;
                         }
                         fileStream.Write(array, 0, array.Length);
                         fileStream.Close();
                         break;
                     }
                     catch
                     {
                         if (i == 0)
                         {
                             this.UsbDataMessagePrompt("USB_Save_Failed", 2, System.Drawing.Color.Red);
                             return;
                         }
                         Thread.Sleep(200);
                     }
                 }
                 Thread.Sleep(500);
                 if (!File.Exists(this.UdiskDirList[this.UsbListComboBox.SelectedIndex] + "\\ledV3.zh3"))
                 {
                     MessageBox.Show(this, formMain.ML.GetStr("Prompt_DataDownloadFailed"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
                 }
                 this.UsbDataMessagePrompt("USB_Save_Success", 3, System.Drawing.Color.Blue);
             }
         }
     }
     catch
     {
         this.UsbDataMessagePrompt("USB_Save_Failed", 2, System.Drawing.Color.Red);
     }
 }
Ejemplo n.º 4
0
        public bool SaveForeignTradeModeData()
        {
            bool result;

            try
            {
                ProcessUSB processUSB = new ProcessUSB();
                processUSB.ItemStartLBytes  = this.panel.ToItemStartLBytes();
                processUSB.ItemLBytes       = this.panel.ToItemLBytes();
                processUSB.ItemTimerLBytes  = this.panel.ToItemTimerLByte();
                processUSB.TimerSwitchBytes = this.panel.TimerSwitch.ToLBytes();
                processUSB.LuminanceBytes   = this.panel.Luminance.ToLBytes();
                processUSB.ProtocolVersion  = 52;
                if (this.TimingCheckBox.Checked)
                {
                    processUSB.SetTimingBytes(this.TimingDateTimePicker.Value);
                }
                protocol_data_integration protocol_data_integration = new protocol_data_integration();
                byte[] array = protocol_data_integration.WritingData_USB_Pack(processUSB, false, true);
                processUSB.TimerSwitchBytes = null;
                processUSB.LuminanceBytes   = null;
                processUSB.PanelBytes       = this.panel.ToBytes();
                processUSB.BmpDataBytes     = this.panel.ToItemBmpDataBytes();
                processUSB.ItemBytes        = this.panel.ToItemBytes();
                processUSB.TimerSwitchBytes = this.panel.TimerSwitch.ToBytes();
                processUSB.LuminanceBytes   = this.panel.Luminance.ToBytes();
                processUSB.ProtocolVersion  = 49;
                byte[] array2 = protocol_data_integration.WritingData_USB_Pack(processUSB, false, false);
                if (array2 == null || array == null)
                {
                    this.UsbDataMessagePrompt("USB_Save_Failed", 2, System.Drawing.Color.Red);
                    result = false;
                }
                else if (array2.Length > this.panel.GetFlashCapacity() || array.Length > this.panel.GetFlashCapacity())
                {
                    this.UsbDataMessagePrompt("Prompt_MemeoryOverSize", 2, System.Drawing.Color.Red);
                    result = false;
                }
                else
                {
                    string str = this.UdiskDirList[this.UsbListComboBox.SelectedIndex];
                    Dictionary <string, byte[]> dictionary = new Dictionary <string, byte[]>();
                    Directory.CreateDirectory(str + "ZH_LED\\ZH-5WX");
                    Directory.CreateDirectory(str + "ZH_LED\\ZH-XXL");
                    string key  = str + "ZH_LED\\ZH-5WX\\led_data.zh";
                    string key2 = str + "ZH_LED\\ZH-XXL\\led_data.zh";
                    dictionary.Add(key, array2);
                    dictionary.Add(key2, array);
                    foreach (string current in dictionary.Keys)
                    {
                        int i = 10;
                        while (i > 0)
                        {
                            try
                            {
                                i--;
                                FileStream fileStream = new FileStream(current, FileMode.Create, FileAccess.Write);
                                DriveInfo  driveInfo  = new DriveInfo(this.UdiskDirList[this.UsbListComboBox.SelectedIndex]);
                                if ((long)dictionary[current].Length > driveInfo.TotalFreeSpace)
                                {
                                    fileStream.Close();
                                    this.UsbDataMessagePrompt("formUSBWrite_Message_FileOverUsbSize", 2, System.Drawing.Color.Red);
                                    result = false;
                                    return(result);
                                }
                                fileStream.Write(dictionary[current], 0, dictionary[current].Length);
                                fileStream.Close();
                                break;
                            }
                            catch
                            {
                                if (i == 0)
                                {
                                    this.UsbDataMessagePrompt("USB_Save_Failed", 2, System.Drawing.Color.Red);
                                    result = false;
                                    return(result);
                                }
                                Thread.Sleep(200);
                            }
                        }
                    }
                    Thread.Sleep(500);
                    foreach (string current2 in dictionary.Keys)
                    {
                        if (!File.Exists(current2))
                        {
                            MessageBox.Show(this, formMain.ML.GetStr("Prompt_DataDownloadFailed"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
                            result = false;
                            return(result);
                        }
                    }
                    this.UsbDataMessagePrompt("USB_Save_Success", 3, System.Drawing.Color.Blue);
                    result = true;
                }
            }
            catch
            {
                this.UsbDataMessagePrompt("USB_Save_Failed", 2, System.Drawing.Color.Red);
                result = false;
            }
            return(result);
        }
Ejemplo n.º 5
0
 private void UsbSaveButton_Click(object sender, EventArgs e)
 {
     this.timer1.Stop();
     try
     {
         this.UsbSaveButton.Enabled = false;
         this.label_Remind.Text     = formMain.ML.GetStr("USB_SavingData");
         Thread.Sleep(500);
         this.label_Remind.ForeColor = System.Drawing.Color.Black;
         if (this.UsbListComboBox.SelectedIndex == -1)
         {
             MessageBox.Show(this, formMain.ML.GetStr("Prompt_NoFlashDisk"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
         }
         else
         {
             LedTimeSequence ledTimeSequence = new LedTimeSequence();
             ledTimeSequence.CKCPHA          = (byte)this.nudCKCPHA.Value;
             ledTimeSequence.CKCDC           = (byte)this.nudCKCDC.Value;
             ledTimeSequence.LTDelay         = (int)this.nudLTDelay.Value;
             this.panel.TimeSequence.CKCPHA  = ledTimeSequence.CKCPHA;
             this.panel.TimeSequence.CKCDC   = ledTimeSequence.CKCDC;
             this.panel.TimeSequence.LTDelay = ledTimeSequence.LTDelay;
             this.panel.TimeSequence.Changed = true;
             base.Enabled = false;
             ProcessUSB processUSB = new ProcessUSB();
             processUSB.PanelBytes        = this.panel.ToLBytes();
             processUSB.TimeSequenceBytes = this.panel.TimeSequence.ToBytes();
             processUSB.ProtocolVersion   = this.panel.ProtocolVersion;
             protocol_data_integration protocol_data_integration = new protocol_data_integration();
             byte[] array = protocol_data_integration.WritingData_USB_Pack(processUSB, true, false);
             if (array == null)
             {
                 base.Enabled = true;
                 this.label_Remind.ForeColor = System.Drawing.Color.Red;
                 this.label_Remind.Text      = formMain.ML.GetStr("USB_Save_Failed");
                 this.UsbSaveButton.Enabled  = true;
                 Thread.Sleep(1000);
                 this.timer1.Start();
                 this.LastMessage = "save";
             }
             else if (array.Length > this.panel.GetFlashCapacity())
             {
                 MessageBox.Show(this, formMain.ML.GetStr("Prompt_MemeoryOverSize"));
                 base.Enabled = true;
                 this.UsbSaveButton.Enabled = true;
                 Thread.Sleep(1000);
                 this.timer1.Start();
                 this.LastMessage = "save";
             }
             else
             {
                 int i = 10;
                 while (i > 0)
                 {
                     try
                     {
                         i--;
                         FileStream fileStream = new FileStream(this.UdiskDirList[this.UsbListComboBox.SelectedIndex] + "ledV3.zh3", FileMode.Create, FileAccess.Write);
                         fileStream.Write(array, 0, array.Length);
                         fileStream.Close();
                         break;
                     }
                     catch (Exception ex)
                     {
                         if (i == 0)
                         {
                             this.UsbSaveButton.Enabled  = true;
                             this.label_Remind.ForeColor = System.Drawing.Color.Red;
                             this.label_Remind.Text      = formMain.ML.GetStr("USB_Save_Failed") + "(" + ex.Message + ")";
                             base.Enabled = true;
                             Thread.Sleep(1000);
                             this.timer1.Start();
                             this.LastMessage = "save";
                             return;
                         }
                         Thread.Sleep(200);
                     }
                 }
                 Thread.Sleep(500);
                 if (!File.Exists(this.UdiskDirList[this.UsbListComboBox.SelectedIndex] + "\\ledV3.zh3"))
                 {
                     MessageBox.Show(this, formMain.ML.GetStr("Prompt_DataDownloadFailed"), formMain.ML.GetStr("Display_Prompt"), MessageBoxButtons.OK);
                 }
                 this.label_Remind.ForeColor = System.Drawing.Color.Blue;
                 this.label_Remind.Text      = formMain.ML.GetStr("USB_Save_Success");
                 this.UsbSaveButton.Enabled  = true;
                 base.Enabled = true;
                 Thread.Sleep(1000);
                 this.timer1.Start();
                 this.LastMessage = "save";
             }
         }
     }
     catch (Exception ex2)
     {
         this.UsbSaveButton.Enabled  = true;
         this.label_Remind.ForeColor = System.Drawing.Color.Red;
         this.label_Remind.Text      = formMain.ML.GetStr("USB_Save_Failed") + "(" + ex2.Message + ")";
         base.Enabled = true;
         Thread.Sleep(1000);
         this.timer1.Start();
         this.LastMessage = "save";
     }
 }