You are on page 1of 25

/******************************************************************************** ********************************************* * PROGRAM - QALM (Quality Assurance Lens Manager) * Requires SQL compact database and SQL server

* Path C:\QALM\APP * Path C:\QALM\Dbase * FileName : QAmanager.exe * DBfilename: qalmDB.sdf * * Program stores used to organize and store lens for QA department. * * ***************************************************************************** **************************************************/ using using using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Threading; System.Data.SqlClient;

namespace QALManager { public partial class QALMForm : Form { //bool flags for various functions bool FindSelected = false; bool FindOldSelected = false; bool bool bool bool bool bool AddLens = true; refreshEnabled = false; NoLocationsAvilable = false; UpdateSelectedItem = true; AddVisiableRowsOneTime = true; ModifyEnable = false; EOAserverNameString = "Server=eoascg2;"; EOAendString = "Initial Catalog=AssistedControl;Persist Security ID=as; Password =as;"; EOAconnectionString = "" ;

string string Info=True;User string

//bool flag for graphics bool SphereImage = false; bool CylinderImage = false; //keep track of selected rows int SelectedRowIndexGlobal = 0; // incoming serial data string RxString; string[] StoreRXstring; //job tray number string TrayNumberGlobal; bool OpenSerialStartUpbool = true;

public QALMForm() { InitializeComponent(); } private void lenStoreBindingNavigatorSaveItem_Click(object sender, Event Args e) { // // // // } /************************************ form load ******************************** ****************************************** * * Form load is used thru out the program to refresh the table adaptors * Resets error providers * Updates the date displayed on the screen * * ***************************************************************************** *****************************************/ private void Form1_Load(object sender, EventArgs e) { string ComPort; int BaudRate; // fill or refresh table adaptors this.locationTableAdapter.Fill(this.qalmDBDataSet.Location); this.lenStoreTableAdapter.Fill(this.qalmDBDataSet.LenStore); this.sphereTableAdapter.Fill(this.qalmDBDataSet.Sphere); this.cylinderTableAdapter.Fill(this.qalmDBDataSet.Cylinder); this.addTableAdapter.Fill(this.qalmDBDataSet.Add); this.styleTableAdapter.Fill(this.qalmDBDataSet.Style); this.materialTableAdapter.Fill(this.qalmDBDataSet.Material); this.utilityTableAdapter.Fill(this.qalmDBDataSet.Utility); // retrive the com port and baud rate from the database ComPort = utilityDataGridView[0, 0].Value.ToString(); BaudRate = int.Parse(utilityDataGridView[0, 1].Value.ToString()); //retrive the server and update the connection string EOAserverNameString = utilityDataGridView[0, 2].Value.ToString(); EOAconnectionString = "Server=" + EOAserverNameString + ";" + EOA endString; if (OpenSerialStartUpbool) { serialPort1.PortName = ComPort; serialPort1.BaudRate = BaudRate; serialPort1.Open(); disable nav sav -NO saves from nav bar this.Validate(); this.lenStoreBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.qalmDBDataSet);

if (serialPort1.IsOpen) { OpenSerialStartUpbool = false; } } //Check hidden radio buttons invisible at run time UnknownRadioButton.Checked = true; //reset find button after refresh if(!ModifyEnable) Findbutton1.Enabled = true; //reset error providers DropDownerrorProvider.SetError(CylindercomboBox, ""); DropDownerrorProvider.SetError(SpherecomboBox, ""); //check for unused locations make sure there locations available . string LocNum = checkAvailableLoations(); createDISPLAYGrid(); //reset bool flags FindSelected = false; FindOldSelected = false; refreshEnabled = false;

MessageBox.Show("Check DB or DB Server", "No DB access (Form_Loa d)"); //update todays date Datelabel.Text = DateTime.Now.ToString("MM/dd/yy"); } /******************************************* Display used position Grid **** ************************************/ private void createDISPLAYGrid() { //Add the rows if (AddVisiableRowsOneTime) { DisplayLocationdataGridView.Rows.Add(" ", "1", "2", "3", "4", "5 ", "6", "7", "8"); DisplayLocationdataGridView.Rows.Add("A"); DisplayLocationdataGridView.Rows.Add("B"); DisplayLocationdataGridView.Rows.Add("C"); DisplayLocationdataGridView.Rows.Add("D"); DisplayLocationdataGridView.Rows.Add("E"); DisplayLocationdataGridView.Rows.Add("F");

DisplayLocationdataGridView.Rows.Add("G"); DisplayLocationdataGridView.Rows.Add("H"); DisplayLocationdataGridView.Rows.Add("I"); DisplayLocationdataGridView.Rows.Add("J"); DisplayLocationdataGridView.Rows.Add("K"); DisplayLocationdataGridView.Rows.Add("L"); DisplayLocationdataGridView.Rows.Add("M"); DisplayLocationdataGridView.Rows.Add("N"); DisplayLocationdataGridView.Rows.Add("0"); AddVisiableRowsOneTime = false; } int Countlocations = locationDataGridView.Rows.Count; int locationCounter = 1; int rowindex = 1; //Place an X in locations where ther are lens for (int Y = 0; Y < Countlocations-1; Y++) { bool verifylocation = Convert.ToBoolean(locationDataGridView[1 , Y].Value.ToString()); if (!verifylocation) DisplayLocationdataGridView[locationCounter, rowindex].Val ue = "O"; else DisplayLocationdataGridView[locationCounter, rowindex].Val ue = " "; locationCounter++; if (locationCounter == 9) { locationCounter = 1; rowindex++; } } } /****************************************************** check for available loca tions **************************** * * Returns first avialble locations * if none are available only display refresh and remove / do not display add * * ***************************************************************************** *********************************/ private string checkAvailableLoations() { bool LocAvail = false; string LocNum = "*";

int locationCounter = 0; //find out how many current rows int NumberOfLocations = locationDataGridView.Rows.Count; //decrease the counter by 1 NumberOfLocations--; //look for unused location in hidden data grid view while (!LocAvail) { //read the bit status in the locations availabe table and covert to bool LocAvail = Convert.ToBoolean(locationDataGridView[1, locationCou nter].Value.ToString()); //get the location identifier LocNum = locationDataGridView[0, locationCounter].Value.ToString (); locationCounter++; if (locationCounter >= NumberOfLocations) break; } //No more location avialable if (locationCounter == NumberOfLocations && !LocAvail ) { this.NoLocationslabel.ForeColor = Color.Red; NoLocationslabel.Text = "ALL LOCATIONS FULL"; StoreLensbutton.Text = "REFRESH"; refreshEnabled = true; NoLocationsAvilable = true; } else // Locations are available { NoLocationsAvilable = false; this.NoLocationslabel.ForeColor = Color.Black; NoLocationslabel.Text = "LOCATIONS AVAILABLE"; StoreLensbutton.Text = "STORE"; AddLens = true; } // return the first avilable location return LocNum; } /****************************************** store Lens ************************* *******************************/ private void StoreLensbutton_Click(object sender, EventArgs e) { //date time strings for index and for todays date string todaysDate = DateTime.Now.ToString("MM/dd/yy"); //String primary db key made from date time min second and fractiona l seconds string dbindex = DateTime.Now.ToString("MMddyy.HHmmss.FFFFFFF"); //value of the selected drop downs string cylinder = CylindercomboBox.SelectedValue.ToString();

string string string string

sphere = SpherecomboBox.SelectedValue.ToString(); addP = AddcomboBox.SelectedValue.ToString(); Style = StyleComboBox.SelectedValue.ToString(); LensIndex = IndexcomboBox.SelectedValue.ToString();

//set up strings string WhichLens = "*"; string plusSign = "+"; string minusSign = "-"; string TsphereString; string TcylinderString; string statuslist; //set reset bool for no update UpdateSelectedItem = false; //Only if add lens button not in refresh state if(AddLens == true && !NoLocationsAvilable) try { //check cylinder and sphere drop down if (CylindercomboBox.SelectedIndex == 0 || SpherecomboBox.Select edIndex == 0 && !ModifycheckBox.Checked ) throw new System.Exception(); try { //if no add power selected set to * if (addP == "Select") addP = WhichLens; // assing * if no material selected if (Style == "Select") Style = WhichLens; if (LensIndex == "Select") LensIndex = WhichLens; // assign a sign value to sphere number if (SpherecomboBox.SelectedIndex == 1) sphere = plusSign + sphere; else if (!SphereImage) sphere = minusSign + sphere; else sphere = plusSign + sphere; //assign a sign value to cylinder number if (CylindercomboBox.SelectedIndex == 1) cylinder = plusSign + cylinder; else if (!CylinderImage) cylinder = minusSign + cylinder; else cylinder = plusSign + cylinder; //clear error provider DropDownerrorProvider.SetError(CylindercomboBox, "") ; DropDownerrorProvider.SetError(SpherecomboBox, "");

//set right or left button if selected if (RightradioButton.Checked == true) WhichLens = "RIGHT"; if (LEFTradioButton.Checked == true) WhichLens = "LEFT"; //parse the Sphere and Cylinder numbers from drop do wns //calculate the transpostion values for both decimal Tsphere = decimal.Parse(sphere) + decimal.Pa rse(cylinder); decimal Tcylinder = decimal.Parse(cylinder) * -1; //check for minus if positive number add + to the st ring value for search and display purposes if (Tsphere < 0) TsphereString = Tsphere.ToString(); else TsphereString = plusSign + Tsphere.ToString(); //check for minus if positive number add + to the st ring value if (Tcylinder < 0) TcylinderString = Tcylinder.ToString(); else TcylinderString = plusSign + Tcylinder.ToString( ); if (!ModifycheckBox.Checked) { //retrns the next available location string LocNum = checkAvailableLoations(); //update location status this.locationTableAdapter.UpdateLocationStatus(f alse, LocNum); //insert new line in lenstore table this.lenStoreTableAdapter.StoreNewLens(dbindex, todaysDate, cylinder, sphere, addP, LocNum, WhichLens, TcylinderString, TsphereS tring, Style, LensIndex); //Change location lable to display for user BigLocationlabel.Text = LocNum; //set font color and change message this.LocNamelabel.ForeColor = Color.Blue; LocNamelabel.Text = "PLACE IN POSITION"; BigLocationlabel.Visible = true; LocNamelabel.Visible = true; //update status box statuslist = "---> ADD Location --->" + " [" + L ocNum + "] " + sphere + " " + cylinder + " " + addP + " " + todaysDate; //refresh table adaptors Form1_Load(sender, e); //reset flags and graphics SphereImage = true;

CylinderImage = true; //call method to reset graphic buttons SphereSignbutton_Click(sender, e); CylinderSignbutton_Click(sender, e); } else { string DBprimaryKey = lenStoreDataGridView[10, S electedRowIndexGlobal].Value.ToString(); this.lenStoreTableAdapter.UpdateLensData(cylinde r, sphere, addP, WhichLens, TcylinderString, TsphereString, LensIndex, Style, DB primaryKey); lenStoreDataGridView[1, SelectedRowIndexGlobal]. Value = sphere; lenStoreDataGridView[2, SelectedRowIndexGlobal]. Value = cylinder; lenStoreDataGridView[3, SelectedRowIndexGlobal]. Value = addP; lenStoreDataGridView[4, SelectedRowIndexGlobal]. Value = LensIndex; lenStoreDataGridView[5, SelectedRowIndexGlobal]. Value = Style; lenStoreDataGridView[6, SelectedRowIndexGlobal]. Value = WhichLens; //Change location lable to display for user BigLocationlabel.Text = lenStoreDataGridView[7, SelectedRowIndexGlobal].Value.ToString(); //set font color and change message this.LocNamelabel.ForeColor = Color.Green; LocNamelabel.Text = "PARAMTERS MODIFIED"; BigLocationlabel.Visible = true; LocNamelabel.Visible = true; statuslist = "<---> MODIFY Location <--->" + " [ " + lenStoreDataGridView[7, SelectedRowIndexGlobal].Value.ToString() +"] " + sph ere + " " + cylinder + " " + addP + " " + todaysDate; UpdateSelectedItem = true; } //update status panel StatuslistBox.Items.Insert(0,statuslist); //Clear old status messages removeOldStatus(); } catch { StatuslistBox.Items.Insert(0,"UPDATE FAILED STORE LE NS BUTTON");

MessageBox.Show("FAILED TO UPDATE DATABASE", "STORE LENS BUTTON"); } } catch { //set error provider if any one of 2 boxs are not select ed if(SpherecomboBox.SelectedIndex == 0) DropDownerrorProvider.SetError(SpherecomboBox, "PLEASE S ELECT"); if(CylindercomboBox.SelectedIndex ==0) DropDownerrorProvider.SetError(CylindercomboBox, "PLEASE SELECT"); } //refresh table adapotrs and return button to correct text StoreLensbutton.Text = "STORE"; //refresh or no locations are available if (refreshEnabled || NoLocationsAvilable) { Form1_Load(sender, e); //set bool flags so both image set back to minus signs SphereImage = true; CylinderImage = true; //call method to reset graphic buttons SphereSignbutton_Click(sender, e); CylinderSignbutton_Click(sender, e); AutoTrayNumberlabel.Text = string.Empty; AutoSpherelabel.Text = string.Empty; AutoCylinderlabel.Text = string.Empty; AutoADDPlabel.Text = string.Empty; AutoAxislabel.Text = string.Empty; AutoIndexlabel.Text = string.Empty; AutoStylelabel.Text = string.Empty; } } /************************************** remove lens entry ************* *******************************/ private void Removebutton_Click(object sender, EventArgs e) { string statuslist; //get the location to update from the selected row string updatelocation = lenStoreDataGridView[7, SelectedRowIndexGlob al].Value.ToString(); if (!ModifycheckBox.Checked)

{ if (indexLabel1.Text != "DONOTDELETE") { DialogResult YesOrNo = new DialogResult(); YesOrNo = MessageBox.Show("OK To Remove Location >>> " + upd atelocation + " <<<", "REQUEST to REMOVE LOCATION", MessageBoxButtons.YesNo, Mes sageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (YesOrNo == DialogResult.Yes) { //update the display label BigLocationlabel.Text = updatelocation; //set bool for one time no update UpdateSelectedItem = false; try { //update and remove query this.locationTableAdapter.UpdateLocationStatus(true, updatelocation); //uses hidden index lable to update this.lenStoreTableAdapter.RemoveLensQuery(indexLabel 1.Text); //change the font color and text for user message ne xt to biglocation label this.LocNamelabel.ForeColor = Color.Red; LocNamelabel.Text = "REMOVE LOCATION"; //update status box formated text statuslist = "<--- REMOVE LOCATION <--- [" + BigLoca tionlabel.Text + "]"; //update status panel StatuslistBox.Items.Insert(0, statuslist); //Clear old status messages removeOldStatus(); } catch { //DB update failed StatuslistBox.Items.Insert(0, "!!!~ FAILED TO REMOVE LENS ~!!!"); MessageBox.Show("FAILED TO REMOVE LENS RECORD", "REM OVE BUTTON"); } } } //refresh table adaptors depending on which query is being used. if (FindSelected) findLensToolStripButton_Click(sender, e);

else if (FindOldSelected) findOldToolStripButton_Click(sender, e); else if (!ModifyEnable) Form1_Load(sender, e); } else //reroute method StoreLensbutton_Click(sender, e); } /********************************************* find lens ********************* ******************** * used to search for lens * will not trigger unless some * * *************************************************************************** ********************/ private void findLensToolStripButton_Click(object sender, EventArgs e) { string WhichLens = "%"; //count the rows int lenstoreRowCount = lenStoreDataGridView.Rows.Count; string SearchSphere, SearchCylinder, SearchAdd, SearchIndex, SearchS tyle; //set value to start string Tcylinderstring = "*"; string Tspherestring = "*"; string SphereSign; string CylinderSign; //set up sphere sign if (!SphereImage && SpherecomboBox.SelectedIndex != 1) SphereSign = "-"; else SphereSign = "+"; //set up cylinder sign if (!CylinderImage && CylindercomboBox.SelectedIndex != 1) CylinderSign = "-"; else CylinderSign = "+"; try { FindSelected = true; //set left or right lens to search if (LEFTradioButton.Checked == true) WhichLens = "LEFT"; if (RightradioButton.Checked == true) WhichLens = "RIGHT"; if (UnknownRadioButton.Checked == true && CylindercomboBox.S electedIndex == 0 && SpherecomboBox.SelectedIndex == 0 && StyleComboBox.Selected Index == 0 && AddcomboBox.SelectedIndex == 0) WhichLens = "*";

//copy cylinder for search if (CylindercomboBox.SelectedIndex != 0) { SearchCylinder = CylinderSign + CylindercomboBox.Selecte dValue.ToString(); // cylinderToolStripTextBox.Text = CylinderSign + Cylinde rcomboBox.SelectedValue.ToString(); Tcylinderstring = SearchCylinder; } else SearchCylinder = "%"; //copy sphere for search if (SpherecomboBox.SelectedIndex != 0) { SearchSphere = SphereSign + SpherecomboBox.SelectedValue .ToString(); Tspherestring = SearchSphere; } else SearchSphere = "%"; //search for index type if(IndexcomboBox.SelectedIndex != 0) SearchIndex = IndexcomboBox.SelectedValue.ToString(); else SearchIndex = "%"; //copy material for search if (StyleComboBox.SelectedIndex != 0) SearchStyle = StyleComboBox.SelectedValue.ToString(); else SearchStyle = "%"; //copy add for search if (AddcomboBox.SelectedIndex != 0) SearchAdd = AddcomboBox.SelectedValue.ToString(); else SearchAdd = "%";

//set store button text to refresh and do not allow add lens function StoreLensbutton.Text = "REFRESH"; refreshEnabled = true; AddLens = false; //query for specifed lens uses hidden query bar for some of the values other values are directly assigned //this.lenStoreTableAdapter.FindLens(this.qalmDBDataSet.LenS tore, cylinderToolStripTextBox.Text, sphereToolStripTextBox.Text, materialToolSt ripTextBox.Text, addpToolStripTextBox.Text, WhichLens, Tcylinderstring, Tspheres tring); this.lenStoreTableAdapter.FindLens(this.qalmDBDataSet.LenSto re, SearchCylinder, SearchSphere, SearchAdd, WhichLens, SearchStyle,SearchIndex, Tcylinderstring, Tspherestring);

}//try catch { MessageBox.Show("FAILD TO SEARCH", "FIND LENS TOOL STRIP"); }//catch } /******************************* find old lens button click ******************** ******************************** * Finds old lens entries * * ***************************************************************************** ******************************/ private void findOldToolStripButton_Click(object sender, EventArgs e) { //set the bool flag for find old FindOldSelected = true; //disable the find button until find old is complete Findbutton1.Enabled = false; try { //get todays date dateToolStripTextBox.Text = DateTime.Now.ToString("MM/dd/yy"); //query looks for dates older than the system date this.lenStoreTableAdapter.FindOld(this.qalmDBDataSet.LenStore, d ateToolStripTextBox.Text); //set refresh state StoreLensbutton.Text = "REFRESH"; refreshEnabled = true; AddLens = false; } catch { MessageBox.Show("FAILD TO FIND", "FIND OLD TOOLSTRIP"); } } /***************************************** REMOVE OLD STATUS LINES ************* ************************ * * removes the last line of the status list box * * ***************************************************************************** *************************/ private void removeOldStatus() { //count the items int Titems = StatuslistBox.Items.Count;

//if equal to 5 then delete the last one if (Titems == 5) StatuslistBox.Items.RemoveAt(4); } /******************************************* lens store data grid view ********* ************************* * * method triggers on user moving the around in the data grid view * * * ***************************************************************************** ***********************/ private void lenStoreDataGridView_RowEnter(object sender, DataGridViewCe llEventArgs e) { //get the selected row and asign to class level variable SelectedRowIndexGlobal = e.RowIndex; if (lenStoreDataGridView[7, SelectedRowIndexGlobal].Value.ToString() == "A-0") { lenStoreDataGridView[7, SelectedRowIndexGlobal].Value = "*"; if (FindSelected || FindOldSelected ) { UpdateSelectedItem = true; } } //allows for the big location label not to update for event followin g an add or remove event if (UpdateSelectedItem) { //updated big blue location label and change the selected locati on label to black BigLocationlabel.Text = lenStoreDataGridView[7, SelectedRowIndex Global].Value.ToString(); this.LocNamelabel.ForeColor = Color.Black;

if (BigLocationlabel.Text == "*") { Removebutton.Visible = false; BigLocationlabel.Visible = false; Removebutton.Visible = false; LocNamelabel.Visible = false; } else { if (!ModifyEnable) { LocNamelabel.Text = "SELECTED LOCATION"; Removebutton.Text = "REMOVE " + BigLocationlabel.Text;

} else { LocNamelabel.Text = "SELECTED LOCATION"; Removebutton.Text = "UPDATE " + BigLocationlabel.Text; } Removebutton.Visible = true; BigLocationlabel.Visible = true; Removebutton.Visible = true; LocNamelabel.Visible = true; } } if (!UpdateSelectedItem) Removebutton.Visible = false; //Reset update bit UpdateSelectedItem = true; if (ModifyEnable) { ModifycheckBox_CheckedChanged(sender, e); }

} /******************** Cylinder sign ************************************ ******** * * * * Update image on button click***************************************** *********/ private void CylinderSignbutton_Click(object sender, EventArgs e) { if (!CylinderImage) { this.CylinderSignbutton.BackgroundImage = ((System.Drawing.Image )(Properties.Resources.Bplus1)); CylinderImage = true; } else { this.CylinderSignbutton.BackgroundImage = ((System.Drawing.Image )(Properties.Resources.bminus)); CylinderImage = false; }

} /******************** Sphere sign ************************************** ******

* * * * Update image on button click***************************************** *********/ private void SphereSignbutton_Click(object sender, EventArgs e) { if (!SphereImage) { this.SphereSignbutton.BackgroundImage = ((System.Drawing.Image)( Properties.Resources.Bplus1)); SphereImage = true; } else { this.SphereSignbutton.BackgroundImage = ((System.Drawing.Image)( Properties.Resources.bminus)); SphereImage = false; } } /********************************* SERIAL PORT FOR Humphreys *********** ******************************* * * serail port class added to the form * * ********************************************************************* ****************************/ private void serialPort1_DataReceived(object sender, System.IO.Ports.Ser ialDataReceivedEventArgs e) { //grab the data sleep 250 ms and wait for the data to build up in th e buffer Thread.Sleep(250); //read the data RxString = serialPort1.ReadExisting(); //invoke a new thread this.Invoke(new EventHandler(processData)); } /******************************* close the serial port if program is clo sed *****************************/ private void QALMForm_FormClosing(object sender, FormClosingEventArgs e) { //close the serial port when the form is closed. if (serialPort1.IsOpen) serialPort1.Close(); } /******************************************** Process DATA **************** ************************************ * * StoreRX string array values * 15 = Right or left * 24 = sphere measurment * 33 = cylinder measurment plus axis

* * method is used to process the data received from the humphreys lens anal izer. * serial port data is first split up into an array * array location 15 contains the measurment data to where a left or right lens was specified * The sphere sign is first processed from location 24. After the sign is e xtracted the bool bits are set and a * call to sphere sign method is made. The cylinder sign is processed in th e same way. * The mothod call selects the appropriate on screen graphics for the add f unction. The sphere is processes as * a whole number by determining its lenght and extracting just the number. * The drop down selected is calculted by dividing the read sphere number b y .25. Since the drop down is in * 1/4 diopters the resulting number is the index number of the drop down. 1 must be added to the value since * the first value in the drop down is SELECT. The cylinder measurment has to be split again since it contains * both the cylinder and axis. The axis is not used. The full value of th e cylinder is extracted and mulitplied * by -1 if the value is negative. After this method is complete the follo wing controls will have been updated * * spheresignbutton * cylindersignbutton * spherecombobox * cylindercombox * right / left / unknown radio button * ************************************************************************ **************************************/ private void processData(object sender, EventArgs e) { string SignValue; string measurement; int measurmentlenght = 0; decimal calculatedropdownlocation; char[] charsToTrim = { '*'}; //split up the data reciev'd from the serial port StoreRXstring = RxString.Split(); //PROCESS left or right //Set the value for the lens right or left if (StoreRXstring[15] == "?RIGHT") RightradioButton.Checked = true; else if (StoreRXstring[15] == "?LEFT") LEFTradioButton.Checked = true; //PROCESS SPHERE SIGN //get the sphere sign and change the value on the screen SignValue = StoreRXstring[24].Substring(0, 1); if (SignValue == "-") SphereImage = true; else if(SignValue == "+")

SphereImage = false; SphereSignbutton_Click( sender, e); //PROCESS THE SPHERE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& && //get the cylinder sign and change the value on the screen SignValue = StoreRXstring[33].Substring(0, 1); if (SignValue == "-") CylinderImage = true; else if (SignValue == "+") CylinderImage = false; CylinderSignbutton_Click(sender, e); //Procss the Sphere measurement measurmentlenght = StoreRXstring[24].Length; measurement = StoreRXstring[24].Substring(1, measurmentlenght-1); //divide out number steps calculatedropdownlocation = decimal.Parse(measurement); calculatedropdownlocation = calculatedropdownlocation / .25m; //select the index calculation SpherecomboBox.SelectedIndex = (int)calculatedropdownlocation + 1; //PROCESS THE CYLINDER &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& && //trim the string of the axis measurment string[] trimmedString = StoreRXstring[33].Split(charsToTrim); //calculate the postion in the drop down calculatedropdownlocation = decimal.Parse(trimmedString[0]); calculatedropdownlocation = calculatedropdownlocation / .25m; //convert to Positive number if (calculatedropdownlocation < 0) calculatedropdownlocation = calculatedropdownlocation * -1; //select the correct cylinder CylindercomboBox.SelectedIndex = (int)calculatedropdownlocation + 1; //put the focus on the storebutton this.StoreLensbutton.Focus();

} /****************************** Assisted Controls Access *************** *********************************************/ // MUST SET UP ODBC connection to eoascg2 prior to use private void AssitedControlsAccess(object sender, EventArgs e) { string SphereString;

string string string string string

CylinderString; AxisString; AddPowerstring; IndexString; StyleString;

using (SqlConnection EOAconnection = new SqlConnection(EOAconnec tionString)) { EOAconnection.Open(); SqlCommand Mycommand = new SqlCommand("spGetRx", EOAconnecti on); Mycommand.CommandType = CommandType.StoredProcedure; //input paramter SqlParameter trayNumber = Mycommand.Parameters.Add("@orderNu mber", SqlDbType.VarChar, 8); trayNumber.Value = TrayNumberGlobal; //output parameter SqlParameter Sphere = Mycommand.Parameters.Add("@Sphere", Sq lDbType.VarChar, 5); Sphere.Direction = ParameterDirection.Output; SqlParameter Cylinder = Mycommand.Parameters.Add("@Cylinder" , SqlDbType.VarChar, 5); Cylinder.Direction = ParameterDirection.Output; SqlParameter Axis = Mycommand.Parameters.Add("@Axis", SqlDbT ype.VarChar, 3); Axis.Direction = ParameterDirection.Output; SqlParameter AddPower = Mycommand.Parameters.Add("@Addition" , SqlDbType.VarChar, 5); AddPower.Direction = ParameterDirection.Output; SqlParameter Index = Mycommand.Parameters.Add("@Index", SqlD bType.VarChar, 5); Index.Direction = ParameterDirection.Output; SqlParameter Style = Mycommand.Parameters.Add("@Style", SqlD bType.VarChar, 4); Style.Direction = ParameterDirection.Output; SqlParameter ValidTray = Mycommand.Parameters.Add("@orderNum ber", SqlDbType.Int); ValidTray.Direction = ParameterDirection.ReturnValue; Mycommand.ExecuteNonQuery(); if ((int)ValidTray.Value == 0) { //covert all the values to strings SphereString = Sphere.Value.ToString(); CylinderString = Cylinder.Value.ToString(); AxisString = Axis.Value.ToString(); AddPowerstring = AddPower.Value.ToString(); IndexString = Index.Value.ToString();

StyleString = Style.Value.ToString(); //format the lens query values formatAutoSearchResults(SphereString, CylinderString, Ad dPowerstring, AxisString, IndexString, StyleString); //convert to number for drop down calucations decimal SphereData = decimal.Parse(SphereString); decimal CylinderData = decimal.Parse(CylinderString); //set the + - buttons on the user screen for sphere if (SphereData < 0) SphereImage = true; else SphereImage = false; //set the +- buttons on the user screen for cylinder if (CylinderData < 0) CylinderImage = true; else CylinderImage = false; //update the sign buttons SphereSignbutton_Click(sender, e); CylinderSignbutton_Click(sender, e); //convert to positive numbers if (SphereData < 0) SphereData = SphereData * -1; if (CylinderData < 0) CylinderData = CylinderData * -1; //calculate the drop location SphereData = SphereData / .25m + 1; CylinderData = CylinderData / .25m + 1; //change to correct index in drop downs SpherecomboBox.SelectedIndex = (int)SphereData; CylindercomboBox.SelectedIndex = (int)CylinderData; //find the matching add power int AddPowerIndex = AddcomboBox.FindString(AddPower.Valu e.ToString()); if (AddPowerIndex > 0) AddcomboBox.SelectedIndex = AddPowerIndex; //click the find button Findbutton1.PerformClick(); //keep cursor in auto search box ScanBox.Focus(); } //close the SQL connection EOAconnection.Close(); } }

/**************************************** FORMAT AUTO SEARCH RESULTS *** **************************************/ private void formatAutoSearchResults(string Sphere, string cylinder, str ing AddPower, string Axis, string index, string style) { decimal checkSign; //check the sign value of the sphere and adjust accordingly checkSign = decimal.Parse(Sphere); if (checkSign > 0) Sphere = "+" + Sphere; int slenght = Sphere.Length; if (checkSign == 0) Sphere = "+0.00"; else if (slenght < 5) Sphere = Sphere + "0"; //check the sign value of the cylinder and adjust accordingly checkSign = decimal.Parse(cylinder); if (checkSign > 0) cylinder = "+" + cylinder; int clenght = cylinder.Length; if (checkSign == 0) cylinder = "+0.00"; else if (slenght < 5) cylinder = cylinder + "0"; // add a + to the add power if (AddPower != "0") AddPower = "+" + AddPower; //update the text boxes AutoTrayNumberlabel.Text = TrayNumberGlobal; AutoSpherelabel.Text = Sphere; AutoCylinderlabel.Text = cylinder; AutoADDPlabel.Text = AddPower; AutoAxislabel.Text = Axis; AutoIndexlabel.Text = index; AutoStylelabel.Text = style; } /********************** SCAN BOX handler ****************************/ private void ScanBox_TextChanged(object sender, EventArgs e) { int JobNumber; int lenght; try { JobNumber = int.Parse(ScanBox.Text); lenght = ScanBox.Text.Length; if (lenght == 6) { TrayNumberGlobal = ScanBox.Text;

ScanBox.Clear(); //retrive job number AssitedControlsAccess(sender, e); AddLens = false; } } catch { ScanBox.Clear(); } } /******************************************** MODIFY CHECK BOX CHANGED ********* **************************************/ private void ModifycheckBox_CheckedChanged(object sender, EventArgs e) { string checklocationEntry = "*"; try { checklocationEntry = lenStoreDataGridView[0, SelectedRowIndexGlo bal].Value.ToString(); } catch { }//no data available to check if (ModifycheckBox.Checked) { ModifyEnable = true; Removebutton.Text = "UPDATE " + BigLocationlabel.Text; StoreLensbutton.Enabled = false; Findbutton1.Enabled = false; Oldbutton.Enabled = false; refreshEnabled = false; ;

if (ModifyEnable && checklocationEntry != "*") {

decimal sextract = decimal.Parse(lenStoreDataGridView[1, SelectedRowIndexGlobal].Value.ToString()); decimal cextract = decimal.Parse(lenStoreDataGridView[2, SelectedRowIndexGlobal].Value.ToString()); if (sextract < 0) { SphereImage = true; sextract = sextract * -1; } else

SphereImage = false; if (cextract < 0) { CylinderImage = true; cextract = cextract * -1; } else CylinderImage = false; int Sindex = SpherecomboBox.FindString(sextract.ToString()); int Cindex = CylindercomboBox.FindString(cextract.ToString() ); //call method to set graphic buttons SphereSignbutton_Click(sender, e); CylinderSignbutton_Click(sender, e); //update the selected index of the drop downs SpherecomboBox.SelectedIndex = Sindex; CylindercomboBox.SelectedIndex = Cindex; if (lenStoreDataGridView[6, SelectedRowIndexGlobal].Value.To String() == "RIGHT") RightradioButton.Checked = true; if (lenStoreDataGridView[6, SelectedRowIndexGlobal].Value.To String() == "LEFT") LEFTradioButton.Checked = true; if (lenStoreDataGridView[6, SelectedRowIndexGlobal].Value.To String() == "*") UnknownRadioButton.Checked = true; if (lenStoreDataGridView[3, SelectedRowIndexGlobal].Value.To String() != "*") { int addextract = AddcomboBox.FindString(lenStoreDataGrid View[3, SelectedRowIndexGlobal].Value.ToString()); AddcomboBox.SelectedIndex = addextract; } else AddcomboBox.SelectedIndex = 0; if (lenStoreDataGridView[4, SelectedRowIndexGlobal].Value.To String() != "*") { int indexNumber = IndexcomboBox.FindString(lenStoreDataG ridView[4, SelectedRowIndexGlobal].Value.ToString()); IndexcomboBox.SelectedIndex = indexNumber; } else IndexcomboBox.SelectedIndex = 0; if (lenStoreDataGridView[5, SelectedRowIndexGlobal].Value.To String() != "*") { int materialextract = StyleComboBox.FindString(lenStoreD ataGridView[5, SelectedRowIndexGlobal].Value.ToString()); StyleComboBox.SelectedIndex = materialextract;

} else StyleComboBox.SelectedIndex = 0; } } else { ModifyEnable = false; Form1_Load(sender, e); StoreLensbutton.Enabled = true; Findbutton1.Enabled = true; Oldbutton.Enabled = true; //call method to set graphic buttons SphereImage = true; CylinderImage = true; SphereSignbutton_Click(sender, e); CylinderSignbutton_Click(sender, e); } } /************************* LOAD DB EDIT UTILITY ************************ ******************/ private void utilityToolStripMenuItem_Click(object sender, EventArgs e) { utility myutilityform = new utility(); myutilityform.ShowDialog(); //refresh Form1_Load(sender, e); } /************************** Visual Display Grid Cell Click ************* ***********************************/ private void DisplayLocationdataGridView_CellClick(object sender, DataGr idViewCellEventArgs e) { string MyColumn = DisplayLocationdataGridView[e.ColumnIndex, 0].Valu e.ToString(); string MyRow = DisplayLocationdataGridView[0, e.RowIndex].Value.ToSt ring(); string RetreiveLocation = MyRow + "-" + MyColumn; this.lenStoreTableAdapter.LocationClick(this.qalmDBDataSet.LenStore, RetreiveLocation); if (!ModifycheckBox.Checked) {

StoreLensbutton.Text = "REFRESH"; refreshEnabled = true; } if (DisplayLocationdataGridView[e.ColumnIndex, e.RowIndex].Value.ToS tring() != "O") { Removebutton.Visible = false; BigLocationlabel.Visible = false; Removebutton.Visible = false; LocNamelabel.Visible = false; } else { Removebutton.Visible = true; BigLocationlabel.Visible = true; Removebutton.Visible = true; LocNamelabel.Visible = true; } } private void CylindercomboBox_SelectedIndexChanged(object sender, EventA rgs e) { } private void cylinderLabel_Click(object sender, EventArgs e) { }

} }