本文整理汇总了C#中Connector.Query_Scalar_Parameters方法的典型用法代码示例。如果您正苦于以下问题:C# Connector.Query_Scalar_Parameters方法的具体用法?C# Connector.Query_Scalar_Parameters怎么用?C# Connector.Query_Scalar_Parameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connector
的用法示例。
在下文中一共展示了Connector.Query_Scalar_Parameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: pageArticles_Images_Upload
public static void pageArticles_Images_Upload(ref StringBuilder content, string pluginid, Connector conn, ref Misc.PageElements pageElements, HttpRequest request, HttpResponse response, bool permCreate)
{
// Upload an image
// -- Ensure the user has creation permissions, else we'll 404
if (!permCreate) return;
string error = null;
HttpPostedFile image = request.Files["image"];
string title = request.Form["title"];
string captcha = request.Form["captcha"];
// Check for postback
if (title != null && captcha != null && image != null)
{
// Validate
if (!Common.Validation.validCaptcha(captcha))
error = "Incorrect captcha verification code, please try again!";
else if (title.Length < Core.settings[SETTINGS_KEY].getInt(SETTINGS_IMAGES_TITLE_MIN) || title.Length > Core.settings[SETTINGS_KEY].getInt(SETTINGS_TITLE_MAX))
error = "Title must be between " + Core.settings[SETTINGS_KEY][SETTINGS_TITLE_MIN] + " to " + Core.settings[SETTINGS_KEY][SETTINGS_IMAGES_TITLE_MAX] + " characters in length!";
else if (image.ContentLength == 0)
error = "The uploaded image contains no data, please try again!";
else if (image.ContentLength > Core.settings[SETTINGS_KEY].getInt(SETTINGS_IMAGES_MAXSIZE))
error = "The uploaded image is too large - maximum size allowed is " + Misc.Plugins.getBytesString(Core.settings[SETTINGS_KEY].getLong(SETTINGS_IMAGES_MAXSIZE)) + "!";
else if (!Core.settings[SETTINGS_KEY].getCommaArrayContains(SETTINGS_IMAGE_TYPES, image.ContentType))
error = "Invalid image type - ensure you've uploaded an actual image!";
else
{
// Compress the image data for database storage
byte[] imageData = compressImageData(image.InputStream, Core.settings[SETTINGS_KEY].getInt(SETTINGS_IMAGES_MAXWIDTH), Core.settings[SETTINGS_KEY].getInt(SETTINGS_IMAGES_MAXHEIGHT));
if (imageData == null)
error = "Failed to process image - please try your request again or ensure the uploaded image is not corrupt!";
else
{
// Write the data to the database
Dictionary<string, object> imageParams = new Dictionary<string, object>();
imageParams.Add("title", title);
imageParams.Add("userid", HttpContext.Current.User.Identity.Name);
imageParams.Add("data", imageData);
string imageid = conn.Query_Scalar_Parameters("INSERT INTO articles_images (title, userid, data, datetime) VALUES(@title, @userid, @data, NOW()); SELECT LAST_INSERT_ID();", imageParams).ToString();
// Redirect the user to view the image
conn.Disconnect();
response.Redirect(pageElements["URL"] + "/articles/images/view/" + imageid);
}
}
}
// Output form
content.Append(
Core.templates["articles"]["image_uploader"]
.Replace("<ERROR>", error != null ? Core.templates[pageElements["TEMPLATE"]]["error"].Replace("<ERROR>", error) : string.Empty)
.Replace("<TITLE>", HttpUtility.HtmlEncode(title))
);
pageElements["TITLE"] = "Articles - Image Store - Upload";
}
示例2: pageArticle_Editor
/// <summary>
/// Used to create/modify an article.
/// </summary>
/// <param name="pluginid"></param>
/// <param name="conn"></param>
/// <param name="pageElements"></param>
/// <param name="request"></param>
/// <param name="response"></param>
public static void pageArticle_Editor(string pluginid, Connector conn, ref Misc.PageElements pageElements, HttpRequest request, HttpResponse response)
{
// Check the user is logged-in, else redirect to the login page
if (!HttpContext.Current.User.Identity.IsAuthenticated)
response.Redirect(pageElements["URL"] + "/login", true);
// Load the users permissions and check they're able to create articles
Result perms = conn.Query_Read("SELECT ug.access_media_create, ug.access_media_publish, ug.access_media_edit, ug.access_admin FROM bsa_users AS u LEFT OUTER JOIN bsa_user_groups AS ug ON ug.groupid=u.groupid WHERE u.userid='" + Utils.Escape(HttpContext.Current.User.Identity.Name) + "'");
if (perms.Rows.Count != 1 || !perms[0]["access_media_create"].Equals("1")) return;
bool permAdmin = perms[0]["access_admin"].Equals("1");
bool permEdit = perms[0]["access_media_edit"].Equals("1");
bool permPublish = perms[0]["access_media_publish"].Equals("1");
string error = null;
Result preData = null;
ResultRow preDataRow = null;
// Check if we're modifying an existing article, if so we'll load the data
string articleid = request.QueryString["articleid"];
if (articleid != null && Misc.Plugins.isNumeric(articleid))
{
// Attempt to load the pre-existing article's data
preData = conn.Query_Read("SELECT a.*, at.relative_url, at.pdf_name, GROUP_CONCAT(at2.keyword SEPARATOR ',') AS tags FROM articles AS a LEFT OUTER JOIN articles_tags AS at2 ON (EXISTS (SELECT tagid FROM articles_tags_article WHERE tagid=at2.tagid AND articleid='" + Utils.Escape(articleid) + "')) LEFT OUTER JOIN articles_thread AS at ON at.threadid=a.threadid WHERE articleid='" + Utils.Escape(articleid) + "'");
if (preData.Rows.Count != 1) preData = null;
else
preDataRow = preData[0];
}
// Check for postback
string title = request.Form["title"];
string body = request.Form["body"];
string relativeUrl = request.Form["relative_url"] ?? request.QueryString["relative_url"];
string tags = request.Form["tags"];
bool allowHTML = request.Form["allow_html"] != null;
bool allowComments = request.Form["allow_comments"] != null;
bool showPane = request.Form["show_pane"] != null;
bool inheritThumbnail = request.Form["inherit_thumbnail"] != null;
bool updateExisting = request.Form["update_existing"] != null;
HttpPostedFile thumbnail = request.Files["thumbnail"];
if (title != null && body != null && relativeUrl != null && tags != null)
{
// Validate
if (title.Length < Core.settings[SETTINGS_KEY].getInt(SETTINGS_TITLE_MIN) || title.Length > Core.settings[SETTINGS_KEY].getInt(SETTINGS_TITLE_MAX))
error = "Title must be " + Core.settings[SETTINGS_KEY][SETTINGS_TITLE_MIN] + " to " + Core.settings[SETTINGS_KEY][SETTINGS_TITLE_MAX] + " characters in length!";
else if (body.Length < Core.settings[SETTINGS_KEY].getInt(SETTINGS_BODY_MIN) || body.Length > Core.settings[SETTINGS_KEY].getInt(SETTINGS_BODY_MAX))
error = "Body must be " + Core.settings[SETTINGS_KEY][SETTINGS_BODY_MIN] + " to " + Core.settings[SETTINGS_KEY][SETTINGS_BODY_MAX] + " characters in length!";
else if (body.Replace(" ", string.Empty).Length == 0)
error = "Body cannot be empty/contain just spaces!";
else if (thumbnail != null && thumbnail.ContentLength > 0 && thumbnail.ContentLength > Core.settings[SETTINGS_KEY].getInt(SETTINGS_THUMBNAIL_MAXSIZE))
error = "Thumbnail cannot exceed " + Core.settings[SETTINGS_KEY][SETTINGS_THUMBNAIL_MAXSIZE] + " bytes (" + Misc.Plugins.getBytesString(Core.settings[SETTINGS_KEY].getInt(SETTINGS_THUMBNAIL_MAXSIZE)) + ")!";
else if (thumbnail != null && thumbnail.ContentLength > 0 && !Core.settings[SETTINGS_KEY].getCommaArrayContains(SETTINGS_IMAGE_TYPES, thumbnail.ContentType))
error = "Invalid thumbnail image format - ensure you uploaded an image!";
else if ((error = validRelativeUrl(relativeUrl, Core.settings[SETTINGS_KEY].getInt(SETTINGS_RELATIVE_URL_MAXCHUNKS), Core.settings[SETTINGS_KEY].getInt(SETTINGS_RELATIVE_URL_CHUNK_MIN), Core.settings[SETTINGS_KEY].getInt(SETTINGS_RELATIVE_URL_CHUNK_MAX))) != null)
;
else
{
// Verify the user has not exceeded post limits for today - unless they're admin, we'll just skip the checks
ResultRow postLimits = permAdmin ? null : conn.Query_Read("SELECT (SELECT COUNT('') FROM articles WHERE userid='" + Utils.Escape(HttpContext.Current.User.Identity.Name) + "' AND datetime >= DATE_SUB(NOW(), INTERVAL 1 HOUR)) AS articles_hour, (SELECT COUNT('') FROM articles WHERE userid='" + Utils.Escape(HttpContext.Current.User.Identity.Name) + "' AND datetime >= DATE_SUB(NOW(), INTERVAL 1 DAY)) AS articles_day")[0];
if (postLimits != null && int.Parse(postLimits["articles_hour"]) >= Core.settings[SETTINGS_KEY].getInt(SETTINGS_ARTICLES_EDIT_PER_HOUR))
error = "You've already posted the maximum amount of articles allowed within an hour, please try again later!";
else if (postLimits != null && int.Parse(postLimits["articles_day"]) >= Core.settings[SETTINGS_KEY].getInt(SETTINGS_ARTICLES_EDIT_PER_DAY))
error = "You've already posted the maximum amount of articles allowed today, please try again later!";
else
{
// Verify tags
ArticleTags parsedTags = getTags(tags, Core.settings[SETTINGS_KEY].getInt(SETTINGS_TAGS_TITLE_MIN), Core.settings[SETTINGS_KEY].getInt(SETTINGS_TAGS_TITLE_MAX), Core.settings[SETTINGS_KEY].getInt(SETTINGS_TAGS_MAX));
if (parsedTags.error != null) error = parsedTags.error;
else
{
// Check if we're inserting, else perhaps inheriting, a thumbnail
string thumbnailid = null;
if (thumbnail != null && thumbnail.ContentLength > 0)
{
byte[] imageData = compressImageData(thumbnail.InputStream, Core.settings[SETTINGS_KEY].getInt(SETTINGS_THUMBNAIL_MAXWIDTH), Core.settings[SETTINGS_KEY].getInt(SETTINGS_THUMBNAIL_MAXHEIGHT));
if (imageData != null)
{
// Success - insert thumbnail and get thumbnailid
Dictionary<string, object> thumbParams = new Dictionary<string, object>();
thumbParams.Add("thumb", imageData);
thumbnailid = conn.Query_Scalar_Parameters("INSERT INTO articles_thumbnails (data) VALUES(@thumb); SELECT LAST_INSERT_ID();", thumbParams).ToString();
}
else
error = "Failed to process thumbnail image, please try again or report this to the site administrator!";
}
else if (inheritThumbnail && preDataRow != null && preDataRow["thumbnailid"].Length != 0)
{
// Grab pre-existing thumbnailid
thumbnailid = preDataRow["thumbnailid"];
}
// Ensure no thumbnail processing errors occur, else do not continue
if (error == null)
{
// Format the body formatting for caching
StringBuilder cached = new StringBuilder(body);
//.........这里部分代码省略.........