Esempio n. 1
0
        /// <summary>
        /// 读取excel文件
        /// </summary>
        public void ReadExcel()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "Excel2003|*.xls";
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            var result = openFileDialog.ShowDialog();
            List <ChemicalEntity> list = new List <ChemicalEntity>();

            if (result == DialogResult.OK || result == DialogResult.Yes)
            {
                var dataTable = ExcelHelper.ExcelImport(openFileDialog.FileName);
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    for (int i = 0; i < 10155; i++)
                    {
                        var entity = new ChemicalEntity();
                        //for(int j= 0 ;j< dataTable.Columns.Count;j++)
                        //{
                        //    if(dataTable.Rows[i][j] == null)
                        //    {
                        //        dataTable.Rows[i][j] = dataTable.Rows[i-1][j];
                        //    }
                        //    Console.Write(dataTable.Rows[i][j].ToString().Trim().PadLeft(10,' '));
                        //}
                        entity.Id            = String.IsNullOrEmpty(dataTable.Rows[i][0].ToString()) ? list[i - 1].Id : dataTable.Rows[i][0].ToString().Trim();
                        entity.Name          = String.IsNullOrEmpty(dataTable.Rows[i][1].ToString()) ? list[i - 1].Name : dataTable.Rows[i][1].ToString().Trim();
                        entity.Alias         = String.IsNullOrEmpty(dataTable.Rows[i][2].ToString()) ? GetPreEnglish(list, entity.Id) : dataTable.Rows[i][2].ToString().Trim();
                        entity.EnglishName   = String.IsNullOrEmpty(dataTable.Rows[i][3].ToString()) ? list[i - 1].EnglishName : dataTable.Rows[i][3].ToString().Trim();
                        entity.CAS_Num       = String.IsNullOrEmpty(dataTable.Rows[i][4].ToString()) ? GetPreCas(list, entity.Id) : dataTable.Rows[i][4].ToString().Trim();
                        entity.DangerousType = dataTable.Rows[i][5].ToString().Trim();
                        Console.WriteLine(i.ToString());
                        list.Add(entity);
                    }
                    var DangerousGroup = list.GroupBy(e => e.DangerousType);
                    foreach (var Dangerous in DangerousGroup)
                    {
                        Console.WriteLine(String.Format("{0}:{1}", Dangerous.Key.ToString(), Dangerous.Count()));
                    }

                    Console.WriteLine(DangerousGroup.Count());

                    var find = list.Where(e => e.DangerousType == "(1)闪点<23℃和初沸点≤35℃:").FirstOrDefault();
                    if (find != null)
                    {
                        Console.WriteLine(find.Id + find.Name + find.DangerousType);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 化合物测试
        /// </summary>
        public static void TextChemicalMix()
        {
            var dtList = InitDangerousType();
            var dlList = InitDangerousLevel();

            List <ChemicalEntity> ceList = new List <ChemicalEntity>();

            //具有毒性1A类的化合物
            ChemicalEntity entity1A = new ChemicalEntity();

            entity1A.DangerousList.Add(dtList[4]);


            //具有毒性1B类的化合物
            ChemicalEntity entity1B = new ChemicalEntity();

            entity1B.DangerousList.Add(dtList[3]);

            //具有毒性1C类的化合物
            ChemicalEntity entity1C = new ChemicalEntity();

            entity1C.DangerousList.Add(dtList[2]);

            //具有毒性2类的化合物
            ChemicalEntity entity2 = new ChemicalEntity();

            entity2.DangerousList.Add(dtList[1]);

            //具有毒性3类的化合物
            ChemicalEntity entity3 = new ChemicalEntity();

            entity3.DangerousList.Add(dtList[0]);

            entity1A.c_param = 0.1;
            entity1B.c_param = 0.2;
            entity1C.c_param = 0.1;
            entity2.c_param  = 9;
            entity3.c_param  = 0;

            entity1A.Name = "某成分1";
            entity1B.Name = "某成分2";
            entity1C.Name = "某成分3";
            entity2.Name  = "某成分4";
            entity3.Name  = "某成分5";

            ceList.Add(entity1A);
            ceList.Add(entity1B);
            ceList.Add(entity1C);
            ceList.Add(entity2);
            ceList.Add(entity3);


            foreach (var ce in ceList)
            {
                Console.WriteLine(ce.ToString());
            }
            Console.WriteLine("---------------------------------化合----------------------------------");
            mixture mix = new mixture(ceList);

            mix.RuleList = InitRule();
            mix.Calculate();
        }