コード例 #1
0
ファイル: SPINFactory.cs プロジェクト: yuryk53/dotnetrdf
        /**
         * Creates a new Exists as a blank node in a given Model.
         * @param model  the Model to create the EXISTS in
         * @param elements  the elements of the EXISTS
         * @return a new Exists
         */
        public static IExists createExists(SpinProcessor model, IElementList elements)
        {
            IExists notExists = (IExists)model.CreateResource(SP.ClassExists).As(typeof(ExistsImpl));

            notExists.AddProperty(SP.PropertyElements, elements);
            return(notExists);
        }
コード例 #2
0
        public ActionResult ImportData(string cls)
        {
            //string table = "Department";
            IList <ImportResult> retVal = new List <ImportResult>();

            string path = Server.MapPath("/") + @"Files\Temp\";

            ////文件上传,一次上传1M的数据,防止出现大文件无法上传
            HttpFileCollectionBase files = Request.Files;

            for (int i = 0; i < files.Count; i++)
            {
                //保存上传的文件
                File file = SaveHttpPostFile(files[i], path);
                if (file.Size == 0)
                {
                    continue;
                }
                Type type = Type.GetType("EasyJob.Pojo.Pojo." + cls + ",EasyJob.Pojo");

                ImportExcel ie = new ImportExcel(file.RealPath, type);

                IList <object> vals = ie.List(type);

                //数据存储
                ISession     s     = null;
                ITransaction trans = null;
                try {
                    s     = HibernateOper.GetCurrentSession();
                    trans = s.BeginTransaction();

                    foreach (object val in vals)
                    {
                        if (val is TbBase && val is IExists)
                        {
                            ImportResult ir    = new ImportResult();
                            TbBase       tbVal = (TbBase)val;
                            try {
                                bool    isExists  = false;//是否存在
                                IExists valExists = (IExists)tbVal;
                                isExists = valExists.IsExists(s);

                                if (tbVal.ImportType.Equals("添加"))
                                {
                                    if (isExists)
                                    {
                                        throw new Exception("Val is exists");
                                    }
                                    s.Save(tbVal);
                                }
                                else if (tbVal.ImportType.Equals("修改"))
                                {
                                    if (!isExists)
                                    {
                                        throw new Exception("Val is not exists");
                                    }
                                    //s.Update(tbVal);
                                    s.Merge(tbVal);
                                }
                                ir.Success = true;
                            } catch (Exception e) {
                                ir.Success = false;
                                ir.Msg     = e.Message;
                            } finally {
                                retVal.Add(ir);
                            }
                        }
                    }
                    trans.Commit();
                } catch (Exception e) {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    throw e;
                }
            }

            return(Json(retVal));
        }