Пример #1
0
        bool SaveCSV(string fileName, StringBuilder data)
        {
            if (fileName == string.Empty || (data == null || data.Length == 0))
            {
                return(false);
            }

            //var fp = new FileProcess();
            bool bCreate = FileProcess.CreateFolder(folderPath);

            //fp = null;

            if (bCreate == false)
            {
                TRMessageBox.Show(string.Format("Create CSV folder failed({0})", folderPath));
                return(false);
            }

            string filePath = string.Format("{0}\\{1}", folderPath, fileName);
            var    file     = new StreamWriter(filePath, true);

            try
            {
                file.Write(data.ToString());
                file.Flush();
                file.Close();
            }
            catch (Exception ee)
            {
                Log4.PrinterLogger.InfoFormat(ee.ToString());
                return(false);
            }

            return(true);
        }
Пример #2
0
        void ExecuteDeleteLane()
        {
            Log4.PrinterLogger.Info("[A]Press Delete button.");

            if (LaneContainer.Count > 0)
            {
                RemoveOneLaneSetting();

                if (LaneContainer.Count == 1)
                {
                    PrinterManager.getInstance().EnableLane2SettingUI(false);
                }
                else
                if (LaneContainer.Count == 0)
                {
                    PrinterManager.getInstance().EnableLane1SettingUI(false);
                    PrinterManager.getInstance().EnableLane2SettingUI(false);
                }
            }
            else
            {
                Log4.PrinterLogger.Info("[A]There is no data.");
                TRMessageBox.Show("@THERE_IS_NO_DATA".Translate(), "@PRINTER_CENTER".Translate());
            }
        }
Пример #3
0
        void ExecuteAddLane()
        {
            Log4.PrinterLogger.Info("[A]Press Add button.");

            if (LaneContainer.Count < 2)
            {
                AddOneLaneSetting();

                if (LaneContainer.Count == 1)
                {
                    PrinterManager.getInstance().EnableLane1SettingUI(true);
                }
                else
                if (LaneContainer.Count == 2)
                {
                    PrinterManager.getInstance().EnableLane1SettingUI(true);
                    PrinterManager.getInstance().EnableLane2SettingUI(true);
                }
            }
            else
            {
                Log4.PrinterLogger.Info("[A]upport at most 2 lane.");
                TRMessageBox.Show("@SUPPORT_AT_MOST_2_LANE".Translate(), "@PRINTER_CENTER".Translate());
            }
        }
Пример #4
0
        public PrinterWindow()
        {
            MultiLanguageHelper.SettingLanguageFromRegisty();
            InitializeComponent();

            NetworkDriveViewModel ndvm = (NetworkDriveViewModel)ucNetworkDrive.DataContext;

            ndvm.NetworkDriveMappingChangedEvent += new NetworkDriveMappingChangedHandler(NetworkDrive_Changed);

            OneLaneSelectorVM.VendorChangedEvent += new VendorChangedHandler(Vendor_Changed);

            using (var ini = new IniFile())
            {
                bool PrinterClosing = Boolean.TryParse(ini.Read("Printer", "ClosingPrompt"), out IsClosingPrompt);
                bool bAlreadyExist  = IsProcessAlreadyExist("PrinterCenter");               //PrinterCenter
                if (bAlreadyExist)
                {
                    MessageBoxResult ret = TRMessageBox.Show(this,
                                                             "@SERVICE_OPENED".Translate(),
                                                             "@PRINTER_CENTER".Translate(),
                                                             MessageBoxButton.OK,
                                                             MessageBoxImage.Stop);
                    if (ret == MessageBoxResult.OK)
                    {
                        IsClosingPrompt = false;
                        System.Windows.Application.Current.Shutdown();
                    }
                }
                BindingClosing = ini.Read("Printer", "BindingClosing");
            }

            //Auto Load Settings
            if (System.IO.File.Exists("PrinterCenter.xml"))
            {
                Log4.PrinterLogger.InfoFormat("*AutoLoading \"PrinterCenter.xml\" ...");
                ViewModelLocator.Atom.PrinterWindowVM.LoadSettingFromXml("PrinterCenter.xml");
                if (ViewModelLocator.Atom.PrinterWindowVM.ExamineData())
                {
                    ViewModelLocator.Atom.PrinterWindowVM.ExecuteOpenService();
                }
                else
                {
                    ViewModelLocator.Atom.PrinterWindowVM.IsAutoLoadFile = true;

                    Log4.PrinterLogger.InfoFormat("Examining Fail ...");
                }
                ViewModelLocator.Atom.PrinterWindowVM.stcSelectedIndex = 6;
            }
        }
