Esempio n. 1
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);
        }
Esempio n. 2
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);
     }
 }