Ejemplo n.º 1
0
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="entity">日志实体</param>
        /// <returns></returns>
        public static AjaxResult Add(C_S_Log entity)
        {
            AjaxResult msg = new AjaxResult();

            string strSql = string.Format(@"INSERT INTO dbo.C_S_Log
                                            VALUES  ( NEWID() ,@OperateType ,@OperateUserId ,@ApplicationId , 
                                            @ApplicationCode ,@Content ,GETDATE() ,@IPAddress, @MachineName  )");

            SqlParameter[] parameter = new SqlParameter[] {
                new SqlParameter("OperateType", entity.OperateType),
                new SqlParameter("OperateUserId", entity.OperateUserId),
                new SqlParameter("ApplicationId", entity.ApplicationId),
                new SqlParameter("ApplicationCode", entity.ApplicationCode),
                new SqlParameter("Content", entity.Content),
                new SqlParameter("IPAddress", entity.IPAddress),
                new SqlParameter("MachineName", entity.MachineName)
            };

            int tmp = SqlHelper.ExecuteNonQuery(strSql, parameter);

            if (tmp >= 1)
            {
                msg.data    = "成功";
                msg.state   = 1;
                msg.message = "写入日志成功。";
            }
            else
            {
                msg.data    = "失败";
                msg.state   = -1;
                msg.message = "写入日志失败。";
            }
            return(msg);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 客户端更新日志
        /// </summary>
        /// <param name="appCode"></param>
        /// <param name="userId"></param>
        /// <param name="ip_HostName_state"></param>
        /// <returns></returns>
        public static AjaxResult WriteUpdateLog(string appCode, string userId, string ip_HostName_state)
        {
            AjaxResult msg = new AjaxResult();

            //获取用户数据
            string    sqlStr = "SELECT * FROM dbo.[User] WHERE UserID=@UserID";
            DataTable dt     = SqlHelper.ExecuteDataTable(sqlStr, new SqlParameter[] { new SqlParameter("UserID", userId) });

            string userName = string.Empty;

            if (dt.Rows.Count > 0)
            {
                userName = dt.Rows[0]["DisplayName"].ToString();
            }

            //获取应用数据
            dt = SqlHelper.ExecuteDataTable("SELECT * FROM dbo.C_S_Application WHERE ApplicationCode=@ApplicationCode", new SqlParameter[] { new SqlParameter("ApplicationCode", appCode) });

            string applicationId = string.Empty;

            if (dt.Rows.Count > 0)
            {
                applicationId = dt.Rows[0]["ApplicationId"].ToString();
            }

            //拆分获得 ip(ip地址)  hostName(客户端)  state (更新状态)
            string[] ip_hostName_state = ip_HostName_state.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            //默认更新成功
            int    operateType = 1;
            string content     = "客户端更新成功。";

            //如果更新失败
            if (ip_hostName_state.Last() == "fail")
            {
                operateType = 2;
                content     = "客户端更新失败。";
            }
            C_S_Log entity = new C_S_Log()
            {
                OperateType     = operateType,
                OperateUserId   = userName,
                ApplicationId   = applicationId,
                ApplicationCode = appCode,
                Content         = content,
                IPAddress       = ip_hostName_state[0],
                MachineName     = ip_hostName_state[1]
            };

            msg = Add(entity);
            return(msg);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ApplicationId"></param>
        /// <returns></returns>
        public AjaxResult Delete(string ApplicationId)
        {
            AjaxResult msg = new AjaxResult();

            DataTable dt = SqlHelper.ExecuteDataTable("select * from C_S_Application where ApplicationId = @ApplicationId", new SqlParameter[] { new SqlParameter("ApplicationId", ApplicationId) });

            //删除应用的时候,连同应用的版本号一起删除
            string sqlStr = "delete C_S_AppVersion where ApplicationId = @ApplicationId;";

            sqlStr += "delete C_S_Application where ApplicationId = @ApplicationId";
            SqlParameter[] parameter = { new SqlParameter("ApplicationId", ApplicationId) };

            int result = SqlHelper.ExecuteNonQuery(sqlStr, parameter);

            if (result > 0)
            {
                msg.data    = "";
                msg.state   = "success";
                msg.message = "删除成功!";

                #region ===========记录操作日志=================
                C_S_Log log = new C_S_Log()
                {
                    OperateType     = 3,    //移除
                    OperateUserId   = OperatorProvider.Provider.GetCurrent().UserName,
                    ApplicationId   = ApplicationId,
                    Content         = "删除应用",
                    ApplicationCode = "",
                    IPAddress       = Net.Ip,
                    MachineName     = Net.Host
                };

                if (dt.Rows.Count > 0)
                {
                    log.ApplicationCode = dt.Rows[0]["ApplicationCode"].ToString();
                }
                CSLog_BLL.Add(log);
                #endregion ======================================
            }
            else
            {
                msg.data    = "";
                msg.state   = "error";
                msg.message = "删除失败!";
            }
            return(msg);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public AjaxResult Add(C_S_Application entity)
        {
            AjaxResult          msg       = new AjaxResult();
            List <SqlParameter> parameter = new List <SqlParameter>();

            parameter.Add(new SqlParameter("ApplicationName", entity.ApplicationName));
            parameter.Add(new SqlParameter("ApplicationCode", entity.ApplicationCode));
            parameter.Add(new SqlParameter("Company", entity.Company));

            string sqlStr = "select * from C_S_Application where (ApplicationName = @ApplicationName or ApplicationCode=@ApplicationCode) and Company = @Company";

            DataTable dt = SqlHelper.ExecuteDataTable(sqlStr, parameter.ToArray());

            if (dt.Rows.Count > 0)
            {
                msg.data    = "";
                msg.state   = "error";
                msg.message = "新增失败,该应用已经存在!";
            }
            else
            {
                sqlStr = @"INSERT INTO dbo.C_S_Application (ApplicationId,ApplicationName,ApplicationCode,
                                 Company,SortCode,Remark,CreateBy,CreateTime,StartFileName)
                                VALUES  ( @ApplicationId ,@ApplicationName ,
                                          @ApplicationCode ,  @Company, @SortCode ,                                      
                                          @Remark ,  @CreateBy , @CreateTime,@StartFileName) ";
                parameter.Clear();
                parameter.Add(new SqlParameter("ApplicationId", entity.ApplicationId));
                parameter.Add(new SqlParameter("ApplicationName", entity.ApplicationName));
                parameter.Add(new SqlParameter("ApplicationCode", entity.ApplicationCode));
                parameter.Add(new SqlParameter("SortCode", entity.SortCode));
                parameter.Add(new SqlParameter("Company", entity.Company));
                parameter.Add(new SqlParameter("Remark", entity.ApplicationName));
                parameter.Add(new SqlParameter("CreateBy", entity.CreateBy));
                parameter.Add(new SqlParameter("CreateTime", entity.CreateTime));
                parameter.Add(new SqlParameter("StartFileName", entity.StartFileName));

                int result = SqlHelper.ExecuteNonQuery(sqlStr, parameter.ToArray());

                if (result == 1)
                {
                    msg.data    = "";
                    msg.state   = "success";
                    msg.message = "新增成功!";


                    #region =====================写操作日志======================
                    C_S_Log log = new C_S_Log()
                    {
                        OperateType     = 4,        //新增
                        OperateUserId   = entity.CreateBy,
                        ApplicationId   = entity.ApplicationId,
                        ApplicationCode = entity.ApplicationCode,
                        Content         = "新增应用",
                        IPAddress       = Net.Ip,
                        MachineName     = Net.Host
                    };

                    CSLog_BLL.Add(log);
                    #endregion =================================================
                }
                else
                {
                    msg.data    = "";
                    msg.state   = "error";
                    msg.message = "新增失败!";
                }
            }
            return(msg);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public AjaxResult Add(C_S_AppVersion entity)
        {
            DataTable dt = SqlHelper.ExecuteDataTable("select * from C_S_Application where ApplicationId = @ApplicationId", new SqlParameter[] { new SqlParameter("ApplicationId", entity.ApplicationId) });

            entity.Create();
            AjaxResult msg    = new AjaxResult();
            string     sqlStr = @"INSERT INTO dbo.C_S_AppVersion(AppVersionId,ApplicationId,VersionCode,AppFileName,
                                     AppDirectory,AppSize,Remark,CreateBy,CreateTime)
                                VALUES  ( @AppVersionId , @ApplicationId , 
                                          @VersionCode ,  @AppFileName , 
                                          @AppDirectory ,  @AppSize , 
                                          @Remark ,  @CreateBy ,  @CreateTime)";

            SqlParameter[] parameter =
            {
                new SqlParameter("AppVersionId",  entity.AppVersionId),
                new SqlParameter("ApplicationId", entity.ApplicationId),
                new SqlParameter("VersionCode",   entity.VersionCode),
                new SqlParameter("AppFileName",   entity.AppFileName),
                new SqlParameter("AppDirectory",  entity.AppDirectory),
                new SqlParameter("AppSize",       entity.AppSize),
                new SqlParameter("Remark",        entity.Remark),
                new SqlParameter("CreateBy",      entity.CreateBy),
                new SqlParameter("CreateTime",    entity.CreateTime)
            };
            int result = SqlHelper.ExecuteNonQuery(sqlStr, parameter);

            if (result == 1)
            {
                msg.data    = "";
                msg.state   = "success";
                msg.message = "新增成功!";

                #region ===========记录操作日志=============
                C_S_Log log = new C_S_Log()
                {
                    OperateType     = 0,//上传
                    OperateUserId   = entity.CreateBy,
                    ApplicationId   = entity.ApplicationId,
                    Content         = "上传应用",
                    ApplicationCode = "",
                    IPAddress       = Net.Ip,
                    MachineName     = Net.Host
                };

                if (dt.Rows.Count > 0)
                {
                    log.ApplicationCode = dt.Rows[0]["ApplicationCode"].ToString();
                }

                CSLog_BLL.Add(log);
                #endregion =================================
            }
            else
            {
                msg.data    = "";
                msg.state   = "error";
                msg.message = "新增失败!";
            }
            return(msg);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="appVersionId"></param>
        /// <returns></returns>
        public AjaxResult Delete(string appVersionId)
        {
            AjaxResult msg = new AjaxResult();

            try
            {
                string         sqlStr1   = "select * from C_S_AppVersion where AppVersionId = @AppVersionId";
                SqlParameter[] parameter = { new SqlParameter("AppVersionId", appVersionId) };
                DataTable      dt        = SqlHelper.ExecuteDataTable(sqlStr1, parameter);

                if (dt.Rows.Count > 0)
                {
                    string applicationId = dt.Rows[0]["ApplicationId"].ToString();


                    DataTable dt_app = SqlHelper.ExecuteDataTable("select * from C_S_Application where ApplicationId = @ApplicationId", new SqlParameter[] { new SqlParameter("ApplicationId", applicationId) });

                    //先删除版本文件数据再删除应用版本数据
                    string sqlStr = @"delete C_S_VersionFile where AppVersionId = @AppVersionId
                                      ;delete C_S_AppVersion where AppVersionId = @AppVersionId";

                    string path = dt.Rows[0]["AppDirectory"].ToString();

                    SqlParameter[] parameter1 = { new SqlParameter("AppVersionId", appVersionId) };

                    int result = SqlHelper.ExecuteNonQuery(sqlStr, parameter1);

                    if (result > 0)
                    {
                        msg.data    = "";
                        msg.state   = "success";
                        msg.message = "删除成功!";

                        #region ===========记录操作日志=================
                        C_S_Log log = new C_S_Log()
                        {
                            OperateType     = 3,//移除
                            OperateUserId   = OperatorProvider.Provider.GetCurrent().UserName,
                            ApplicationId   = applicationId,
                            Content         = "删除版本",
                            ApplicationCode = "",
                            IPAddress       = Net.Ip,
                            MachineName     = Net.Host
                        };

                        if (dt.Rows.Count > 0)
                        {
                            log.ApplicationCode = dt_app.Rows[0]["ApplicationCode"].ToString();
                        }
                        CSLog_BLL.Add(log);
                        #endregion ======================================
                    }
                    else
                    {
                        msg.data    = "";
                        msg.state   = "error";
                        msg.message = "删除失败!";
                    }
                }
                else
                {
                    msg.data    = "";
                    msg.state   = "success";
                    msg.message = "已删除";
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                msg.data    = "";
                msg.state   = "error";
                msg.message = "删除失败,程序发生异常!";
            }

            return(msg);
        }