Пример #5
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (IsProcessExist(BindingClosing))             //表示ini有設定bindingClose的app
            {
                e.Cancel = true;
            }

            if (IsClosingPrompt)
            {
                MessageBoxResult ret = TRMessageBox.Show(this,
                                                         "@ARE_YOU_SURE_TO_CLOSE_WINDOW".Translate(),
                                                         "@CONFIRM".Translate(),
                                                         MessageBoxButton.YesNo,
                                                         MessageBoxImage.Question);
                if (ret == MessageBoxResult.No)
                {
                    e.Cancel = true;
                }
            }

            if (!e.Cancel)
            {
                App.Current.Shutdown();
            }

            //if (IsClosingPrompt)
            //{
            //    MessageBoxResult ret = TRMessageBox.Show(this,
            //            "@ARE_YOU_SURE_TO_CLOSE_WINDOW".Translate(),
            //            "@CONFIRM".Translate(),
            //            MessageBoxButton.YesNo,
            //            MessageBoxImage.Question);
            //    if (ret == MessageBoxResult.No)
            //        e.Cancel = true;
            //}
            //if (IsProcessExist(BindingClosing))//表示ini有設定bindingClose的app
            //    e.Cancel = true;
            //else
            //    App.Current.Shutdown();

            Log4.PrinterLogger.InfoFormat(" ================== Closing ================== ");
        }
Пример #6
0
        public static void UnMappingNetDrive(string netDrive)
        {
            NetworkDrive oNetDrive = new NetworkDrive();

            try
            {
                //unmap the drive
                oNetDrive.Force      = true;
                oNetDrive.LocalDrive = netDrive;
                oNetDrive.UnMapDrive();
                //update status
            }
            catch (Exception err)
            {
                //report error

                TRMessageBox.Show("Cannot unmap drive!\nError: " + err.Message);
            }
            oNetDrive = null;
        }
Пример #7
0
        static public bool CreateFile(string fullPath)
        {
            FileStream fs = null;

            try
            {
                fs = System.IO.File.Create(fullPath);
            }
            catch (Exception e)
            {
                TRMessageBox.Show(e.ToString());
            }
            if (fs != null)
            {
                fs.Close();
                fs.Dispose();
                return(true);
            }
            return(false);
        }
Пример #8
0
        public override bool Run(bool bAppend = false)
        {
            if (string.IsNullOrEmpty(FilePath))
            {
                return(false);
            }
            if (StrList == null || StrList.Count < 1)
            {
                return(false);
            }

            StreamWriter streamWriter = null;

            try
            {
                streamWriter = new StreamWriter(FilePath, bAppend);
                for (int i = 0; i < StrList.Count; i++)
                {
                    streamWriter.WriteLine(StrList[i]);
                }
            }
            catch (Exception ex)
            {
                TRMessageBox.Show(
                    ex.Message,
                    "PrinterCenter",
                    System.Windows.MessageBoxButton.OK,
                    System.Windows.MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Flush();
                    streamWriter.Close();
                    streamWriter.Dispose();
                }
            }
            return(true);
        }
Пример #9
0
        public MPMPrinter(eAssignedLane_Printer lane) : base(ePrinterVendor.MPM, lane)
        {
            string errStr  = "";
            string section = String.Format("MPM_{0}", lane.ToString());

            //ulong inspectedLow = (ulong)((DateTime.Now.AddHours(-8) - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds);//Test
            //取得RPC參數
            using (IniFile ini = new IniFile())
            {
                _RPCPara.SideIP           = ini.Read(section, "SideIP");
                _RPCPara.SidePort         = ini.Read(section, "SidePort");
                _RPCPara.SideComputerName = ini.Read(section, "SideComputerName");

                _RPCPara.RPCServerPort = ini.Read(section, "RPCServerPort");

                var path = ini.Read(section, "WorkingPath");
                if (!String.IsNullOrEmpty(path))
                {
                    Log4.PrinterLogger.InfoFormat("Override WorkingPath ={0}", path);
                    _RPCPara.WorkingPath = path;
                }
                if (lane == eAssignedLane_Printer.Lane2)
                {
                    _RPCPara.ClientDualLaneEanbled = "1";
                }
                else
                {
                    _RPCPara.ClientDualLaneEanbled = "0";
                }
                bool bShow;
                Boolean.TryParse(ini.Read(section, "bShowRPCWindow"), out bShow);
                _RPCPara.bShowRPCWindow = bShow;
            }


            _IsConnect = Connect(ref errStr);
            if (!_IsConnect)
            {
                TRMessageBox.Show("請確認MPM RPC連線");
            }
        }
