Ejemplo n.º 1
0
        public bool CheckUserIden(int UserId, String SessionKey)
        {
            try
            {
                new Guid(SessionKey);
            }
            catch (Exception ex)
            {
                ex.ToString();
                return(false);
            }
            DbHelper _helper  = new DbHelper("CPOrganIns", CPAppContext.CurDbType());
            string   strSql   = " SELECT UserId FROM CP_UserIdentity WHERE UserKey='" + SessionKey + "'";
            object   userIdDb = _helper.ExecuteScalar(strSql);

            if (Convert.IsDBNull(userIdDb) || userIdDb == null)
            {
                return(false);
            }
            else
            {
                if (int.Parse(userIdDb.ToString()).Equals(UserId))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 2
0
        public static HttpContext GetHttpContext()
        {
            object factory = CPAppContext.GetService(typeof(Microsoft.AspNetCore.Http.IHttpContextAccessor));

            Microsoft.AspNetCore.Http.HttpContext context = ((Microsoft.AspNetCore.Http.HttpContextAccessor)factory).HttpContext;
            return(context);
        }
Ejemplo n.º 3
0
        public override int GetMaxAutoIndex(CPAutoNum auto)
        {
            DbHelper _db = new DbHelper(auto.FormDbIns, CPAppContext.CurDbType());

            if (CPAppContext.CurDbType() == DbHelper.DbTypeEnum.SqlServer)
            {
                string strSql = @"SELECT ISNULL(MAX(" + auto.FormAumField + @"),0)   FROM dbo." + auto.FormTableName;
                if (auto.FormAutoYearSplit.Value)
                {
                    strSql += " WHERE " + auto.FormYearField + "=" + DateTime.Now.Year;
                    if (string.IsNullOrEmpty(auto.FormDataSearch) == false)
                    {
                        strSql += "  AND (" + CPExpressionHelper.Instance.RunCompile(auto.FormDataSearch) + " ) ";
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(auto.FormDataSearch) == false)
                    {
                        strSql += "  WHERE (" + CPExpressionHelper.Instance.RunCompile(auto.FormDataSearch) + " ) ";
                    }
                }
                int NextAutoNum = Convert.ToInt32(_db.ExecuteScalar(strSql));
                return(NextAutoNum);
            }
            else
            {
                throw new Exception("未实现");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="userName">用户姓名</param>
        /// <param name="device">设备类型</param>
        /// <param name="operRemark">日志内容</param>
        /// <param name="operType">日志类型</param>
        /// <returns></returns>
        public bool AddLog(int userId, string userName, CPEnum.DeviceTypeEnum device, string operRemark, string operType)
        {
            CPLog log = new CPLog();

            log.UserId     = userId;
            log.UserName   = userName;
            log.OperTime   = DateTime.Now;
            log.OperDevice = device;
            log.OperRemark = operRemark;
            log.OperType   = operType;
            log.OperIP     = "";
            try
            {
                //获取操作IP
                log.OperIP = CPAppContext.GetClientIP();
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            log.OperUrl = "";
            try
            {
                //获取办理页面地址
                log.OperUrl = CPAppContext.GetHttpContext().Request.Path;
            }
            catch (Exception ex)
            {
            }
            return(this._CPLogRep.Add(log) > 0 ? true : false);
        }
Ejemplo n.º 5
0
        public FileResult DownloadAutoConfig(string AutoIds, int CurUserId, string CurUserIden)
        {
            base.SetHeader();
            CurUserIden = CPAppContext.FormatSqlPara(CurUserIden);
            CPWebApiBaseReturnEntity re = new CPWebApiBaseReturnEntity();

            if (this.CheckUserIden(CurUserId, CurUserIden) == false)
            {
                throw new Exception("系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!");
            }
            AutoIds = AutoIds.Replace("@", ",");
            AutoIds = CPAppContext.FormatSqlPara(AutoIds);
            List <int> col = new List <int>();

            AutoIds.Split(',').ToList().ForEach(t => {
                if (string.IsNullOrEmpty(t) == false)
                {
                    col.Add(int.Parse(t));
                }
            });
            string sXml = CPAutoNumHelper.Instance().GetAutoConfigXml(col);

            byte[] byteArray = System.Text.Encoding.Default.GetBytes(sXml);
            return(File(byteArray, "application/x-msdownload", "自动编号配置.CPXml"));
        }
Ejemplo n.º 6
0
 public void SetGlobalViewBag()
 {
     ViewBag.CPSkin         = "Default";
     ViewBag.CPWebRootPath  = "<script>var CPWebRootPath = \"" + CPAppContext.CPWebRootPath() + "\";</script>";
     ViewBag.CPCurUserId    = "<script>var CPCurUserId = \"" + CPExpressionHelper.Instance.RunCompile("${CPUser.UserId()}") + "\";</script>";
     ViewBag.CPCurUserIden  = "<script>var CPCurUserIden = \"" + CPExpressionHelper.Instance.RunCompile("${CPUser.UserIden()}") + "\";</script>";
     ViewBag.CPWebRootPath2 = CPAppContext.CPWebRootPath();
 }
Ejemplo n.º 7
0
        public string GetDbName([CPName("数据库链接实例")] string ins)
        {
            DbHelper _helper = new DbHelper(ins, CPAppContext.CurDbType());
            string   db      = _helper.GetConnection().Database;

            _helper = null;
            return(db);
        }
Ejemplo n.º 8
0
        public string UserAdminSysIds()
        {
            string UserAdminSysIds = CPAppContext.GetHttpContext().Session.GetString("UserAdminSysIds");

            if (string.IsNullOrEmpty(UserAdminSysIds))
            {
                return("");
            }
            else
            {
                return(UserAdminSysIds);
            }
        }
Ejemplo n.º 9
0
        public string DepNames()
        {
            string DepNames = CPAppContext.GetHttpContext().Session.GetString("DepNames");

            if (string.IsNullOrEmpty(DepNames))
            {
                return("");
            }
            else
            {
                return(DepNames);
            }
        }
Ejemplo n.º 10
0
        public string Session([CPName("Key")] string key)
        {
            string s = CPAppContext.GetHttpContext().Session.GetString(key);

            if (string.IsNullOrEmpty(s))
            {
                return("");
            }
            else
            {
                return(s);
            }
        }
Ejemplo n.º 11
0
        public string UserRoleNames()
        {
            string RoleNames = CPAppContext.GetHttpContext().Session.GetString("RoleNames");

            if (string.IsNullOrEmpty(RoleNames))
            {
                return("");
            }
            else
            {
                return(RoleNames);
            }
        }
Ejemplo n.º 12
0
        public string UserLoginName()
        {
            string UserLoginName = CPAppContext.GetHttpContext().Session.GetString("UserLoginName");

            if (string.IsNullOrEmpty(UserLoginName))
            {
                return("");
            }
            else
            {
                return(UserLoginName);
            }
        }
Ejemplo n.º 13
0
        public string UserPhotoPath()
        {
            string UserPhotoPath = CPAppContext.GetHttpContext().Session.GetString("UserPhotoPath");

            if (string.IsNullOrEmpty(UserPhotoPath))
            {
                return("");
            }
            else
            {
                return(UserPhotoPath);
            }
        }
Ejemplo n.º 14
0
        public string UserIden()
        {
            string UserKey = CPAppContext.GetHttpContext().Session.GetString("UserKey");

            if (string.IsNullOrEmpty(UserKey))
            {
                return("");
            }
            else
            {
                return(UserKey);
            }
        }
Ejemplo n.º 15
0
        public int UserId()
        {
            string UserId = CPAppContext.GetHttpContext().Session.GetString("UserId");

            if (string.IsNullOrEmpty(UserId))
            {
                return(0);
            }
            else
            {
                return(int.Parse(UserId));
            }
        }
Ejemplo n.º 16
0
 public void SetHeader()
 {
     try
     {
         //增加设置允许跨域访问,否则会导致如果直接把HTML放入手机里时,会导致不能访问数据的问题
         CPAppContext.GetHttpContext().Response.Headers.Add("Access-Control-Allow-Origin", "*");                              //允许哪些url可以跨域请求到本域
         CPAppContext.GetHttpContext().Response.Headers.Add("Access-Control-Allow-Methods", "POST");                          //允许的请求方法,一般是GET,POST,PUT,DELETE,OPTIONS
         CPAppContext.GetHttpContext().Response.Headers.Add("Access-Control-Allow-Headers", "x-requested-with,content-type"); //允许哪些请求头可以跨域
     }
     catch (Exception ex)
     {
         ex.ToString();
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取客户端IP
        /// </summary>
        public static string GetClientIP()
        {
            try
            {
                object factory = CPAppContext.GetService(typeof(Microsoft.AspNetCore.Http.IHttpContextAccessor));

                Microsoft.AspNetCore.Http.HttpContext context = ((Microsoft.AspNetCore.Http.HttpContextAccessor)factory).HttpContext;

                var ip = context.Features.Get <IHttpConnectionFeature>()?.RemoteIpAddress?.ToString();
                return(ip);
            }
            catch (Exception)
            {
                return("未获取用户IP");
            }
        }
Ejemplo n.º 18
0
        public static bool CheckHasQueryStringKey(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(false);
            }

            if (CPAppContext.GetHttpContext().Request.Query.Keys.Contains(key) == false)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 19
0
        public CPWebApiBaseReturnEntity SynAutoConfig(int TargetSysId, bool IsCreateNew, int CurUserId, string CurUserIden)
        {
            base.SetHeader();
            CurUserIden = CPAppContext.FormatSqlPara(CurUserIden);
            CPWebApiBaseReturnEntity re = new CPWebApiBaseReturnEntity();

            if (this.CheckUserIden(CurUserId, CurUserIden) == false)
            {
                re.Result   = false;
                re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                return(re);
            }
            var files = Request.Form.Files;

            foreach (var file in files)
            {
                //  var filename = ContentDispositionHeaderValue
                //                   .Parse(file.ContentDisposition)
                //                .FileName
                //                .Trim('"');
                ////  filename = _FilePath + $@"\{filename}";
                //  size += file.Length;
                byte[] bData = null;
                using (var fileStream = file.OpenReadStream())
                    using (var ms = new MemoryStream())
                    {
                        fileStream.CopyTo(ms);
                        bData = ms.ToArray();
                        //var fileBytes = ms.ToArray();
                        //string s = Convert.ToBase64String(fileBytes);
                        //// act on the Base64 data
                    }
                if (bData != null)
                {
                    if (IsCreateNew)
                    {
                        re.Result = CPAutoNumHelper.Instance().InitAutoFromConfigXml(TargetSysId, bData);
                    }
                    else
                    {
                        re.Result = CPAutoNumHelper.Instance().SyncAutoFromConfigXml(TargetSysId, bData);
                    }
                }
            }
            re.Result = true;
            return(re);
        }
Ejemplo n.º 20
0
        public string QueryString([CPName("参数key")] string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return("");
            }

            object obj = CPAppContext.GetHttpContext().Request.Query[key];

            if (obj == null)
            {
                return("");
            }
            else
            {
                return(obj.ToString());
            }
        }
Ejemplo n.º 21
0
        public override DataSet GetConfig(List <int> gridIdCol)
        {
            string ids = "";

            gridIdCol.ForEach(t => {
                if (string.IsNullOrEmpty(ids))
                {
                    ids = t.ToString();
                }
                else
                {
                    ids += "," + t.ToString();
                }
            });
            DbHelper _helper = new DbHelper("CPCommonIns", CPAppContext.CurDbType());
            string   strSql  = "SELECT * FROM CP_AutoNum WHERE AutoId in(" + ids + ")";
            DataSet  ds      = _helper.ExecuteDataSet(strSql);

            ds.Tables[0].TableName = "CP_AutoNum";
            return(ds);
        }
Ejemplo n.º 22
0
 public string CPWebRootPath()
 {
     return(CPAppContext.CPWebRootPath());
 }
Ejemplo n.º 23
0
        public override bool SyncConfigFromDataSet(int targetSysId, DataSet ds, bool isCreateNew)
        {
            DbHelper _helper = new DbHelper("CPCommonIns", CPAppContext.CurDbType());

            bool b = true;

            #region 先删除数据
            if (isCreateNew == false)
            {
                string delCodes = "";
                foreach (DataRow drMain in ds.Tables["CP_AutoNum"].Rows)
                {
                    if (string.IsNullOrEmpty(delCodes))
                    {
                        delCodes = drMain["AutoCode"].ToString();
                    }
                    else
                    {
                        delCodes += "," + drMain["AutoCode"].ToString();
                    }
                }
                if (string.IsNullOrEmpty(delCodes) == false)
                {
                    string delSql = @"DELETE FROM CP_AutoNum WHERE     AutoCode IN ('" + delCodes.Replace(",", "','") + @"')";
                    _helper.ExecuteNonQuery(delSql);
                    if (!b)
                    {
                        throw new Exception("先删除已经存在的配置时出错");
                    }
                }
            }
            #endregion

            #region 写入数据
            SqlCommand cmd = new SqlCommand(@"SELECT * FROM CP_AutoNum WHERE 1=2",
                                            _helper.GetConnection() as SqlConnection);
            SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
            // SqlCommandBuilder builder = new SqlCommandBuilder(da);
            //AddWithKey: 自动填充数据表结构,如:主键和限制
            //预设值Add,不填充结构
            da.MissingSchemaAction = MissingSchemaAction.AddWithKey;//Default Value is: Add
            DataSet dsStruct = new DataSet();
            da.Fill(dsStruct);
            dsStruct.Tables[0].TableName = "CP_AutoNum";
            #region CP_AutoNum
            foreach (DataRow dr in ds.Tables["CP_AutoNum"].Rows)
            {
                dr["SysId"] = targetSysId;
                if (isCreateNew)
                {
                    dr["AutoName"] = dr["AutoName"].ToString() + "_副本";
                    dr["AutoCode"] = dr["AutoCode"].ToString() + "_副本";
                }
                string insertSql = CPAppContext.GetInsertSql("CP_AutoNum", dsStruct.Tables["CP_AutoNum"].Columns, dr);

                SqlCommand cmdInsert = new SqlCommand(insertSql, _helper.GetConnection() as SqlConnection);
                foreach (DataColumn dc in dsStruct.Tables["CP_AutoNum"].Columns)
                {
                    if (dc.AutoIncrement)
                    {
                        continue;
                    }
                    if (dr.Table.Columns.Contains(dc.ColumnName))
                    {
                        cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, dr[dc.ColumnName]);
                    }
                    else
                    {
                        cmdInsert.Parameters.AddWithValue("@" + dc.ColumnName, DBNull.Value);
                    }
                }
                _helper.ExecuteNonQuery(cmdInsert);
            }

            #endregion

            #endregion
            return(b);
        }
Ejemplo n.º 24
0
 public static CPAutoNumHelper Instance()
 {
     return(CPAppContext.GetService <CPAutoNumHelper>());
 }