Ejemplo n.º 1
0
        private bool uploadData()
        {
            bool       goodData  = true;
            bool       uploaded  = false;
            int        errI      = 0;
            string     base64Str = ReadXlsToBase64(resultFile);
            FileStream input     = new FileStream(resultFile, FileMode.Open);

            try
            {
                XSSFWorkbook xssfworkbook = new XSSFWorkbook(input);
                ISheet       sheetI       = xssfworkbook.GetSheet("Data code");
                IRow         irow         = sheetI.GetRow(0);
                string       name         = irow.GetCell(2).ToString();
                IRow         irow2        = sheetI.GetRow(1);
                string       time         = irow2.GetCell(2).DateCellValue.ToString();
                DateTime     ddd          = DateTime.Parse(time);
                string       ttime        = ddd.ToString("yyyy-MM-dd HH:mm:ss");
                DataList     dl           = new DataList();
                dl.orderid    = vjList.orderId;
                dl.testDate   = ttime;
                dl.testUser   = name;
                dl.verifyCode = verifyCode;
                List <TestData> listData = new List <TestData>();
                DataSet         ds       = LoginHelper.LoadData(dataFile);
                if (ds.Tables.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    foreach (DataRow dr in dt.Rows)
                    {
                        string dataSheet = dr[0].ToString();
                        int    startRow  = int.Parse(dr[1].ToString());
                        int    endRow    = int.Parse(dr[2].ToString());
                        int    codeC     = int.Parse(dr[3].ToString());
                        int    keyC      = int.Parse(dr[4].ToString());
                        int    valueC    = int.Parse(dr[5].ToString());
                        for (int i = startRow; i <= endRow; i++)
                        {
                            errI = i;
                            ISheet sheet   = xssfworkbook.GetSheet(dataSheet);
                            IRow   dataRow = sheet.GetRow(i);
                            string code    = dataRow.GetCell(codeC).ToString();
                            string key     = dataRow.GetCell(keyC).ToString();
                            string value   = dataRow.GetCell(valueC) == null ? "" : dataRow.GetCell(valueC).ToString();
                            if (value.Length == 0 || value == "#N/A")
                            {
                                //goodData = false;
                                value = "0";
                                continue;
                            }
                            TestData td = new TestData();
                            td.id    = key;
                            td.value = value;
                            td.code  = code;
                            listData.Add(td);
                        }
                    }
                }
                dl.testDatas = listData;
                string rtnJson = JsonConvert.SerializeObject(dl);
                if (rtnJson.Length > 0)
                {
                    string saveStr = webService.saveScheduling(rtnJson);
                    if (saveStr == "1")
                    {
                        LogHelper.WriteLog(verifyCode + "---" + "DataCode上传成功");
                    }
                    else
                    {
                        LogHelper.WriteLog(verifyCode + "---" + "DataCode上传失败");
                    }
                }
                if (base64Str.Length > 0)
                {
                    string xlsOut = webService.fileOutXls(base64Str, verifyCode, dl.orderid, ttime);
                    if (xlsOut == "1")
                    {
                        uploaded = true;
                        LogHelper.WriteLog(verifyCode + "---" + "base64上传成功");
                    }
                    else
                    {
                        LogHelper.WriteLog(verifyCode + "---" + "base64上传失败");
                    }
                }
            }
            catch (Exception ex)
            {
                if (File.Exists(reportFile))
                {
                    File.Delete(reportFile);
                }
                string errorStr = errI.ToString();
                LogHelper.WriteLog("数据问题---------" + errorStr);
                uploaded = false;
            }
            finally
            {
                input.Close();
            }
            return(uploaded);
        }