コード例 #1
0
        public void TableColumnsStructureRepositoryGetInterfaceTest()
        {
            var tblRep = new TableColumnsStructureFactory();
            var o      = tblRep.GetImporter(TableColumnsStructureFactory.BiometricRawDataName);

            Assert.True(o is ExcelBiometryDataImporter);
            try
            {
                var o2 = tblRep.GetImporter("sfd");
                Assert.True(false);
            }
            catch (ExcelImporterException e)
            {
                Assert.True(true);
            }

            try
            {
                var o2 = tblRep.GetImporter(null);
                Assert.True(false);
            }
            catch (ExcelImporterException e)
            {
                Assert.True(true);
            }
        }
コード例 #2
0
        public ActionResult Create(long?Table, long?id)
        {
            var postedModel =
                ViewData[GlobalNames.PostedModel] as Engine.Areas.ImportExport.ServiceTests.ExcelStructreTable;

            if (postedModel != null)
            {
                Table = (long)postedModel.Table;
            }

            if (id.HasValue)
            {
                using (var db = new EngineContext())
                {
                    var table = db.ExcelStructreTables.Include("Nodes").FirstOrDefault(d => d.Id == id);
                    if (table == null)
                    {
                        throw new Exception("ساختار جدول یافت نشد");
                    }
                    return(View("Create", table));
                }
            }

            try
            {
                if (Table.HasValue)
                {
                    ExcelStructureTableNames type = 0;
                    try
                    {
                        type = (ExcelStructureTableNames)Table.Value;
                    }
                    catch (Exception e)
                    {
                        throw new Exception("شماره نوع جدول اشتباه است");
                    }

                    var            factory   = new TableColumnsStructureFactory();
                    IExcelImporter impoerter = factory.GetImporter(factory.GetImporterName(type));

                    ExcelStructreTable tbl = impoerter.GetTableTemplate();
                    return(View("Create", tbl));
                }
                else
                {
                    return(View("Create", new ExcelStructreTable()));
                }
            }
            catch (Exception e)
            {
                ViewData[GlobalNames.MVCResponseMessage] = new CustomResult
                {
                    Message = e.Message,
                    Status  = CustomResultType.fail
                };

                return(View("Create", new ExcelStructreTable()));
            }
        }
コード例 #3
0
        private ActionResult ImportExcelHelper(long id,
                                               bool confirmed, bool isSave,
                                               string msg, string viewName)
        {
            using (var db = new EngineContext())
            {
                var model = db.ExcelStructreTables.Find(id);
                if (model == null)
                {
                    EBaseAppController <ExcelStructreTable, CommonParameter>
                    .GenErrorMessage(ViewData, "ساختار اکسل یافت نشد");

                    return(View("ImportExcel"));
                }

                if (!model.Table.HasValue)
                {
                    EBaseAppController <ExcelStructreTable, CommonParameter>
                    .GenErrorMessage(ViewData, "نوع جدولی یافت نشد");

                    return(View("ImportExcel"));
                }

                var            table     = new TableColumnsStructureFactory();
                IExcelImporter impoerter = table.GetImporter(table
                                                             .GetImporterName(model.Table.Value));

                ImportExcelMainFunction(impoerter, model, confirmed);
                var models = impoerter.GetModels();

                ViewData["ModelsName"] = models;


                if (isSave)
                {
                    impoerter.Save();
                }

                ViewData[Success] = msg;
                return(View(viewName, model));
            }
        }