Пример #1
0
 //--------------------------------------------------
 public void UpdateAttachMent()
 {
     if (mVisual != null && mVisual.Visual != null && InitModelID == mModelResID)
     {
         for (uint i = 0; i < (uint)AttachMountType.AttachCount; ++i)
         {
             AttachMent attach = mAttachMents[i];
             if (attach == null || attach.parent != null)
             {
                 continue;
             }
             //挂接
             if (mVisual != null && attach.visual != null && attach.visual.Visual != null)
             {
                 Transform t = mVisual.GetBoneByName(attach.socketname);
                 if (t == null)
                 {
                     t = mVisual.VisualTransform;
                 }
                 attach.parent = t.gameObject;
                 attach.visual.Visual.SetActive(true);
                 DressingRoom.AttachObjectTo(t, attach.visual.VisualTransform, attach.transform);
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>返回影响行数</returns>
        public int Update(AttachMent model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("UPDATE " + tablePrefix + "AttachMent SET ");
            strSql.Append("Attribute=@Attribute,");
            strSql.Append("DisplayName=@DisplayName,");
            strSql.Append("AttachMentPath=@AttachMentPath,");
            strSql.Append("AttachMentSize=@AttachMentSize,");
            strSql.Append("AbbrPhotoPath=@AbbrPhotoPath,");
            strSql.Append("PubLisher=@PubLisher,");
            strSql.Append("AddDate=@AddDate,");
            strSql.Append("PhotoDescription=@PhotoDescription");
            strSql.Append(" WHERE AID=@AID");
            SqlParameter[] cmdParms =
            {
                AddInParameter("@Attribute",        SqlDbType.TinyInt,    1, model.Attribute),
                AddInParameter("@DisplayName",      SqlDbType.NVarChar,  50, model.DisplayName),
                AddInParameter("@AttachMentPath",   SqlDbType.VarChar,  255, model.AttachMentPath),
                AddInParameter("@AttachMentSize",   SqlDbType.Int,        4, model.AttachMentSize),
                AddInParameter("@AbbrPhotoPath",    SqlDbType.VarChar,  255, model.AbbrPhotoPath),
                AddInParameter("@PubLisher",        SqlDbType.NVarChar,  50, model.PubLisher),
                AddInParameter("@AddDate",          SqlDbType.DateTime,   8, model.AddDate),
                AddInParameter("@PhotoDescription", SqlDbType.NVarChar, 100, model.PhotoDescription),
                AddInParameter("@AID",              SqlDbType.Int,        4, model.AID)
            };

            return(dbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms));
        }
Пример #3
0
    public void OnWingSuccess()
    {
        AttachMent attachment = mAttachMents[(int)AttachMountType.Wing];

        if (attachment == null)
        {
            return;
        }

        WingCommonTableItem commonRes = DataManager.WingCommonTable[mWingID] as WingCommonTableItem;

        if (commonRes == null)
        {
            return;
        }
        int effectid = WingModule.GetEffectId(mWingID, (int)mWingLv);

        if (effectid == -1)
        {
            return;
        }

        uint         instid = ParticleUtility.AddEffect2MV(attachment.visual as MeshVisual, effectid, commonRes.modelSlot, SceneManager.Instance.GetCurScene().GetParticleManager());
        ParticleItem pitem  = SceneManager.Instance.GetCurScene().GetParticleManager().GetParticle(instid);

        if (pitem != null)
        {
            pitem.Layer = layermask;
        }
    }
Пример #4
0
    public AttachMent ChangeAttach(AttachMountType type, PrimitiveVisual visual, string mount, TransformData trans = null)
    {
        if (type >= AttachMountType.AttachCount)
        {
            return(null);
        }
        AttachMent attach = mAttachMents[(uint)type];

        if (attach != null && attach.visual == visual)
        {
            return(attach);
        }

        if (attach != null && attach.visual != null)
        {
            attach.visual.Destroy();
        }

        attach                   = new AttachMent();
        attach.visual            = visual;
        attach.socketname        = mount;
        attach.transform         = trans;
        mAttachMents[(uint)type] = attach;
        return(attach);
    }
Пример #5
0
    private void onWeaponVisualSucess()
    {
        if (mWeaponVisual == null || mWeaopnRes == null)
        {
            return;
        }
        TransformData trans = new TransformData();

        trans.Rot   = new Vector3(90, 0, 0);
        trans.Scale = Vector3.one * mWeaopnRes.scale;
        //mWeaponAttach = AttachVisual(mWeaponVisual, mWeaopnRes.mountpoint, trans);

        mWeaponAttach = ChangeAttach(AttachMountType.Weapon, mWeaponVisual, mWeaopnRes.mountpoint, trans);


        if (mWeaopnRes.weapon_buff != uint.MaxValue)
        {
            ErrorHandler.Parse(
                AddSkillEffect(new AttackerAttr(this), SkillEffectType.Buff, mWeaopnRes.weapon_buff),
                "in Npc::AddBornBuff"
                );
        }

        mLastWeaponBuffID = mWeaopnRes.weapon_buff;

        PlayWeaponAnim(AnimationNameDef.WeaponDefault);

        OnChangeWeapon();
    }
Пример #6
0
    public void UpdateAttachMent()
    {
        if (mVisual != null && mVisual.Visual != null)
        {
            for (uint i = 0; i < (uint)AttachMountType.AttachCount; ++i)
            {
                AttachMent attach = mAttachMents[i];
                if (attach == null || attach.parent != null)
                {
                    continue;
                }
                //挂接
                if (mVisual != null && attach.visual != null && attach.visual.Visual != null)
                {
                    Transform t = mVisual.GetBoneByName(attach.socketname);
                    if (t == null)
                    {
                        t = mVisual.VisualTransform;
                    }
                    attach.parent       = t.gameObject;
                    attach.visual.Layer = layermask;
                    DressingRoom.AttachObjectTo(t, attach.visual.VisualTransform, attach.transform);

                    if (i == (uint)AttachMountType.Weapon)
                    {
                        OnWeaponSuccess();
                    }
                    else if (i == (uint)AttachMountType.Wing)
                    {
                        OnWingSuccess();
                    }
                }
            }
        }
    }
Пример #7
0
    /// <summary>
    /// 对玩家, 只改变模型; 其他单位模型和武器技能都被改变.
    /// </summary>
    public override bool ChangeWeapon(int weaponID)
    {
        if (!CanChangeWeapon() || mActiveFlagsContainer[ActiveFlagsDef.DisableChangeWeaponModel] != 0)
        {
            return(false);
        }

        if (weaponID == -1)
        {
            return(false);
        }

        //测试武器
        if (!DataManager.WeaponTable.ContainsKey(weaponID))
        {
            GameDebug.LogError(dbgGetIdentifier() + " not find weapon id=" + weaponID.ToString());
            return(false);
        }

        if (mWeaponAttach != null)
        {
            DetachVisual(mWeaponAttach);
            mWeaponAttach.visual.Destroy();
            mWeaponAttach = null;
        }
        RemoveAttach(AttachMountType.Weapon);
        if (mWeaponVisual != null)
        {
            mWeaponVisual.Destroy();
            mWeaponVisual = null;
        }

        if (mLastWeaponBuffID != uint.MaxValue)
        {
            ErrorHandler.Parse(
                RemoveSkillBuffByResID(mLastWeaponBuffID),
                "failed to remove skill buff on skill stopped"
                );
            mLastWeaponBuffID = uint.MaxValue;
        }

        mWeaopnRes = DataManager.WeaponTable[weaponID] as WeaponTableItem;

        mWeaponVisual = new MeshVisual();
        if (string.IsNullOrEmpty(mWeaopnRes.modelname))
        {
            onWeaponVisualSucess();
        }
        else
        {
            mWeaponVisual.CreateWithConfig(AssetConfig.WeaponPath + mWeaopnRes.modelname, onWeaponVisualSucess, onWeaponVisualFail, false);
        }

        return(true);
    }
Пример #8
0
    /// <summary>
    /// 移除挂接物体
    /// </summary>
    /// <param name="type"></param>
    public void RemoveAttach(AttachMountType type)
    {
        if (type >= AttachMountType.AttachCount)
        {
            return;
        }
        AttachMent attach = mAttachMents[(uint)type];

        if (attach != null && attach.visual != null)
        {
            attach.visual.Destroy();
        }
        mAttachMents[(uint)type] = null;
    }
Пример #9
0
        /// <summary>
        /// 由一行数据得到一个实体
        /// </summary>
        /// <param name="dr">SqlDataReader对象</param>
        /// <returns>实体对象</returns>
        private AttachMent GetModel(SqlDataReader dr)
        {
            AttachMent model = new AttachMent();

            model.AID              = dbHelper.GetInt(dr["AID"]);
            model.Attribute        = dbHelper.GetByte(dr["Attribute"]);
            model.DisplayName      = dbHelper.GetString(dr["DisplayName"]);
            model.AttachMentPath   = dbHelper.GetString(dr["AttachMentPath"]);
            model.AttachMentSize   = dbHelper.GetInt(dr["AttachMentSize"]);
            model.AbbrPhotoPath    = dbHelper.GetString(dr["AbbrPhotoPath"]);
            model.PubLisher        = dbHelper.GetString(dr["PubLisher"]);
            model.AddDate          = dbHelper.GetDateTime(dr["AddDate"]);
            model.PhotoDescription = dbHelper.GetString(dr["PhotoDescription"]);
            return(model);
        }
Пример #10
0
 public void DetachVisual(AttachMent attach)
 {
     if (attach == null)
     {
         return;
     }
     if (attach.visual != null)
     {
         Transform trans = null;
         if (attach.parent != null)
         {
             trans = attach.parent.transform;
         }
         DressingRoom.DetachObjectFrom(trans, attach.visual.Visual);
     }
     attachments.Remove(attach);
 }
Пример #11
0
    override public void Destroy()
    {
        if (mBattleUintAI != null)
        {
            mBattleUintAI.Destory();
            mBattleUintAI = null;
        }

        if (mActionCenter != null)
        {
            mActionCenter.Destroy();
            mActionCenter = null;
        }

        if (mSkillEffectManager != null)
        {
            SkillDetails.OnSkillEffectOwnerEvent(mSkillEffectManager, SkillEffectOwnerEventDef.OwnerLeaveScene);
            mSkillEffectManager.Destroy();
            mSkillEffectManager = null;
        }

        mActiveFlagsContainer = null;
        mRandEventContainer   = null;

        mHitMaterialEffectCdContainer = null;

        mProperty = null;

        mUIShield = null;

        base.Destroy();



        for (int i = 0; i < mAttachMents.Length; ++i)
        {
            AttachMent attach = mAttachMents[i];
            if (attach != null && attach.visual != null)
            {
                attach.visual.Destroy();
            }
            mAttachMents[i] = null;
        }
    }
Пример #12
0
    /// <summary>
    /// 挂接一个显示对象
    /// </summary>
    protected AttachMent AttachVisual(PrimitiveVisual visual, string socketname, TransformData trans)
    {
        AttachMent attach = new AttachMent();

        attach.socketname = socketname;
        attach.transform  = trans;
        attach.visual     = visual;

        Transform bone = mVisual.GetBoneByName(attach.socketname);

        if (bone == null)
        {
            bone = mVisual.VisualTransform;
        }
        DressingRoom.AttachObjectTo(bone, attach.visual.VisualTransform, attach.transform);
        // BehaviourUtil.StartCoroutine(WaitForAttachComplete(attach));

        return(attach);
    }
Пример #13
0
    private void OnWeaponSuccess()
    {
        if (mVisual == null || mVisual.Visual == null)
        {
            return;
        }
        if (mWeapon == null || !mWeapon.IsCompleteOrDestroy)
        {
            return;
        }

        WeaponTableItem mWeaopnRes = DataManager.WeaponTable[mWeaponID] as WeaponTableItem;

        Transform bone = mVisual.GetBoneByName(mWeaopnRes.mountpoint);

        if (bone == null)
        {
            bone = mVisual.VisualTransform;
        }

        string animname = AnimationNameDef.GetAnimNameByStatename(mWeaopnRes.ani_pre, AnimationNameDef.PrefixXiuxi);

        PlayAnimaton(animname);


        AttachMent attachment = mAttachMents[(int)AttachMountType.Weapon];

        if (attachment == null)
        {
            return;
        }

        if (mWeaopnRes.weapon_buff != uint.MaxValue)
        {
            SkillBuffTableItem sbt = DataManager.BuffTable[mWeaopnRes.weapon_buff] as SkillBuffTableItem;
            if (sbt != null)
            {
                ParticleUtility.AddEffect2MV(mWeapon, (int)sbt._3DEffectID, sbt._3DEffectBindpoint, ParticleMng);
            }
        }
    }
Пример #14
0
    public override void PlayWingAnim(string statename)
    {
        AttachMent attach = GetAttach(AttachMountType.Wing);

        if (attach == null)
        {
            return;
        }
        MeshVisual wingVisual = attach.visual as MeshVisual;

        if (wingVisual != null && wingVisual.AnimManager != null && wingVisual.AnimManager.Property != null)
        {
            int stateid = wingVisual.AnimManager.Property.GetStateHash(statename);
            if (stateid == 0)
            {
                stateid = wingVisual.AnimManager.Property.GetStateHash("Base Layer.emptyState");
            }

            wingVisual.AnimManager.Anim.SetInteger("state", stateid);
        }
    }
Пример #15
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="AID">编号ID</param>
        /// <returns>返回影响行数</returns>
        public int Add(AttachMent model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("INSERT INTO " + tablePrefix + "AttachMent(");
            strSql.Append("Attribute,DisplayName,AttachMentPath,AttachMentSize,AbbrPhotoPath,PubLisher,AddDate,PhotoDescription)");
            strSql.Append(" VALUES (");
            strSql.Append("@Attribute,@DisplayName,@AttachMentPath,@AttachMentSize,@AbbrPhotoPath,@PubLisher,@AddDate,@PhotoDescription)");
            SqlParameter[] cmdParms =
            {
                AddInParameter("@Attribute",        SqlDbType.TinyInt,    1, model.Attribute),
                AddInParameter("@DisplayName",      SqlDbType.NVarChar,  50, model.DisplayName),
                AddInParameter("@AttachMentPath",   SqlDbType.VarChar,  255, model.AttachMentPath),
                AddInParameter("@AttachMentSize",   SqlDbType.Int,        4, model.AttachMentSize),
                AddInParameter("@AbbrPhotoPath",    SqlDbType.VarChar,  255, model.AbbrPhotoPath),
                AddInParameter("@PubLisher",        SqlDbType.NVarChar,  50, model.PubLisher),
                AddInParameter("@AddDate",          SqlDbType.DateTime,   8, model.AddDate),
                AddInParameter("@PhotoDescription", SqlDbType.NVarChar, 100, model.PhotoDescription)
            };

            return(dbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms));
        }
Пример #16
0
    private void UpdateWingAnim(uint elapsed)
    {
        AttachMent attach = GetAttach(AttachMountType.Wing);

        if (attach == null)
        {
            return;
        }
        MeshVisual wingVisual = attach.visual as MeshVisual;

        if (wingVisual != null && wingVisual.AnimManager != null && wingVisual.AnimManager.Property != null)
        {
            AnimatorStateInfo info = wingVisual.AnimManager.Anim.GetCurrentAnimatorStateInfo(0);

            if (!info.IsName(AnimationNameDef.WingDefault) && !info.IsName(AnimationNameDef.WingEmpty) && info.normalizedTime >= 1 && !info.loop)
            {
                int stateid = wingVisual.AnimManager.Property.GetStateHash(AnimationNameDef.WingDefault);

                if (stateid == 0)
                {
                    stateid = wingVisual.AnimManager.Property.GetStateHash(AnimationNameDef.WingEmpty);
                }
                wingVisual.AnimManager.Anim.SetInteger("state", stateid);
            }
            mWaveWingTime += elapsed;
            if (mWaveWingTime >= GameConfig.WaveWingFrequency * 1000 && (info.IsName(AnimationNameDef.WingDefault) || info.IsName(AnimationNameDef.WingEmpty)))
            {
                mWaveWingTime = 0;
                int stateid = wingVisual.AnimManager.Property.GetStateHash(AnimationNameDef.WingFei);

                if (stateid != 0)
                {
                    wingVisual.AnimManager.Anim.SetInteger("state", stateid);
                }
            }
        }
    }
Пример #17
0
    public void OnWingSuccess()
    {
        AttachMent attachment = mAttachMents[(int)AttachMountType.Wing];

        if (attachment == null)
        {
            return;
        }

        WingCommonTableItem commonRes = DataManager.WingCommonTable[mWingID] as WingCommonTableItem;

        if (commonRes == null)
        {
            return;
        }
        if (!DataManager.EffectTable.ContainsKey(commonRes.effectNomal))
        {
            return;
        }

        EffectTableItem item = DataManager.EffectTable[commonRes.effectNomal] as EffectTableItem;

        ParticleUtility.AddEffect2MV(attachment.visual as MeshVisual, commonRes.effectNomal, commonRes.modelSlot, ParticleMng);
    }
Пример #18
0
    /// <summary>
    /// 更新挂接特效
    /// </summary>
    public void UpdateAttachParticle()
    {
        SceneParticleManager particlemng = SceneManager.Instance.GetCurScene().GetParticleManager();
        int nCount = mAttachParticles.Count;
        List <ParticleAttachMent> toDel = null;

        for (int i = 0; i < nCount; ++i)
        {
            ParticleAttachMent attach = mAttachParticles[i];
            ParticleItem       item   = particlemng.GetParticle(attach.particleid);

            if (attach == null || item == null || item.IsDead())
            {
                if (toDel == null)
                {
                    toDel = new List <ParticleAttachMent>();
                }
                toDel.Add(attach);
                continue;
            }
            //将特效更新到对应位置上
            if (attach.parent == null || item.parent == null)
            {
                PrimitiveVisual aVisual = null;
                if (attach.atype != AttachMountType.AttachCount)
                {
                    AttachMent buildinAttach = mAttachMents[(int)attach.atype];
                    if (buildinAttach != null)
                    {
                        aVisual = buildinAttach.visual;
                    }
                }
                else
                {
                    aVisual = mVisual;
                }
                if (aVisual != null && aVisual is MeshVisual && aVisual.Visual != null)
                {
                    Transform tr = null;
                    if (string.IsNullOrEmpty(attach.socketname))
                    {
                        tr = aVisual.VisualTransform;
                    }
                    else
                    {
                        tr = (aVisual as MeshVisual).GetBoneByName(attach.socketname);
                        if (tr == null)
                        {
                            tr = aVisual.VisualTransform;
                        }
                    }

                    attach.parent = tr.gameObject;


                    EffectTableItem effectitem = DataManager.EffectTable[attach.resid] as EffectTableItem;

                    //不跟随释放者的特效,取挂点的方向
                    if (effectitem.notFollow && tr != null && attach.transform != null)
                    {
                        if (tr != null)
                        {
                            attach.transform.Rot = tr.rotation.eulerAngles;
                        }
                        else
                        {
                            attach.transform.Rot = Vector3.zero;
                        }
                    }
                }

                if (attach.parent != null)
                {
                    if (item.visual != null && item.visual.Visual != null)
                    {
                        item.visual.Visual.SetActive(true);
                    }
                    DressingRoom.AttachParticleTo(item, attach.parent.transform);
                }
            }
        }

        if (toDel != null)
        {
            foreach (ParticleAttachMent at in toDel)
            {
                mAttachParticles.Remove(at);
            }
        }
    }
Пример #19
0
        /// <summary>
        /// 附件上传
        /// </summary>
        private void Upload()
        {
            byte   attribute        = (byte)Utils.GetFormInt("hidden_attr");  //附件属性
            string hasWaterMark     = Utils.GetFormString("chHasWaterMark");  //原图是否水印
            string hasAbbrImage1    = Utils.GetFormString("chHasAbbrImage1"); //是否生成缩略图
            string hasWaterMark1    = Utils.GetFormString("chHasWaterMark1"); //缩略图是否水印
            int    abbrImageWidth1  = Utils.GetFormInt("abbrImageWidth1");    //缩略图宽
            int    abbrImageHeight1 = Utils.GetFormInt("abbrImageHeight1");   //缩略图高
            string filepathshort    = sysConfig.Attachments.Path.Replace("\\\\", "\\") + "\\"
                                      + DateTime.Now.ToString(sysConfig.Attachments.Directory == "" ? "yyyyMM" : sysConfig.Attachments.Directory) + "\\";
            string filepath = Utils.GetRootPath() + filepathshort; //附件存放路径

            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }

            string errorMsg      = string.Empty; //错误信息
            int    returnVal     = 1;            //返回值。1:成功,202:无效上传文件,203:你没有权限,204:未知错误
            string returnImgName = string.Empty; //返回图片名称
            string abbName       = string.Empty; //缩略图名称

            HttpFileCollection uploadedFiles = Request.Files;

            for (int i = 0; i < uploadedFiles.Count; i++)
            {
                string fileDisplayName = DTCMS.Common.Utils.GetFormString("File" + (i + 1) + "Name"); //附件名称
                string fileInfo        = DTCMS.Common.Utils.GetFormString("File" + (i + 1) + "Info"); //附件描述

                HttpPostedFile userPostedFile = uploadedFiles[i];
                string         fileName       = System.IO.Path.GetFileName(userPostedFile.FileName);
                if (fileName != "")
                {
                    #region 验证附件格式是否正确
                    if (!AttachmentFormat(fileName, attribute))
                    {
                        if (errorMsg != string.Empty)
                        {
                            errorMsg += ",";
                        }
                        errorMsg += fileName;
                        continue;
                    }
                    #endregion 验证附件格式是否正确

                    try
                    {
                        int fileContentLen = userPostedFile.ContentLength;
                        if (fileContentLen > 0)
                        {
                            #region 附件上传

                            returnImgName = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString() + fileName.Substring(fileName.LastIndexOf('.')).ToLower();
                            abbName       = returnImgName.Substring(0, returnImgName.LastIndexOf('.')) + "_abbr" + fileName.Substring(fileName.LastIndexOf('.')).ToLower();
                            userPostedFile.SaveAs(filepath + returnImgName);  //附件上传
                            #endregion 附件上传

                            #region 是否图片
                            if (attribute == (int)EAttachmentAttribute.Photo)
                            {
                                if (hasAbbrImage1.Trim().ToLower() == "true")
                                {
                                    #region 生成缩略图
                                    EWaterImageType mode = EWaterImageType.W;
                                    if (abbrImageHeight1 > 0 && abbrImageWidth1 <= 0)
                                    {
                                        mode = EWaterImageType.H;
                                    }
                                    else if (abbrImageWidth1 > 0 && abbrImageHeight1 <= 0)
                                    {
                                        mode = EWaterImageType.W;
                                    }
                                    else if ((abbrImageHeight1 > 0) && (abbrImageWidth1 > 0))
                                    {
                                        mode = EWaterImageType.CUT;
                                    }
                                    else
                                    {
                                        mode = EWaterImageType.NO;
                                    }
                                    if (mode == EWaterImageType.NO)
                                    {
                                        abbrImageWidth1  = 500;
                                        abbrImageHeight1 = 0;
                                        mode             = EWaterImageType.W;
                                    }
                                    string abbPath = filepath + abbName;
                                    Common.WaterImage.MakeThumbnail(filepath + returnImgName, abbPath
                                                                    , abbrImageWidth1, abbrImageHeight1, mode);
                                    #endregion 生成缩略图

                                    #region 缩略图水印
                                    if (hasWaterMark1.Trim().ToLower() == "true")
                                    {
                                        WaterImage(abbPath, abbPath);
                                    }
                                    #endregion 缩略图水印
                                }

                                #region 原图水印

                                if (attribute == (int)EAttachmentAttribute.Photo)
                                {
                                    if (hasWaterMark.Trim().ToLower() == "true")
                                    {
                                        WaterImage(filepath + returnImgName, filepath + returnImgName);
                                    }
                                }
                                #endregion 原图水印
                            }
                            #endregion 是否图片

                            #region 保存数据
                            AttachMent modAttachMent = new AttachMent();
                            modAttachMent.Attribute      = attribute;
                            modAttachMent.DisplayName    = fileDisplayName;
                            modAttachMent.AttachMentPath = "/" + filepathshort.Replace("\\", "/") + returnImgName;
                            modAttachMent.AttachMentSize = fileContentLen;
                            if (hasAbbrImage1.Trim().ToLower() == "true")
                            {
                                modAttachMent.AbbrPhotoPath = "/" + filepathshort.Replace("\\", "/") + abbName;
                            }
                            else
                            {
                                modAttachMent.AbbrPhotoPath = "";
                            }
                            modAttachMent.PubLisher        = "";
                            modAttachMent.AddDate          = DateTime.Now;
                            modAttachMent.PhotoDescription = fileInfo;
                            bllAttachment.Add(modAttachMent);
                            #endregion 保存数据
                        }
                        else
                        {
                            if (errorMsg != string.Empty)
                            {
                                errorMsg += ",";
                            }
                            errorMsg += fileName;
                        }
                    }
                    catch
                    {
                        returnVal = 204;    //未知错误
                        errorMsg  = "";
                    }
                }

                if (errorMsg != "")
                {
                    returnVal = 202;    //无效上传文件
                }
            }
            string returnImgPath = "";
            if (hasAbbrImage1.Trim().ToLower() == "true")
            {
                if (abbName != string.Empty && abbName != null)
                {
                    returnImgPath = "/" + filepathshort.Replace("\\", "/") + abbName;
                }
            }
            else
            {
                if (returnImgName != string.Empty && returnImgName != null)
                {
                    returnImgPath = "/" + filepathshort.Replace("\\", "/") + returnImgName;
                }
            }

            Response.Redirect("~/admin/attachment/emptyPage.html?returnVal=" + returnVal + "&errorMsg=" + Server.UrlEncode(errorMsg) + "&returnImgPath=" + Server.UrlEncode(returnImgPath));
        }
Пример #20
0
        public ActionResult Publish(string title, string body)
        {
            ResultInfo ri = new ResultInfo();

            if (!string.IsNullOrEmpty(title))
            {
                if (!string.IsNullOrEmpty(body))
                {
                    //是否匿名、
                    bool isanonymous = GetRequest <bool>("isanonymous");

                    bool   contentNeedFee = GetRequest <bool>("contentNeedFee");
                    int    contentFeeType = GetRequest <int>("contentFeeType");
                    int    contentFee     = GetRequest <int>("contentFee");
                    string attachIndex    = GetRequest("attachIndexs");
                    var    fileFee        = JsonHelper.JsonToModel <List <FileFee> >("[" + GetRequest("fees") + "]");//附件费用

                    string   tagsrequest = GetRequest("tags");
                    string[] tags        = tagsrequest.IsNotNullOrEmpty() ? tagsrequest.Split(',') : null;

                    List <AttachMent> attachMents = new List <AttachMent>();
                    try
                    {
                        var fileOk = true;

                        #region 先上传附件再生成数据
                        if (attachIndex.IsNotNullOrEmpty())
                        {
                            var attachIndexs = attachIndex.Split(',');
                            attachIndexs.ForEach(i =>
                            {
                                var file       = Request.Files["file" + i];
                                var fileResult = UpLoadFile(file, "/Content/U/Art/FuJian", needValidatFile: false, rename: false);
                                fileOk         = fileResult.Ok;
                                if (fileResult.Ok)
                                {
                                    var attachment = new AttachMent
                                    {
                                        AttachMentId = Guid.NewGuid(),
                                        CreateTime   = DateTime.Now,
                                        CreateUser   = UserID,
                                        DownCount    = 0,
                                        FileName     = fileResult.Data.FileName,
                                        FilePath     = fileResult.Data.FilePath,
                                        FileSize     = fileResult.Data.FileSize,
                                        MainType     = AttachEnumType.Article.GetHashCode(),
                                        IsDelete     = 0
                                    };
                                    int _index        = i.ToInt32();
                                    var attachFeeInfo = fileFee.FirstOrDefault(a => a.Index == _index);
                                    if (attachFeeInfo != null)
                                    {
                                        attachment.FeeType = attachFeeInfo.FeeType;
                                        attachment.Fee     = attachFeeInfo.Fee;
                                        attachment.IsFee   = attachFeeInfo.FeeType != 0;
                                    }
                                    attachMents.Add(attachment);
                                }
                            });
                        }
                        #endregion

                        if (fileOk)
                        {
                            BeginTran();
                            Article model = new Article()
                            {
                                Body       = HttpUtility.UrlDecode(body),
                                CreateTime = DateTime.Now,
                                IsDelete   = 0,
                                Title      = title,
                                UserID     = UserID,
                                PVCount    = 0,
                                //FilePath = fileResultInfo.Url,
                                EditCount  = 0,
                                CreateUser = UserID.ToString(),
                                UpdateUser = UserID.ToString(),
                                UpdateTime = DateTime.Now,

                                IsAnonymous = isanonymous,
                            };

                            model.ContentNeedPay = contentNeedFee;
                            //内容付费
                            if (contentNeedFee)
                            {
                                model.ContentFeeType = contentFeeType;
                                model.ContentFee     = contentFee;
                            }

                            UserExt userext = UserExtBLL.Instance.GetExtInfo(UserID);

                            //先判断该用户是否被设置成了需要审核,如果没设置的话,再判断系统系统
                            if (userext.CheckBBS == 1)
                            {
                                model.IsChecked = 1;
                            }
                            else
                            {
                                //判断是否触发审核机制:积分大于1000分时,必须要参加审核
                                int mustcheckscore = Convert.ToInt32(ConfigHelper.AppSettings("MustCheckByScore"));
                                //积分大于多少时自动审核
                                int autocheckscore = Convert.ToInt32(ConfigHelper.AppSettings("AutoCheck_NeedScore"));
                                model.IsChecked = userext.TotalScore >= mustcheckscore ? userext.TotalScore <= autocheckscore ? 1 : 2 : 2;
                            }
                            int result = ArticleBLL.Instance.Add(model, Tran);
                            if (result > 0)
                            {
                                //创建成功后 第一时间 添加附件数据
                                attachMents.ForEach(attach => attach.MainId = result);
                                if (QuestionBLL.Instance.AddAttachMent(attachMents, Tran))
                                {
                                    //处理标签
                                    //如果用户没有添加标签,则根据算法匹配
                                    if (tags == null || tags.Length == 0)
                                    {
                                        List <string> newTags = new List <string>();
                                        //获取目前所有标签
                                        var currentTags = DB.Tag.Where(a => a.IsDelete == 0).Select(a => new { tagId = a.TagId, name = a.TagName }).ToList();
                                        var fittler     = HtmlRegexHelper.ToText(HttpUtility.UrlDecode(body)) + HtmlRegexHelper.ToText(title);
                                        var segObj      = new JiebaSegmenter();
                                        var segs        = segObj.Cut(fittler, cutAll: true).GroupBy(a => a).Select(a => a.Key).ToList();
                                        foreach (var seg in segs)
                                        {
                                            var match = currentTags.FirstOrDefault(a => a.name == seg);
                                            if (match != null)
                                            {
                                                if (newTags.Count < 3)
                                                {
                                                    newTags.Add(match.tagId.ToString());
                                                }
                                            }
                                            if (newTags.Count == 3)
                                            {
                                                break;
                                            }
                                        }
                                        if (newTags.Count == 0)
                                        {
                                            //如果没有匹配到,则创建
                                            var tagName = WordSpliterHelper.GetKeyword(fittler, true);
                                            if (tagName.Length > 6)
                                            {
                                                tagName = tagName.Substring(0, 6);
                                            }
                                            Tag tag = new Tag()
                                            {
                                                CreateTime    = DateTime.Now,
                                                CreateUser    = UserID.ToString(),
                                                TagBelongId   = 1038,
                                                TagName       = tagName,
                                                TagCreateType = 3,
                                                IsDelete      = 0,
                                            };
                                            var resultTag = TagBLL.Instance.Add(tag);
                                            newTags.Add(resultTag.ToString());
                                        }
                                        tags = newTags.ToArray();
                                    }

                                    if (MenuBelongTagBLL.Instance.HandleTags(result, CommentEnumType.Article, 1038, tags, Tran))
                                    {
                                        string uri = ConfigHelper.AppSettings("ArticleDetail").FormatWith(result);
                                        if (model.IsChecked == 1)
                                        {
                                            //通知发布用户 和 管理员
                                            noticeService.On_BBS_Article_Publish_Success_Notice(UserInfo, uri, title, 2);
                                            ri.Msg = "文章发表成功,您发布的文章成功触发系统审核机制,等待管理员审核成功后即可在页面里查看";
                                            ri.Url = "/Article";
                                        }
                                        else
                                        {
                                            ri.Msg = "文章发表成功";
                                            ri.Url = uri;
                                        }
                                        //异步通知关注者
                                        NoticeBLL.Instance.OnAdd_Notice_Liker(UserInfo.UserName, UserID, uri, model.Title, NoticeTypeEnum.Article_Add, GetDomainName);
                                        _scoreService.AddScoreOnPublish_BBS_Article(UserID, result, ScoreBeloneMainEnumType.Publish_Article, CoinSourceEnum.NewArticle);
                                        Commit();
                                        ri.Ok = true;
                                    }
                                    else
                                    {
                                        RollBack();
                                    }
                                }
                                else
                                {
                                    ri.Msg = "添加附件时失败,请重试";
                                    RollBack();
                                    //删除附件
                                    attachMents.ForEach(attach =>
                                    {
                                        UploadHelper.DeleteUpFile(attach.FilePath);
                                    });
                                }
                            }
                            else
                            {
                                RollBack();
                                ri.Msg = "文章发表失败";
                                //删除附件
                                attachMents.ForEach(attach =>
                                {
                                    UploadHelper.DeleteUpFile(attach.FilePath);
                                });
                            }
                        }
                        else
                        {
                            //删除附件
                            attachMents.ForEach(attach =>
                            {
                                UploadHelper.DeleteUpFile(attach.FilePath);
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        ri.Msg = "新增文章失败";
                        RollBack();
                        //删除附件
                        attachMents.ForEach(attach =>
                        {
                            UploadHelper.DeleteUpFile(attach.FilePath);
                        });
                    }
                }
                else
                {
                    ri.Msg = "文章内容不能为空";
                }
            }
            else
            {
                ri.Msg = "文章标题不能为空";
            }
            return(Result(ri));
        }
Пример #21
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 /// <param name="model">实体对象</param>
 /// <returns>返回影响行数</returns>
 public int Add(AttachMent model)
 {
     return(dal.Add(model));
 }
Пример #22
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="model">实体对象</param>
 /// <returns>返回影响行数</returns>
 public int Update(AttachMent model)
 {
     return(dal.Update(model));
 }