Exemplo n.º 1
0
 void le_OnlineStatusChanged(LaserEquipment sender, bool online)
 {
     if (LaserEquipmentOnlineStatusChanged != null)
     {
         LaserEquipmentOnlineStatusChanged(sender);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Delete laser equipment data from the database
 /// </summary>
 /// <param name="le"></param>
 public void DeleteLaserEquipment(LaserEquipment le)
 {
     using (SqlConnection connection = new SqlConnection(connectionData.GetConnectionString()))
     {
         connection.Open();
         SqlCommand deleteCommand = new SqlCommand(@"DELETE FROM " + TABLE_NAME + " WHERE id=@id;", connection);
         deleteCommand.Parameters.AddWithValue("@id", le.Id);
         AddParameters(le, deleteCommand);
         try
         {
             deleteCommand.ExecuteScalar();
             LaserEquipment lasertoremove = null;
             foreach (LaserEquipment l in laserEquipments)
             {
                 if (l.Id == le.Id)
                 {
                     lasertoremove = l;
                 }
             }
             if (lasertoremove != null)
             {
                 laserEquipments.Remove(lasertoremove);
             }
         }
         catch (SqlException ex)
         {
             Console.WriteLine("Sql Exception:" + ex.ToString());
         }
     }
 }
Exemplo n.º 3
0
 void le_LaserEquipmentInfoChanged(LaserEquipment laser)
 {
     if (InvokeRequired)
     {
         this.Invoke(new LaserEquipmentInfoChangedHandler(UpdateSelectedLaserInfo), laser);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Load the data from the database
 /// </summary>
 /// <returns>True if the data was loaded successfully</returns>
 /// <exception cref="FileNotFoundException"></exception>
 public bool LoadData()
 {
     this.laserEquipments = new List <LaserEquipment>();
     using (SqlConnection connection = new SqlConnection(connectionData.GetConnectionString()))
     {
         connection.Open();
         SqlCommand selectCommand = new SqlCommand(@"SELECT id,name, facility, area, ip, dsp_name, dsp_file, lens_data, mru_data, programs_data, settings_data FROM " + TABLE_NAME + " ORDER BY name ASC", connection);
         try
         {
             SqlDataReader reader = selectCommand.ExecuteReader();
             while (reader.Read())
             {
                 LaserEquipment laser = new LaserEquipment();
                 laser.Id          = reader.GetInt32(0).ToString();
                 laser.Name        = reader.GetString(1);
                 laser.PlantNumber = (int)reader.GetValue(2);
                 laser.Area        = reader.GetString(3);
                 laser.Ip          = reader.GetString(4);
                 laser.Dsp         = reader.GetString(5);
                 laser.DspFile     = reader.GetString(6);
                 laser.lensData    = (LensData)JsonConvert.DeserializeObject <LensData>(reader.GetString(7));
                 laser.mruData     = (MruData)JsonConvert.DeserializeObject <MruData>(reader.GetString(8));
                 laserEquipments.Add(laser);
             }
             reader.Close();
             connection.Close();
             loaded = true;
             return(true);
         }
         catch (SqlException)
         {
         }
     }
     return(false);
 }
Exemplo n.º 5
0
 void le_PortBusy(LaserEquipment laser)
 {
     if (InvokeRequired)
     {
         this.Invoke(new LaserEquipmentInfoChangedHandler(UpdateUIForPortBusy), laser);
     }
 }
Exemplo n.º 6
0
 private void UpdateSelectedLaserInfo(LaserEquipment laser)
 {
     statusLabel.Text       = (laser.Online) ? "Online" : "Offline";
     hardwareInfoLabel.Text = laser.Hardware;
     programsTextBox.Text   = String.Empty;
     foreach (LaserProgram program in laser.Programs)
     {
         programsTextBox.Text += program + Environment.NewLine;
     }
 }
Exemplo n.º 7
0
 private void ConnectToLaser(LaserEquipment laser)
 {
     connectButton.Enabled = false;
     connectButton.Visible = false;
     laserNameLabel.Text   = laser.Name;
     //laser.Connect();
     statusLabel.Text     = "Loading...";
     programsTextBox.Text = String.Empty;
     propertiesDataTable.laserEquipment = laser;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Updates the laser equipment information in the database
 /// </summary>
 /// <param name="laser">Laser information to be updated</param>
 public void SaveLaserSelectionData(LaserEquipment laser)
 {
     using (SqlConnection connection = new SqlConnection(connectionData.GetConnectionString()))
     {
         connection.Open();
         SqlCommand updateCommand = new SqlCommand(@"UPDATE " + TABLE_NAME + " SET name=@name, facility=@facility, area=@area, ip=@ip, dsp_name=@dsp_name, dsp_file=@dsp_file, lens_data=@lens_data, mru_data=@mru_data, programs_data=@programs_data, settings_data=@settings_data WHERE id=@id;", connection);
         updateCommand.Parameters.AddWithValue("@id", laser.Id);
         AddParameters(laser, updateCommand);
         try
         {
             updateCommand.ExecuteScalar();
         }
         catch (SqlException ex)
         {
             Console.WriteLine("Sql Exception:" + ex.ToString());
         }
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Adds a new registry with the laser equipment data information
 /// </summary>
 /// <param name="le"></param>
 public void AddLaserEquipment(LaserEquipment le)
 {
     using (SqlConnection connection = new SqlConnection(connectionData.GetConnectionString()))
     {
         connection.Open();
         SqlCommand insertCommand = new SqlCommand(@"INSERT INTO " + TABLE_NAME + " (name, facility, area, ip, dsp_name, dsp_file, lens_data, mru_data, programs_data, settings_data) output INSERTED.ID VALUES (@name, @facility, @area, @ip, @dsp_name, @dsp_file, @lens_data, @mru_data,@programs_data,@settings_data);SELECT SCOPE_IDENTITY()", connection);
         AddParameters(le, insertCommand);
         try
         {
             int newId = (int)insertCommand.ExecuteScalar();
             le.Id = newId.ToString();
             laserEquipments.Add(le);
         }
         catch (SqlException ex)
         {
             Console.WriteLine("Sql Exception:" + ex.ToString());
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Adds the parameters for the query
 /// </summary>
 /// <param name="le"></param>
 /// <param name="command"></param>
 private void AddParameters(LaserEquipment le, SqlCommand command)
 {
     try
     {
         command.Parameters.AddWithValue("@name", le.Name);
         command.Parameters.AddWithValue("@facility", le.PlantNumber);
         command.Parameters.AddWithValue("@area", le.Area);
         command.Parameters.AddWithValue("@ip", le.Ip);
         command.Parameters.AddWithValue("@dsp_name", le.Dsp);
         command.Parameters.AddWithValue("@dsp_file", le.DspFile);
         command.Parameters.AddWithValue("@lens_data", JsonConvert.SerializeObject(le.lensData));
         command.Parameters.AddWithValue("@mru_data", JsonConvert.SerializeObject(le.mruData));
         command.Parameters.AddWithValue("@programs_data", string.Empty);
         command.Parameters.AddWithValue("@settings_data", string.Empty);
     }
     catch
     {
     }
 }
Exemplo n.º 11
0
        private void addButton_Click(object sender, EventArgs e)
        {
            DialogResult   result = MessageBox.Show("Do you want to copy settings from current selected laser profile?", "Add Laser Equipment", MessageBoxButtons.YesNo);
            LaserEquipment laser  = new LaserEquipment();

            laser.Plant = (localSettingsManager.Plant == ALL_OPTION) ? String.Empty : localSettingsManager.Plant;
            laser.Area  = (localSettingsManager.Area == ALL_OPTION) ? String.Empty : localSettingsManager.Area;
            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                laser.Ip            = propertiesDataTable.laserEquipment.Ip;
                laser.Dsp           = propertiesDataTable.laserEquipment.Dsp;
                laser.DspFile       = propertiesDataTable.laserEquipment.DspFile;
                laser.Lens          = propertiesDataTable.laserEquipment.Lens;
                laser.LensAmp       = propertiesDataTable.laserEquipment.LensAmp;
                laser.XCompensation = propertiesDataTable.laserEquipment.XCompensation;
                laser.YCompensation = propertiesDataTable.laserEquipment.YCompensation;
            }
            LaserEquipmentListManager.GetInstance().AddLaserEquipment(laser);
            table.Refresh();
        }
Exemplo n.º 12
0
 /// <summary>
 /// Loads the selected row laser data
 /// </summary>
 private void loadSelectedRowInfo()
 {
     try
     {
         string         name  = this.laserEquipmentDataGridView.Rows[this.laserEquipmentDataGridView.CurrentCell.RowIndex].Cells[0].Value.ToString();
         LaserEquipment laser = null;
         foreach (LaserEquipment laserEquipment in LaserEquipmentListManager.GetInstance().LaserEquipmentList)
         {
             if (name == laserEquipment.Name)
             {
                 laser = laserEquipment;
             }
         }
         if (laser != null)
         {
             ConnectToLaser(laser);
         }
     }
     catch
     {
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Select the given laser equipment, change the registry values needed to handle this
        /// </summary>
        /// <param name="equipmentName">Name of the laser equipment</param>
        public void SelectLaserEquipment(string equipmentName)
        {
            List <LaserEquipment> list      = manager.LaserEquipmentList;
            LaserEquipment        equipment = null;

            foreach (LaserEquipment item in list)
            {
                if (item.Name == equipmentName)
                {
                    equipment = item;
                }
            }
            if (equipment != null)
            {
                //Declare objects
                RegistryKey regBase     = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
                RegistryKey globalPrefs = regBase.OpenSubKey(REGISTRY_PATH + GLOBAL_PREFS_REGISTRY_KEY, true);
                try
                {
                    regBase.CreateSubKey(REGISTRY_PATH + DSP_PARAMETERS_REGISTRY_KEY, RegistryKeyPermissionCheck.ReadWriteSubTree);
                }
                catch { }
                RegistryKey dspParam = regBase.OpenSubKey(REGISTRY_PATH + DSP_PARAMETERS_REGISTRY_KEY, true);
                try
                {
                    regBase.CreateSubKey(REGISTRY_PATH + MRU_REGISTRY_KEY, RegistryKeyPermissionCheck.ReadWriteSubTree);
                }
                catch { }
                RegistryKey mru         = regBase.OpenSubKey(REGISTRY_PATH + MRU_REGISTRY_KEY, true);
                RegistryKey fontAuto    = regBase.OpenSubKey(REGISTRY_PATH + FONT_AUTO_DOWNLOAD_REGISTRY_KEY, true);
                RegistryKey scribaKey   = regBase.OpenSubKey(REGISTRY_PATH + SCRIBA_KEY);
                RegistryKey iniFilesKey = regBase.OpenSubKey(REGISTRY_PATH + INI_FILE_LOCATION_KEY, true);
                string      installDir  = scribaKey.GetValue(INSTALL_DIR_KEY).ToString();
                string      markIniFile = iniFilesKey.GetValue(MARK_INI_FILE_KEY).ToString();

                //Close the program if open
                Process[] processes = Process.GetProcessesByName(PROCESS_NAME);
                if (processes.Count() > 0)
                {
                    processes[0].Kill();
                }

                //Copy dsp settings
                if (File.Exists(equipment.DspFile))
                {
                    string[] files = Directory.GetFiles(Path.Combine(installDir, DSP_PARAMETERS_FOLDER));
                    foreach (string file in files)
                    {
                        File.Delete(file);
                    }
                    File.Copy(equipment.DspFile, Path.Combine(installDir, DSP_PARAMETERS_FOLDER, Path.GetFileName(equipment.DspFile)), true);
                }

                //Write values in registry
                globalPrefs.SetValue(ETHERNET_IP_KEY, equipment.Ip);
                globalPrefs.SetValue(COMM_PORT_KEY, 12);
                globalPrefs.SetValue(ETHERNET_PORT_KEY, 4000);
                dspParam.SetValue(LAST_USED_KEY, equipment.Dsp);
                mru.SetValue(MRU_1_KEY, equipment.Mru1);
                mru.SetValue(MRU_2_KEY, equipment.Mru2);
                mru.SetValue(MRU_3_KEY, equipment.Mru3);
                mru.SetValue(MRU_4_KEY, equipment.Mru4);
                mru.SetValue(MRU_5_KEY, equipment.Mru5);
                mru.SetValue(MRU_6_KEY, equipment.Mru6);
                mru.SetValue(MRU_7_KEY, equipment.Mru7);
                mru.SetValue(MRU_8_KEY, equipment.Mru8);
                mru.SetValue(MRU_9_KEY, equipment.Mru9);

                //Update font autodownload settings
                List <string> fonts = FontAutoDownloadManager.GetInstance().Fonts;
                fontAuto.SetValue(NUM_FONTS_KEY, fonts.Count());
                int count = 1;
                foreach (string font in fonts)
                {
                    fontAuto.SetValue(FONT_CHECKED_KEY + count.ToString(), 1);
                    fontAuto.SetValue(FONT_TO_DOWNLOAD_KEY + count.ToString(), font);
                    count++;
                }

                //Update lens setup
                if (File.Exists(settings.MarkerIniFileSource))
                {
                    File.Copy(settings.MarkerIniFileSource, markIniFile, true);
                    MarkerIniFile iniFile = new MarkerIniFile(markIniFile);
                    iniFile.LoadLensSetups();
                    List <LensSetup> lensSetups = iniFile.LensSetups;
                    foreach (LensSetup setup in lensSetups)
                    {
                        if (setup.Name == equipment.Lens)
                        {
                            setup.LensAmplitude = float.Parse(equipment.LensAmp);
                            setup.XCompensation = float.Parse(equipment.XCompensation);
                            setup.YCompensation = float.Parse(equipment.YCompensation);
                            iniFile.SetSetupSelected(setup);
                        }
                    }
                }

                //Open program
                Process.Start(new ProcessStartInfo(Path.Combine(installDir, PROCESS_FILE)));
            }
        }
Exemplo n.º 14
0
 private void UpdateUIForPortBusy(LaserEquipment laser)
 {
     statusLabel.Text      = "Port Busy";
     connectButton.Enabled = true;
     connectButton.Visible = true;
 }