コード例 #1
0
ファイル: ExcelTest.cs プロジェクト: the404/bigline
        public void ReadTour()
        {
            var filename = @"D:\book1.xls";
            var ext = Path.GetExtension(filename);
            DataSet ds = new DataSet();
            if (ext == ".xls")
            {
                ds = ExcelHelper.ExcelToDS_XLS(filename);
            }
            else if (ext == ".xlsx")
            {
                ds = ExcelHelper.ExcelToDS_XLSX(filename);
            }

            var dt = ds.Tables[0];
            var cNums = dt.Columns.Count;

            if (cNums != 7) throw new MsgEx("excel格式錯誤");

            if (dt.Rows[0][0] == null || dt.Rows[0][0].ToString() != "團號")
            {
                throw new MsgEx("excel格式錯誤");
            }

            Tour tour = new Tour();
            var row = dt.Rows[1];
            tour.TourNo = row[0].ToObjString();
            tour.TourName = row[1].ToObjString();
            tour.GuideNo = row[2].ToObjString();
            tour.GuideName = row[3].ToObjString();
            tour.GuideTel = row[4].ToObjString();
            tour.StartDate = row[5].ObjToDateTime().GetValueOrDefault();
            tour.EndDate = row[6].ObjToDateTime().GetValueOrDefault();

            List<Tourist> touristList = new List<Tourist>(dt.Rows.Count - 3);

            for (int i = 4; i < dt.Rows.Count; i++)
            {
                row = dt.Rows[i];
                Tourist tourist = new Tourist();
                tourist.No = row[0].ToObjString();
                tourist.Name = row[1].ToObjString();
                tourist.Tel = row[2].ToObjString();

                if (string.IsNullOrEmpty(tourist.No) || string.IsNullOrEmpty(tourist.Name))
                {
                    continue;
                }
                touristList.Add(tourist);

            }

            var tourService = UnityHelper.Get<ITourService>();
            var touristService = UnityHelper.Get<ITouristService>();

            tourService.AddTourInfo(tour, touristList);
        }
コード例 #2
0
ファイル: ExcelTest.cs プロジェクト: the404/bigline
        public void ReadTour()
        {
            var filename = @"D:\book1.xlsx";

            var dt = ExcelHelper_Npoi.Import(filename);
            var cNums = dt.Columns.Count;

            if (cNums != 7) throw new MsgEx("excel格式錯誤");

            Tour tour = new Tour();
            var row = dt.Rows[0];
            tour.TourNo = row[0].ToObjString();
            tour.TourName = row[1].ToObjString();
            tour.GuideNo = row[2].ToObjString();
            tour.GuideName = row[3].ToObjString();
            tour.GuideTel = row[4].ToObjString();
            tour.StartDate = row[5].ObjToDateTime().GetValueOrDefault();
            tour.EndDate = row[6].ObjToDateTime().GetValueOrDefault();

            List<Tourist> touristList = new List<Tourist>(dt.Rows.Count - 3);

            for (int i = 3; i < dt.Rows.Count; i++)
            {
                row = dt.Rows[i];
                Tourist tourist = new Tourist();
                tourist.No = row[0].ToObjString();
                tourist.Name = row[1].ToObjString();
                tourist.Tel = row[2].ToObjString();

                if (string.IsNullOrEmpty(tourist.No) || string.IsNullOrEmpty(tourist.Name))
                {
                    continue;
                }
                touristList.Add(tourist);

            }

            var tourService = UnityHelper.Get<ITourService>();
            var touristService = UnityHelper.Get<ITouristService>();

            tourService.AddTourInfo(tour, touristList);
        }