Пример #1
0
        public static void importCarsParams(String dataFilePath)
        {
            DataTable dt = ExcelUtils.ExcelUtil.getDataTableFromExcel(dataFilePath);

            int rowParamNameFirst  = 4; //检查参数名称第一顺位行
            int rowParamNameSecond = 3; //检查参数名称第二顺位行

            int[] cursorPackageCode = searchFromDataTable(dt, "Model");
            ParamsCollection.dt = dt;
            Dictionary <String, HtmlAttribute> dicRules = ParamsCollection.dicRules;
            //所有车型配置信息的list
            List <CarParams> listCarParams = new List <CarParams>();
            int rowCounterBeforeConfig     = getRowCounterBeforeConfig(dt);
            int carConfigCounter           = dt.Rows.Count - rowCounterBeforeConfig;

            //针对每个配置信息获取对应参数
            for (int carConfigIter = 0; carConfigIter < carConfigCounter; carConfigIter++)
            {
                CarParams      cps         = new CarParams();
                List <paramPo> listParampo = new List <paramPo>();
                //配置所在行数
                int rowNo = carConfigIter + rowCounterBeforeConfig;
                //行号
                int columnNo = 0;

                //当没有到达最后一列的时候继续增加列数
                while (columnNo < dt.Columns.Count)
                {
                    String cname       = null;
                    String value       = null;
                    String cnameFirst  = null;
                    String cnameSecond = null;
                    Param  p           = null;
                    //因为packageCode与其他参数在不同行,所以需要单独判断
                    if (cursorPackageCode[1] >= 0 && columnNo <= cursorPackageCode[1] + 2)
                    {
                        int rowNoPackageCode = cursorPackageCode[0];
                        cname = dt.Rows[rowNoPackageCode][columnNo].ToString().Trim();
                        value = dt.Rows[rowNo][columnNo].ToString().Trim();
                        if (!String.IsNullOrEmpty(cname))
                        {
                            p = new EngineParam(cname, null, value);
                            cps.listParams.Add(p);
                        }
                        columnNo++;
                        continue;
                    }
                    cnameFirst  = dt.Rows[rowParamNameFirst][columnNo].ToString();
                    cnameSecond = dt.Rows[rowParamNameSecond][columnNo].ToString();
                    value       = dt.Rows[rowNo][columnNo].ToString().Trim();
                    cname       = null;
                    if (!String.IsNullOrEmpty(cnameFirst))
                    {
                        cname = cnameFirst.Trim();
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(cnameSecond))
                        {
                            cname = cnameSecond.Trim();
                        }
                        else
                        {
                            columnNo++;
                            continue;
                        }
                    }
                    p = new EngineParam(cname, null, value);
                    cps.listParams.Add(p);
                    columnNo++;
                }
                //获取配置号信息
                String packageCode = ImportServiceForHCBM.getParameter("Model", cps.listParams) + "_"
                                     + ImportServiceForSHFY.getParameter("Package", cps.listParams) + "_"
                                     + ImportServiceForSHFY.getParameter("Profile", cps.listParams);
                cps.packageCode = packageCode;
                listCarParams.Add(cps);
            }
            //将全部参数添加到参数合集当中
            ParamsCollection.carParams = listCarParams;
        }
