📄 myreports.asmx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
using System.Configuration;
namespace AWC.Reporter.Web
{
/// <summary>
/// Summary description for MyReports.
/// </summary>
public class MyReports : System.Web.Services.WebService
{
public MyReports()
{
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
/// <summary>
/// Inserts a new report or updates an existing report
/// </summary>
/// <param name="reports">A dataset which has the the report changes</param>
[WebMethod]
public void SaveReports(DataSet reports)
{
OleDbConnection connection = new OleDbConnection();
string sql = null;
connection.ConnectionString = ConfigurationSettings.AppSettings[Constants.CONFIG_OLAP_CONNECT_STRING];
OleDbCommand cmd = new OleDbCommand(sql, connection);
cmd.Connection.Open();
try
{
foreach (DataRow report in reports.Tables[0].Rows)
{
switch (report.RowState)
{
case DataRowState.Added:
// insert
sql = String.Format("INSERT INTO Reports ( Name, [User], ReportDef ) SELECT '{0}', '{1}', '{2}';", report["Name"].ToString(), User.Identity.Name, report["ReportDef"].ToString()); break;
case DataRowState.Modified:
// update
sql = String.Format("UPDATE Reports SET Name = '{0}', [User] = '{1}', ReportDef = '{2}', DateModified = Now() WHERE ReportID = {3};", report["Name"].ToString(), User.Identity.Name, report["ReportDef"].ToString(), report["ReportID"]); break;
case DataRowState.Deleted:
// Delete
sql = String.Format("DELETE FROM Reports WHERE ReportID = {0};", Int32.Parse(report["ReportID", DataRowVersion.Original].ToString())); break;
}
// save the changes
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
}
catch (System.Exception ex)
{
connection.Close();
throw ex;
}
}
/// <summary>
/// Returns the report list as a dataset.
/// </summary>
[WebMethod]
public DataSet GetReports()
{
OleDbConnection connection = new OleDbConnection();
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataSet reports = new DataSet();
string sql = null;
try
{
sql = String.Format("SELECT ReportID, Name, Category, ReportDef FROM Reports WHERE User='anonymous' Or User='{0}' ORDER BY Category, Name", User.Identity.Name);
connection.ConnectionString = ConfigurationSettings.AppSettings[Constants.CONFIG_OLAP_CONNECT_STRING];
OleDbCommand cmd = new OleDbCommand(sql, connection);
adapter.SelectCommand = cmd;
adapter.Fill(reports, "Reports");
return reports;
}
catch (System.Exception ex)
{
throw ex;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -