public SurveyBaseInfo(String userName, TrainInfo tr, String failedReason="")
 {
     this.UserName = userName;
     this.TravelRecord = tr;
     this.SurveyStatus = failedReason==""?"等待":"失败";
     this.SurveyNumber = failedReason;
 }
        public List<SurveyBaseInfo> LoadWorkList(string filePath)
        {
            List<SurveyBaseInfo> Worklist = new List<SurveyBaseInfo>();
            DataSet ul = new DataSet();

            //Prepare for connection to Excel
            DataSet workListDataset = new DataSet();
            try
            {
                Console.WriteLine("正在读取Excel文件...");
                String sConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filePath + ";Extended Properties='Excel 8.0; HDR=yes; IMEX=0'"; ;
                OleDbConnection objConn = new OleDbConnection(sConnectionString);
                objConn.Open();
                OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
                OleDbDataAdapter objAdapter = new OleDbDataAdapter();
                objAdapter.SelectCommand = objCmdSelect;
                objAdapter.Fill(workListDataset);
                for (int i = 0; i < workListDataset.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = workListDataset.Tables[0].Rows[i];
                    try
                    {
                        if (dr["乘车日期"].ToString() != "")
                        {
                            TrainInfo ti = new TrainInfo(Convert.ToDateTime(dr["乘车日期"]).ToString("yyyy-MM-dd").Substring(0, 10), dr["所乘车次"].ToString(), dr["票面乘车站"].ToString(), dr["票面下车站"].ToString());
                            String username = dr["用户名"].ToString();
                            ti.TranslateStation(snt.GetTelegramCode(ti.OnBoardStation), snt.GetTelegramCode(ti.OffBoardStation));
                            if (ti.OnBoardStation == null) { Worklist.Add(new SurveyBaseInfo(username, ti, "票面上车站" + ti.OnBoardStationDisplay + "未能被翻译为电报码,请检查")); }
                            else
                            {
                                if (ti.OffBoardStation == null) { Worklist.Add(new SurveyBaseInfo(username, ti, "票面下车站" + ti.OffBoardStationDisplay + "未能被翻译为电报码,请检查")); }
                                else
                                {
                                    Worklist.Add(new SurveyBaseInfo(username, ti));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        String username = "******";
                        TrainInfo ti = new TrainInfo("###", "###", "###", "###");
                        Worklist.Add(new SurveyBaseInfo(username, ti, "无法识别," + e.ToString()));
                    }

                }
            }
            catch (Exception e)
            {
            }
            return Worklist;
        }
Exemple #3
0
 public SurveyBaseInfo(String userName, TrainInfo tr)
 {
     this.UserName     = userName;
     this.TravelRecord = tr;
 }