Example #1
0
        private bool uploadData()
        {
            bool   goodData  = true;
            bool   uploaded  = false;
            int    errI      = 0;
            string base64Str = ReadXlsToBase64(resultFile);

            try
            {
                Thread.Sleep(3000);
                XSSFWorkbook xssfworkbook = new XSSFWorkbook(new FileStream(resultFile,
                                                                            FileMode.Open));
                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;

                //保存matrix
                //sheetI = xssfworkbook.GetSheet("Matrix");
                //List<MatrixData> matrixList = new List<MatrixData>();
                //for (int i = 2; i <= 10764; i++)
                //{
                //    IRow dataRow = sheetI.GetRow(i);
                //    string code = dataRow.GetCell(0).ToString();
                //    string value = dataRow.GetCell(1) == null ? "" : dataRow.GetCell(1).ToString();
                //    if (value.Length == 0 || value == "#N/A")
                //    {
                //        value = "0";
                //        continue;
                //    }
                //    MatrixData md = new MatrixData();
                //    md.code = code;
                //    md.value = value;
                //    matrixList.Add(md);
                //}
                //dl.matrixDatas = matrixList;
                /////////////////////////////////////////////////


                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);
                //StreamWriter strmsave = new StreamWriter("E:\\newtest.txt", false, System.Text.Encoding.Default);
                //strmsave.Write(rtnJson);
                //strmsave.Close();
                if (rtnJson.Length > 0)
                {
                    string saveStr = webService.saveScheduling(rtnJson);
                    if (saveStr == "1")
                    {
                        uploaded = true;
                    }
                }
                if (base64Str.Length > 0)
                {
                    string xlsOut = webService.fileOutXls(base64Str, verifyCode, dl.orderid, ttime);
                    if (xlsOut == "1")
                    {
                        LogHelper.WriteLog(verifyCode + "---" + "base64上传成功");
                    }
                    else
                    {
                        LogHelper.WriteLog(verifyCode + "---" + "base64上传失败");
                    }
                }
            }
            catch (Exception ex)
            {
                string errorStr = errI.ToString();
                WriteLog("上传数据失败");//ex.ToString());
                uploaded = false;
            }
            return(uploaded);
        }
Example #2
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);
        }