protected void Page_Load(object sender, EventArgs e) { using (HanDatabase db = new HanDatabase()) { Query = new WordGroupMapping(db); } }
private void LoadUserSession() { using (HanDatabase db = new HanDatabase()) { DataTable result = db.ExecuteQuery( "SELECT SelfLearning, PreferredLanguage FROM vUserInfo WHERE UserID=@UserID", new SqlParameter[] { new SqlParameter("UserID", UserID) } ); if (result.Rows.Count == 1) { DataRow userData = result.Rows[0]; int selfLearning = -1; if (int.TryParse(userData["SelfLearning"].ForceToString(), out selfLearning)) { Session["SelfLearning"] = selfLearning == 1; } string culture = userData["PreferredLanguage"].ForceToString(); if (string.IsNullOrWhiteSpace(culture)) { culture = null; } Session["PreferredLanguage"] = culture; } } }
protected void Page_Init(object sender, EventArgs e) { using (HanDatabase db = new HanDatabase()) { query = new LearningCharacterMapping(db, ((HanLearning.Masters.Site)Master).UserID, "zh-HK"); } }
public void ProcessRequest(HttpContext context) { SetupHandler(context); XmlNode characterNode = Request.SelectSingleNode("query/character"); if (characterNode == null) { WriteError(context, "missing_arg", "Missing character argument"); return; } int utfCode = -1; if (!int.TryParse(characterNode.InnerText, out utfCode)) { WriteError(context, "invalid_arg", "Invalid character"); return; } XmlNode intentNode = Request.SelectSingleNode("query/intent"); if (intentNode == null) { WriteError(context, "missing_arg", "Missing intent argument"); return; } int intent = -1; if (!int.TryParse(intentNode.InnerText, out intent)) { WriteError(context, "invalid_arg", "Invalid intent"); return; } SqlParameter returnCode = new SqlParameter() { Direction = ParameterDirection.ReturnValue }; SqlParameter[] parameters = { new SqlParameter("UserID", context.GetUserID()), new SqlParameter("UTFCode", utfCode), new SqlParameter("Intent", intent), returnCode }; using (HanDatabase db = new HanDatabase()) { db.ExecuteStoredProcedure("spUserLearningUpdate", parameters); } if ((int)returnCode.Value != 0) { WriteError(context, "op_failed", "Operation failed with error code: " + returnCode.Value); return; } Response.Save(context.Response.OutputStream); }
protected void Page_Load(object sender, EventArgs e) { // Build Culture list StringBuilder builder = new StringBuilder(); using (HanDatabase db = new HanDatabase()) { DataTable data = db.ExecuteQuery("SELECT Culture FROM vCultureList ORDER BY Culture DESC"); foreach (DataRow row in data.Rows) { string culture = row["culture"].ForceToString(); builder.AppendFormat("<option value='{0}' {1}>{2}</option>", culture, culture == PreferredLanguage ? "selected='selected'" : "", GetGlobalResourceObject("Literals", culture)); } } cultureOptions.Controls.Add(new LiteralControl(builder.ToString())); }
protected void Page_PreLoad(object sender, EventArgs e) { if (IsPostBack) { SqlParameter userID = new SqlParameter("UserID", SqlDbType.Int) { Direction = ParameterDirection.Output }; SqlParameter returnCode = new SqlParameter() { Direction = ParameterDirection.ReturnValue }; SqlParameter[] parameters = { new SqlParameter("Username", username.Text), new SqlParameter("Password", password.Text), userID, returnCode }; using (HanDatabase db = new HanDatabase()) { db.ExecuteStoredProcedure("spUserLogin", parameters); } state = (LoginState)returnCode.Value; if (state == LoginState.Success) { Session["UserID"] = userID.Value; Response.Redirect("/Dictionary/"); } } }
public void ProcessRequest(HttpContext context) { // process request XmlDocument request = new XmlDocument(); try { request.Load(context.Request.InputStream); } catch (XmlException) { return; } XmlNode cultureNode = request.SelectSingleNode("/query/culture"); if (cultureNode == null) { return; } HashSet <int> chars = new HashSet <int>(); foreach (XmlNode node in request.SelectNodes("/query/chars/*")) { int utf = -1; if (int.TryParse(node.InnerText, out utf)) { chars.Add(utf); } } // create response XmlDocument doc = new XmlDocument(); XmlElement charList = doc.CreateElement("characters"); doc.AppendChild(charList); using (HanDatabase db = new HanDatabase()) { CharacterLookupMapping query = new CharacterLookupMapping(db, chars, cultureNode.InnerText, context.Session.GetSessionInt("UserID", 0)); foreach (CharacterData charData in query.Characters.Values) { //write character information XmlElement charElement = doc.CreateElement("character"); charElement.SetAttribute("utf", charData.UTFCode.ToString()); charList.AppendChild(charElement); //write readings information XmlElement readingsElement = doc.CreateElement("readings"); charElement.AppendChild(readingsElement); foreach (CharacterReading reading in charData.Readings) { XmlElement readingElement = doc.CreateElement("reading"); readingElement.InnerText = reading.Reading; readingElement.SetAttribute("source", reading.Source); readingElement.SetAttribute("culture", reading.Culture); readingElement.SetAttribute("system", reading.System); readingsElement.AppendChild(readingElement); } XmlElement definitionsElement = doc.CreateElement("definitions"); charElement.AppendChild(definitionsElement); //write definition information foreach (CharacterDefinition definition in charData.Definitions) { XmlElement defElement = doc.CreateElement("definition"); defElement.InnerText = definition.Definition; defElement.SetAttribute("source", definition.Source); defElement.SetAttribute("culture", definition.Culture); definitionsElement.AppendChild(defElement); } } } context.Response.ContentType = "text/xml"; context.Response.Write(doc.OuterXml); }
protected void Page_Load(object sender, EventArgs e) { // check if postback, no point of continuing if no characters if (!IsPostBack) { return; } // get charset option int parsedcharsetType = 0; VariantType charsetType = VariantType.None; if (int.TryParse(characterSetOption.SelectedValue, out parsedcharsetType)) { charsetType = (VariantType)parsedcharsetType; } // collect character set to query HashSet <int> charset = new HashSet <int>(); foreach (char c in textBlock.Text) { charset.Add(Convert.ToInt32(c)); } //query and render using (HanDatabase db = new HanDatabase()) { CharacterLookupMapping query = new CharacterLookupMapping(db, charset, "zh-HK", ((HanLearning.Masters.Site) this.Master).UserID, charsetType); string[] blocks = textBlock.Text.Split('\n'); StringBuilder sb = new StringBuilder(); foreach (string block in blocks) { foreach (char c in block) { CharacterData data; if (query.Characters.TryGetValue(Convert.ToInt32(c), out data)) { int resultChar = Convert.ToInt32(c); if (charsetType == data.VariantType && data.Variants.Count > 0)// && query.Characters.ContainsKey(data.Variants[0])) { data = query.Characters[data.Variants[0]]; resultChar = data.UTFCode; } if (data.LearningStatus == LearningStatus.Learned) { sb.AppendFormat("<span class=\"learned\">&#{0}</span>", resultChar); } else if (data.LearningStatus == LearningStatus.Learning) { sb.AppendFormat("<span class=\"learning\">&#{0}</span>", resultChar); } else { sb.AppendFormat("<span class=\"not-learned\">&#{0}</span>", resultChar); } } else { sb.Append(c); } } resultArea.Controls.Add(new LiteralControl() { Text = "<p>" + sb.ToString() + "</p>" }); sb.Clear(); } } }
public void ProcessRequest(HttpContext context) { HanDatabase db = new HanDatabase(); }