Пример #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);
                }
            }
        }
Пример #2
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("未实现");
            }
        }
Пример #3
0
        public string GetDbName([CPName("数据库链接实例")] string ins)
        {
            DbHelper _helper = new DbHelper(ins, CPAppContext.CurDbType());
            string   db      = _helper.GetConnection().Database;

            _helper = null;
            return(db);
        }
Пример #4
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);
        }
Пример #5
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);
        }