Ejemplo n.º 1
0
        //populate color, state & image lists...
        public void PopulateAesthetics(List <string> lstOriginalSample)
        {
            List <string> lstColors = new List <string>();
            List <string> lstState  = new List <string>();


            DataTable dt1 = dbo.GetTable("Compound_Data");
            DataTable dt  = dbo.GetTable("Physical_Properties");


            foreach (string s in lstOriginalSample)
            {
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    if (Convert.ToBoolean(s.Trim() == (Convert.ToString(dt1.Rows[i].ItemArray[1])).Trim()))
                    {
                        int     index = Convert.ToInt32(dt1.Rows[i].ItemArray[0]);
                        DataRow dr    = dbo.GetRecord("Physical_Properties", index);

                        lstState.Add(Convert.ToString(dr.ItemArray[1]));
                        lstColors.Add(Convert.ToString(dr.ItemArray[2]));
                        break;
                    }
                }
            }



            Sample.lst_Colors.Add(lstColors);
            Sample.lst_State.Add(lstState);

            //Populate the image list...
            MediaOperator mop = new MediaOperator(mainForm);

            Sample.lst_Images.Add(mop.GetImage(lstOriginalSample, lstState, lstColors));
        }
Ejemplo n.º 2
0
        //Fires when a reagent is added...
        private void AddReagent(string reagentName, string reagentCode)
        {
            DataTable dt1 = dbo.GetTable("Compound_Data");
            DataTable dt2 = dbo.GetDataFromChemicalCompoundsTable(reagentCode);

            string message = "";

            if (treeViewSample.SelectedNode != null)
            {
                var sampleIndex = ((CustomTreeNode)treeViewSample.SelectedNode).SampleIndex;

                var sample = Sample.lst_Samples[sampleIndex];
                //List variable that holds chosen compounds from chemical compounds datatable..
                List <string> newSample = new List <string>();

                //list variable that holds the compound IDs of new sample...
                List <int> lstCompoundIDSOfNewSample = new List <int>();

                int indexOfS = 0;

                for (int j = 0; j < sample.Count; j++)
                {
                    string s = sample.ElementAt(j);
                    bool   foundSFromTable = false;

                    for (int i = 0; i < dt1.Rows.Count; i++)
                    {
                        int    compoundID   = Convert.ToInt32(dt1.Rows[i].ItemArray[0]);
                        string compoundName = Convert.ToString(dt1.Rows[i].ItemArray[1]);
                        int    pickedCompoundIDFromTable = Convert.ToInt32(dt2.Rows[i].ItemArray[1]);
                        string pickedCompoundName        = "";



                        if (Convert.ToBoolean(compoundName.Trim() == s.Trim()))
                        {
                            if (pickedCompoundIDFromTable != 0)
                            {
                                //Add compound ID into the new compound ID list...
                                lstCompoundIDSOfNewSample.Add(pickedCompoundIDFromTable);

                                //find the name corresponding to picked compound id...
                                foreach (DataRow dr in dt1.Rows)
                                {
                                    if (Convert.ToInt32(dr.ItemArray[0]) == pickedCompoundIDFromTable)
                                    {
                                        pickedCompoundName = Convert.ToString(dr.ItemArray[1]);
                                    }
                                }

                                newSample.Add(pickedCompoundName);
                                foundSFromTable = true;
                                break;
                            }
                            else
                            {
                                //get the compound id of the current compound (s) and add it to new compound id list...
                                foreach (DataRow dr in dt1.Rows)
                                {
                                    if (Convert.ToBoolean(Convert.ToString(dr.ItemArray[1]) == s.Trim()))
                                    {
                                        lstCompoundIDSOfNewSample.Add(Convert.ToInt32(dr.ItemArray[0]));
                                    }
                                }

                                newSample.Add(s);
                                foundSFromTable = true;
                            }
                        }
                    }

                    if (foundSFromTable == false)
                    {
                        newSample.Add(s);
                    }

                    indexOfS += 1;
                }

                Sample.lst_Samples[sampleIndex] = newSample;

                if (reagentCode.Contains("Op_"))
                {
                    message += reagentName + " was performed on the " + treeViewSample.SelectedNode.Text + "...!  ";
                }
                else
                {
                    message += reagentName + " was added to the " + treeViewSample.SelectedNode.Text + "...!  ";
                }
                //determine color and state of the new compounds..

                DataTable dt3 = dbo.GetTable("Physical_Properties");


                var colorOfEachSpecies = Sample.lst_Colors.ElementAt(sampleIndex);
                var stateOfEachSpecies = Sample.lst_State.ElementAt(sampleIndex);

                List <string> newColorOfEachSpecies = new List <string>();
                List <string> newStateOfEachSpecies = new List <string>();

                indexOfS = 0;

                foreach (int sID in lstCompoundIDSOfNewSample)
                {
                    for (int i = 0; i < dt3.Rows.Count; i++)
                    {
                        if (Convert.ToBoolean(sID == Convert.ToInt32(dt3.Rows[i].ItemArray[0])))
                        {
                            newColorOfEachSpecies.Add((string)dt3.Rows[i].ItemArray[2]);

                            newStateOfEachSpecies.Add((string)dt3.Rows[i].ItemArray[1]);

                            break;
                        }
                    }

                    indexOfS += 1;
                }

                Sample.lst_Colors[sampleIndex] = newColorOfEachSpecies;
                Sample.lst_State[sampleIndex]  = newStateOfEachSpecies;


                string newState = DetermineState(newStateOfEachSpecies);
                string newColor = DetermineColor(newColorOfEachSpecies);

                MediaOperator mop = new MediaOperator(this);

                Sample.lst_Images[sampleIndex] = mop.GetImage(newSample, newStateOfEachSpecies, newColorOfEachSpecies);
                CustomColor cc = new CustomColor();

                picBoxSample.Update();

                if (Convert.ToBoolean(newColor.Trim() == "###,###,###"))
                {
                    newColor = "a colorless";
                }
                else
                {
                    var colorArray = newColor.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    newColor = cc.GetNearestColorName(Color.FromArgb(Convert.ToInt32(colorArray[0]), Convert.ToInt32(colorArray[1]), Convert.ToInt32(colorArray[2])));
                }


                message += "You have obtained " + newColor + " " + newState + " in " + treeViewSample.SelectedNode.Text + "...";
                UpdateStatus(message);
            }
            else
            {
                throw new Exception("You can't add a reagent or perform an operation without selecting a sample...!");
            }
        }