Пример #10
0
        /// <summary>
        /// Mappings the net drive.
        /// </summary>
        public static void MappingNetDrive(string netDrive, string shareFolder, string userName, string password)
        {
            NetworkDrive oNetDrive = new NetworkDrive();

            try
            {
                //set propertys
                oNetDrive.Force                = false;
                oNetDrive.Persistent           = true;//要永久的,不然下次開機會不見
                oNetDrive.LocalDrive           = netDrive;
                oNetDrive.PromptForCredentials = false;
                oNetDrive.ShareName            = shareFolder;
                oNetDrive.SaveCredentials      = false;
                //match call to options provided
                if (password == "" && userName == "")
                {
                    oNetDrive.MapDrive();
                }
                else if (userName == "")
                {
                    oNetDrive.MapDrive(userName);
                }
                else
                {
                    oNetDrive.MapDrive(userName, password);
                }
                //update status
                //System.Threading.Thread.Sleep(1000);
                // Process.Start("explorer.exe", netDrive + @":\");
                //ExecuteAsAdmin("explorer.exe", netDrive + @":\"); //顯示不出來
                //Process.Start("explorer.exe");
            }
            catch (Exception err)
            {
                //report error

                TRMessageBox.Show("Cannot map drive!\nError: " + err.Message);
            }
            oNetDrive = null;
        }
Пример #11
0
        public static bool Ping(string strIP)
        {
            IPAddress ip = null;

            if (IPAddress.TryParse(strIP, out ip) == false)
            {
                return(false);
            }

            try
            {
                if (new Ping().Send(ip, 500).Status == IPStatus.Success)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                TRMessageBox.Show(ex.Message);
            }
            return(false);
        }
Пример #12
0
        void ExecuteSaveFile()
        {
            List <OneLaneSelectorVM> _lstOneLaneModel = new List <OneLaneSelectorVM>();

            foreach (var item in ViewModelLocator.Atom.LaneSelectorHostVM.LaneContainer)
            {
                _lstOneLaneModel.Add((OneLaneSelectorVM)(item as ucOneLaneSelector).DataContext);
            }

            TRMessageBox.Show("@AUTOLOADFILENAME_HINT".Translate());
            System.Windows.Forms.SaveFileDialog ofd = new System.Windows.Forms.SaveFileDialog();
            ofd.Filter = "Xml Files (*.xml)| *.xml";

            //string pathName = "PlacerCenter.xml";
            ofd.Filter = "Xml Files (*.xml)| *.xml";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    XElement              root          = new XElement("PRINTERCENTER");
                    CommonSettingVM       lane1CommonVM = (CommonSettingVM)_window.ucLane1_Common.DataContext;
                    SharedFolderSettingVM lane1SFVM     = (SharedFolderSettingVM)_window.ucLane1_SF.DataContext;
                    CommonSettingVM       lane2CommonVM = (CommonSettingVM)_window.ucLane2_Common.DataContext;
                    SharedFolderSettingVM lane2SFVM     = (SharedFolderSettingVM)_window.ucLane2_SF.DataContext;



                    List <XElement> LaneList = new List <XElement>();

                    foreach (var lane in _lstOneLaneModel)
                    {
                        var iLaneID = _lstOneLaneModel.IndexOf(lane) + 1;
                        var sVendor = lane.Vendor;
                        if (iLaneID == 1)
                        {
                            var el = new XElement("LANE", new XAttribute("ID", iLaneID)
                                                  , new XElement("Vendor", sVendor)
                                                  , lane1CommonVM.ToXml()
                                                  , lane1SFVM.ToXml()
                                                  );
                            LaneList.Add(el);
                        }
                        else if (iLaneID == 2)
                        {
                            var el = new XElement("LANE", new XAttribute("ID", iLaneID)
                                                  , new XElement("Vendor", sVendor)
                                                  , lane2CommonVM.ToXml()
                                                  , lane2SFVM.ToXml()
                                                  );
                            LaneList.Add(el);
                        }
                    }

                    root.Add(LaneList);


                    root.Save(ofd.FileName);
                }
                catch (Exception ex)
                {
                    Log4.PrinterLogger.ErrorFormat("Exception={0}", ex.Message);
                    return;
                }
            }
        }