示例#1
0
文件: Form1.cs 项目: szlfwolf/FZF
		private void btnTosRun_Click(object sender, EventArgs e)
		{
			var ret = MessageBox.Show(ConfigurationManager.ConnectionStrings["OracleConnection"].ToString(), "确认数据库连接", MessageBoxButtons.YesNo);
			if (ret != System.Windows.Forms.DialogResult.Yes) return;
			try
			{
				CM.TOS.V4.Common.TOSFramework.Start();
				Thread.GetDomain().SetData(".appPath", @"c:\Test");
				Thread.GetDomain().SetData(".appVPath", "/");
				TextWriter tw = new StringWriter();
				string address = "http://www.cmhit.com/";
				HttpWorkerRequest wr = new TestWorkerRequest("login.aspx", null, tw, address);
				HttpContext.Current = new HttpContext(wr);

				// 构造 HTTP 调用上下文对象
				HttpContext ctxt = new HttpContext(wr);


				using (CM.CTOS.Common.Core.TosRuntimeContext context = CM.CTOS.Common.Core.TosSessionRuntime.InitializeRuntime(
					CM.CTOS.Utility.LoginUserInfo.TicketIDInitValue,
					"SQL",
					Guid.NewGuid().ToString(),
					"127.0.0.1"))
				{
					using (CM.CTOS.Common.Data.IPsersistenceToken token = CM.CTOS.Common.Core.TosSessionRuntime.CurrentContext.PreparePersistContext())
					{
						CommonDataAccess cda = new CommonDataAccess();
						var db = cda.db;
						var cmd = db.GetSqlStringCommand(this.txtsql.Text);
						int i = cda.TosExecuteNonQuery(cmd);

						token.EndTransaction();

						MessageBox.Show("OK - 执行成功行数:" + i.ToString());
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			finally
			{
				CM.TOS.V4.Common.TOSFramework.End();
			}
		}