示例#1
0
        private void frmCustomSample_Load(object sender, EventArgs e)
        {
            DataTable dt = dbo.GetTable("Compound_Data");

            //Load all the cations into the list box..

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var compound = (string)dt.Rows[i].ItemArray[1];
                if (!compound.Contains('_'))
                {
                    lstBoxCationsFromDB.Items.Add(compound);
                }
            }
        }
示例#2
0
        public void CreateRandomSample(int numOfCompounds)
        {
            DB_Operator dbo = new DB_Operator();
            DataTable   dt  = dbo.GetTable("Compound_Data");

            List <string> lstCompounds = new List <string>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var compound = (string)dt.Rows[i].ItemArray[1];
                if (!compound.Contains('_'))
                {
                    lstCompounds.Add(compound);
                }
            }


            Random        r         = new Random();
            List <string> lstSample = new List <string>();

            int j = 0;

            while (lstCompounds.Count > 0 && j < numOfCompounds)
            {
                int index = r.Next(lstCompounds.Count);
                lstSample.Add(lstCompounds.ElementAt(index));
                lstCompounds.RemoveAt(index);
                j += 1;
            }

            Sample.lst_Samples.Add(lstSample);
            frmCustomSample fc = new frmCustomSample(mainForm);

            fc.PopulateAesthetics(lstSample);
        }
示例#3
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...!");
            }
        }