Exemple #1
0
        /// <summary>
        /// 初始化科室与科室类别
        /// </summary>
        public void InitialDepartmentAndCategory()
        {
            var departmentCategoryFile = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["DepartmentCategory"]);
            //第一列为Category,先获取,再填充到
            //从第二列开始,每列为科室,所属类别为第一列
            //获取当前表格的总共Row数
            ReadFromExcel readFromExcel = new ReadFromExcel();
            //按Row获取当前行的所有数据
            int rowCount = readFromExcel.GetRowCount(departmentCategoryFile);

            for (int i = 2; i <= rowCount; i++)
            {
                var columnData = readFromExcel.ReadRowFromExcel((uint)i, departmentCategoryFile);
                //获取第一个数为类别
                if (columnData.Count >= 2)
                {
                    var firstData = columnData.First();

                    WriteBaseData      writeBaseData      = new WriteBaseData();
                    DepartmentCategory departmentCategory = new DepartmentCategory();
                    //将第一个数当作类别,插入科室类别表中
                    departmentCategory.Name = firstData;
                    departmentCategory      = writeBaseData.AddDepartmentCategory(departmentCategory);
                    if (departmentCategory == null)
                    {
                        return;
                    }
                    columnData.Remove(firstData);

                    foreach (var data in columnData)
                    {
                        //依次将第二个列之后的科室名插入到科室表中
                        Department department = new Department();
                        department.DepartmentName       = data;
                        department.DepartmentCategoryID = departmentCategory.DepartmentCategoryID;
                        writeBaseData.AddDepartment(department);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 初始化科室.
        /// </summary>
        public void InitialDepartment()
        {
            var fileName = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager
                                                              .AppSettings["Department"]);
            //第一列为科室名称,第二列所属科室类别,第三列为科室的Guid
            ReadFromExcel readFromExcel = new ReadFromExcel();
            //按Row获取当前行的所有数据
            int rowCount = readFromExcel.GetRowCount(fileName);

            for (int i = 2; i <= rowCount; i++)
            {
                var columnData = readFromExcel.ReadRowFromExcel((uint)i, fileName);
                //获取第一个数为科室名称
                //数据必须大于等3才是正确的
                if (columnData.Count >= 3)
                {
                    WriteBaseData writeBaseData = new WriteBaseData();
                    //DepartmentCategory departmentCategory = new DepartmentCategory();
                    //第二列为科室类别
                    var name = columnData.ElementAt(1);
                    var departmentCategory = writeBaseData.FindDepartmentCategoryByName(name);
                    if (departmentCategory == null)
                    {
                        return;
                    }
                    Department department = new Department();
                    //第一列为科室名称
                    department.DepartmentName = columnData.ElementAt(0);
                    //第三列为科室Guid
                    department.DepartmentID         = Guid.Parse(columnData.ElementAt(2));
                    department.DepartmentCategoryID = departmentCategory.DepartmentCategoryID;
                    //添加department
                    writeBaseData.AddDepartment(department);
                }
            }
        }