Пример #2
0
        static void Main_service(string[] args)
        {
            //读取rule.xls配置文件,形成map包含填报全部参数
            DataTable dtRules = ExcelUtils.ExcelUtil.getDataTableFromExcel(@"D:\柔性参数填报系统\上海通用\rules.xls");

            LoggerUtils.LoggerUtils.logger(dtRules.Rows.Count.ToString());
            Dictionary <String, HtmlAttribute> dicRules = new Dictionary <String, HtmlAttribute>();
            int totalRowRules = dtRules.Rows.Count;

            for (int rownoRules = 1; rownoRules < totalRowRules; rownoRules++)
            {
                String        name  = ExcelUtil.reader.getCellValue(rownoRules, 2, dtRules).Trim();
                String        eid   = ExcelUtil.reader.getCellValue(rownoRules, 1, dtRules).Trim();
                String        etype = ExcelUtil.reader.getCellValue(rownoRules, 3, dtRules).Trim();
                HtmlAttribute ha    = new HtmlAttribute(eid, name, etype, null);
                dicRules.Add(name, ha);
            }

            String    engineInfoStartString = "车辆名称";
            String    configInfoStartString = "MD配置信息";
            String    patacCodeInitial      = "P";
            DataTable dt = ExcelUtils.ExcelUtil.getDataTableFromExcel(@"D:\柔性参数填报系统\上海通用\data.xls");
            //所有车型配置信息的list
            List <CarParams> listCarParams = new List <CarParams>();

            LoggerUtils.LoggerUtils.logger(dt.Columns.Count.ToString());
            int columnCounterBeforeConfig = 3;
            int carConfigCounter          = dt.Columns.Count - columnCounterBeforeConfig;

            //针对每个配置信息获取对应参数
            for (int carConfigIter = 0; carConfigIter < carConfigCounter; carConfigIter++)
            {
                CarParams      cps         = new CarParams();
                List <paramPo> listParampo = new List <paramPo>();
                //配置所在列数
                int columnNo = carConfigIter + columnCounterBeforeConfig;
                //行号
                int    rowno = 0;
                String cname = dt.Rows[rowno][0].ToString();
                String value = dt.Rows[rowno][columnNo].ToString();
                String pcode = dt.Rows[rowno][1].ToString();
                //当不是车辆名称的时候继续增加行数
                while (!cname.Equals("车辆名称"))
                {
                    rowno++;
                    cname = dt.Rows[rowno][0].ToString();
                    if (rowno >= dt.Rows.Count)
                    {
                        throw new Exception("已经超过最大行,还未找到车辆名称");
                    }
                }
                //从车辆名称到燃料种类
                while (!cname.Equals("部门会签"))
                {
                    if (String.IsNullOrEmpty(cname))
                    {
                        rowno++;
                        cname = dt.Rows[rowno][0].ToString();
                        continue;
                    }
                    value = dt.Rows[rowno][columnNo].ToString();
                    pcode = dt.Rows[rowno][1].ToString();
                    Param p = new EngineParam(cname, pcode, value);
                    cps.listParams.Add(p);
                    rowno++;
                    cname = dt.Rows[rowno][0].ToString();
                }

                //获取配置号信息
                String packageCode = getParameter("Model Code", cps.listParams)
                                     + getParameter("Package Code", cps.listParams) + "-"
                                     + getParameter("Order Sample", cps.listParams);
                cps.packageCode = packageCode;

                //通过配置号信息获取工程信息数据
                List <String> listPackageCode = new List <string>();
                if (!String.IsNullOrEmpty(packageCode))
                {
                    listPackageCode.Add(packageCode);
                    listParampo = getParamsByPackageCode(listPackageCode);
                }
                foreach (Param p in cps.listParams)
                {
                    //只有型式认证编码有效的才能够获取数据
                    if (p.patacode.StartsWith(patacCodeInitial))
                    {
                        String paramValue = getParameter(cps.packageCode, p.patacode, listParampo);
                        p.value = "test";
                        if (String.IsNullOrEmpty(paramValue))
                        {
                            continue;
                        }
                    }
                }
                //获取是否需要申报配置号信息
                String needConfig = getParameter("是否申报新配置", cps.listParams);
                if (needConfig.Equals("Y", StringComparison.OrdinalIgnoreCase))
                {
                    cps.needConfigCode = true;
                }
                else
                {
                    cps.needConfigCode = false;
                }

                //获取配置信息

                //从部门会签到MD配置信息
                while (!cname.Equals("MD配置信息"))
                {
                    rowno++;
                    cname = dt.Rows[rowno][0].ToString();
                }

                //对配置参数进行转化,转化为参数列表(listParams而不是listHtmlAttributes)
                while (rowno < dt.Rows.Count)
                {
                    cname = dt.Rows[rowno][0].ToString().Trim();
                    value = dt.Rows[rowno][columnNo].ToString().Trim();
                    if (String.IsNullOrEmpty(cname))
                    {
                        rowno++;
                        continue;
                    }
                    HtmlAttribute ha = null;
                    if (dicRules.ContainsKey(cname))
                    {
                        ha = dicRules[cname];
                    }
                    //当能够找到对应参数而且参数值不为空的时候才进行
                    //适用于能够直接找到对应参数名称的情况
                    if (ha != null && !String.IsNullOrEmpty(value))
                    {
                        //处理text类型和checkbox类型
                        if (ha.elementType.Equals(Matcher.TYPE_TEXT) || ha.elementType.Equals(Matcher.TYPE_CHECK_BOX))
                        {
                            Param p = new Param(cname, null, Matcher.VALUE_CHECKBOX);
                            cps.listParams.Add(p);
                        }
                        //处理othercheckbox类型
                        else if (ha.elementType.Equals(Matcher.TYPE_OTHER_CHECK_BOX))
                        {
                            Param p1 = new Param(cname, null, Matcher.VALUE_CHECKBOX);
                            cps.listParams.Add(p1);
                            if (dicRules.ContainsKey(cname + "内容"))
                            {
                                Param p2 = new Param(cname + "内容", null, value);
                                cps.listParams.Add(p2);
                            }
                        }
                    }
                    else if (cname.Contains("下拉菜单"))
                    {
                        cname = cname.Replace("(下拉菜单)", "").Trim();
                        //如果不包含直接下一个参数U
                        if (!dicRules.ContainsKey(cname))
                        {
                            rowno++;
                            continue;
                        }
                        ha = dicRules[cname];
                        Boolean got = false;
                        while (!cname.Equals("其他"))
                        {
                            rowno++;
                            cname = dt.Rows[rowno][0].ToString();
                            value = dt.Rows[rowno][columnNo].ToString();
                            if (!got)
                            {
                                if (!String.IsNullOrEmpty(value) && ha != null)
                                {
                                    //如果是S的话就是有这个配置,如果有这个配置就把对应的cname作为value。因为这是一个下拉菜单项
                                    Param p1 = new ConfigParam(ha.name, null, cname);
                                    cps.listParams.Add(p1);
                                    got = !got;
                                    if (cname.Equals("其他")) // 其他项目内容
                                    {
                                        Param p2 = new ConfigParam(ha.name + "其他", null, value);
                                        cps.listParams.Add(p2);
                                    }
                                }
                            }
                        }
                    }
                    rowno++;
                }
                listCarParams.Add(cps);
                //通过接口将型式认证参数导入
                //将参数转化为实际填报参数
                cps.listHtmlAttributes.Clear();
                cps.listHtmlAttributes.AddRange(getAllHAInACar(cps.listParams, dicRules));


                StringBuilder sb = new StringBuilder();
                foreach (Param p in cps.listParams)
                {
                    sb.Append(p.cname + "---" + p.value + "\r\n");
                }
                LoggerUtils.LoggerUtils.loggerTxt(@"d:\test.txt", sb.ToString());
                sb.Clear();
                foreach (HtmlAttribute ha in cps.listHtmlAttributes)
                {
                    sb.Append(handleHtmlAttributes(ha));
                }
                LoggerUtils.LoggerUtils.loggerTxt(@"d:\test2.txt", sb.ToString());
            }
        }