Ejemplo n.º 3
0
        //Seperates solution from the precipitate...
        public void CentrifugeAndSeperateSample(TreeNode treeNode)
        {
            var selectedSampleIndex = ((CustomTreeNode)treeNode).SampleIndex;

            var sampleToSeperate_States = Sample.lst_State.ElementAt(selectedSampleIndex);
            var sampleToSeperate_Sample = Sample.lst_Samples.ElementAt(selectedSampleIndex);
            var sampleToSeperate_Colors = Sample.lst_Colors.ElementAt(selectedSampleIndex);

            var arrayObj = SeperateSample(sampleToSeperate_States, sampleToSeperate_Sample, sampleToSeperate_Colors);


            List <string> tempLstSolution = arrayObj[0];
            List <string> tempLstPpt      = arrayObj[1];

            List <string> lstSolutionStates = arrayObj[2];
            List <string> lstPptStates      = arrayObj[3];

            List <string> lstSolutionColors = arrayObj[4];
            List <string> lstPptColors      = arrayObj[5];

            MediaOperator mop = new MediaOperator(mainForm);

            Bitmap bmp_Soln = mop.GetImage(tempLstSolution, lstSolutionStates, lstSolutionColors);

            Bitmap bmp_Ppt = mop.GetImage(tempLstPpt, lstPptStates, lstPptColors);



            if (tempLstPpt.Count == 0)
            {
                throw new Exception("You have nothing to seperate in this sample...!");
            }
            else
            {
                string nameOfSampleToBeSeperated = treeNode.Text;

                //Increase the sample indices of tree nodes after the selected node...
                //IncreaseSampleIndexOnNodeAddition(selectedSampleIndex);

                //Ammend the text of selected node for the supernatant..
                mainForm.treeViewSample.SelectedNode.Text += "_" + selectedSampleIndex.ToString() + "_1";

                //Create a new node for ppt..

                CustomTreeNode subSampleTreeNode = new CustomTreeNode();
                subSampleTreeNode.Text      = "Precipitate_" + selectedSampleIndex.ToString() + "_1";
                subSampleTreeNode.ForeColor = Color.Black;
                subSampleTreeNode.BackColor = Color.White;

                //Add the node after selected node in the tree view...
                subSampleTreeNode.SampleIndex = lst_Samples.Count;
                mainForm.treeViewSample.SelectedNode.Nodes.Add(subSampleTreeNode);
                mainForm.treeViewSample.ExpandAll();

                //Replace selected solution with supernatant...
                lst_Samples[selectedSampleIndex] = tempLstSolution;
                lst_Images[selectedSampleIndex]  = bmp_Soln;



                //Insert precipitate into the sample list after the supernatant...

                lst_Samples.Add(tempLstPpt);
                lst_Images.Add(bmp_Ppt);

                //Ammend color & state lists in similar manner...

                lst_Colors[selectedSampleIndex] = lstSolutionColors;

                lst_Colors.Add(lstPptColors);

                lst_State[selectedSampleIndex] = lstSolutionStates;

                lst_State.Add(lstPptStates);

                mainForm.UpdateStatus("Sample labelled as " + nameOfSampleToBeSeperated + " was centrifuged and seperated. The supernatant was labelled as " +
                                      mainForm.treeViewSample.SelectedNode.Text + " & the precipitate as " + subSampleTreeNode.Text + "...");
            }
        }