Пример #3
0
        public void importCarsParams(String dataFilePath)
        {
            String    engineInfoStartString = "车辆名称";
            String    configInfoStartString = "MD配置信息";
            String    patacCodeInitial      = "P";
            DataTable dt = ExcelUtils.ExcelUtil.getDataTableFromExcel(dataFilePath);

            ParamsCollection.dt = dt;
            Dictionary <String, HtmlAttribute> dicRules = ParamsCollection.dicRules;
            //所有车型配置信息的list
            List <CarParams> listCarParams = new List <CarParams>();

            LoggerUtils.LoggerUtils.logger(dt.Columns.Count.ToString());
            int columnCounterBeforeConfig = 3;
            int carConfigCounter          = dt.Columns.Count - columnCounterBeforeConfig;

            //针对每个配置信息获取对应参数
            for (int carConfigIter = 0; carConfigIter < carConfigCounter; carConfigIter++)
            {
                CarParams      cps         = new CarParams();
                List <paramPo> listParampo = new List <paramPo>();
                //配置所在列数
                int columnNo = carConfigIter + columnCounterBeforeConfig;
                //行号
                int    rowno = 0;
                String cname = dt.Rows[rowno][0].ToString();
                String value = dt.Rows[rowno][columnNo].ToString();
                String pcode = dt.Rows[rowno][1].ToString();
                //当不是车辆名称的时候继续增加行数
                while (!cname.Equals("车辆名称"))
                {
                    rowno++;
                    cname = dt.Rows[rowno][0].ToString();
                    if (rowno >= dt.Rows.Count)
                    {
                        throw new Exception("已经超过最大行,还未找到车辆名称");
                    }
                }
                //从车辆名称到燃料种类
                while (!cname.Equals("部门会签"))
                {
                    if (String.IsNullOrEmpty(cname))
                    {
                        rowno++;
                        cname = dt.Rows[rowno][0].ToString();
                        continue;
                    }
                    value = dt.Rows[rowno][columnNo].ToString();
                    pcode = dt.Rows[rowno][1].ToString();
                    Param p = new EngineParam(cname, pcode, value);
                    cps.listParams.Add(p);
                    rowno++;
                    cname = dt.Rows[rowno][0].ToString();
                }

                //获取配置号信息
                String packageCode = ImportServiceForSHFY.getParameter("Model Code", cps.listParams)
                                     + ImportServiceForSHFY.getParameter("Package Code", cps.listParams) + "-"
                                     + ImportServiceForSHFY.getParameter("Order Sample", cps.listParams);
                cps.packageCode = packageCode;

                //获取是否需要申报配置号信息
                String needConfig = ImportServiceForSHFY.getParameter("是否申报新配置", cps.listParams);
                if (needConfig.Equals("Y", StringComparison.OrdinalIgnoreCase))
                {
                    cps.needConfigCode = true;
                }
                else
                {
                    cps.needConfigCode = false;
                }

                //通过配置号信息获取工程信息数据
                List <String> listPackageCode = new List <string>();
                if (!String.IsNullOrEmpty(packageCode))
                {
                    //如果需要填报才显示对应的packagecode
                    if (cps.needConfigCode)
                    {
                        listPackageCode.Add(packageCode);
                    }
                    listParampo = ImportServiceForSHFY.getParamsByPackageCode(listPackageCode);
                }
                foreach (Param p in cps.listParams)
                {
                    //只有型式认证编码有效的才能够获取数据
                    if (p.patacode.StartsWith(patacCodeInitial))
                    {
                        String paramValue = ImportServiceForSHFY.getParameter(cps.packageCode, p.patacode, listParampo);
                        if (String.IsNullOrEmpty(p.value))
                        {
                            //p.value = "test";
                        }
                        if (String.IsNullOrEmpty(paramValue))
                        {
                            continue;
                        }
                        p.value = paramValue;
                    }
                }



                //获取配置信息版本号
                String versionNum = getVersionNumFromListParamPo(listParampo);
                cps.version = versionNum;

                //获取配置信息

                //从部门会签到MD配置信息
                while (!cname.Equals("MD配置信息"))
                {
                    rowno++;
                    cname = dt.Rows[rowno][0].ToString();
                }

                //对配置参数进行转化,转化为参数列表(listParams而不是listHtmlAttributes)
                while (rowno < dt.Rows.Count)
                {
                    cname = dt.Rows[rowno][0].ToString().Trim();
                    //将全部英文符号换成中文符号
                    cname = cname.Replace("(", "(").Replace(")", ")");
                    value = dt.Rows[rowno][columnNo].ToString().Trim();
                    if (String.IsNullOrEmpty(cname))
                    {
                        rowno++;
                        continue;
                    }
                    HtmlAttribute ha = null;
                    if (dicRules.ContainsKey(cname))
                    {
                        ha = dicRules[cname];
                    }
                    //当能够找到对应参数而且参数值不为空的时候才进行
                    //适用于能够直接找到对应参数名称的情况
                    if (ha != null && !String.IsNullOrEmpty(value))
                    {
                        //处理text类型和checkbox类型
                        if (ha.elementType.Equals(Matcher.Matcher.TYPE_TEXT) || ha.elementType.Equals(Matcher.Matcher.TYPE_CHECK_BOX))
                        {
                            Param p = new ConfigParam(cname, null, Matcher.Matcher.VALUE_CHECKBOX);
                            cps.listParams.Add(p);
                        }
                        //处理othercheckbox类型
                        else if (ha.elementType.Equals(Matcher.Matcher.TYPE_OTHER_CHECK_BOX))
                        {
                            Param p1 = new ConfigParam(cname, null, Matcher.Matcher.VALUE_CHECKBOX);
                            cps.listParams.Add(p1);
                            if (dicRules.ContainsKey(cname + "内容"))
                            {
                                Param p2 = new ConfigParam(cname + "内容", null, value);
                                cps.listParams.Add(p2);
                            }
                        }
                    }
                    else if (cname.Contains("下拉菜单"))
                    {
                        cname = cname.Replace("(下拉菜单)", "").Trim();
                        //如果不包含直接下一个参数U
                        if (!dicRules.ContainsKey(cname))
                        {
                            rowno++;
                            continue;
                        }
                        ha = dicRules[cname];
                        Boolean got = false;
                        while (!cname.Equals("其他"))
                        {
                            rowno++;
                            cname = dt.Rows[rowno][0].ToString();
                            value = dt.Rows[rowno][columnNo].ToString();
                            if (!got)
                            {
                                if (!String.IsNullOrEmpty(value) && ha != null)
                                {
                                    //如果是S的话就是有这个配置,如果有这个配置就把对应的cname作为value。因为这是一个下拉菜单项
                                    Param p1 = new ConfigParam(ha.name, null, cname);
                                    cps.listParams.Add(p1);
                                    got = !got;
                                    if (cname.Equals("其他")) // 其他项目内容
                                    {
                                        Param p2 = new ConfigParam(ha.name + "其他", null, value);
                                        cps.listParams.Add(p2);
                                    }
                                }
                            }
                        }
                    }
                    rowno++;
                }
                listCarParams.Add(cps);
            }
            //将全部参数添加到参数合集当中
            ParamsCollection.carParams = listCarParams;
        }