public partial class Ustop : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnSDemand_Click(object sender, EventArgs e)
{
string connstr = WebConfigurationManager.ConnectionStrings["waterConnectionString"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(connstr);
sqlconn.Open();
SqlCommand sqlcmd = sqlconn.CreateCommand();
sqlcmd.CommandType = CommandType.Text;
sqlcmd.CommandText = "select UserName,Addr,MeterSta,MeterCode from tbMeterUser where UserCode='" + this.TxtUCode.Text.Trim() + "'";
SqlDataReader sqldr = sqlcmd.ExecuteReader();
while (sqldr.Read())
{
TxtUName.Text = sqldr[0].ToString();
TxtAddr.Text = sqldr[1].ToString();
TxtMSta.Text = sqldr[2].ToString();
TxtMCode.Text = sqldr[3].ToString();
}
sqldr.Close();
}
protected void btnReturn_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
protected void BtnStop_Click(object sender, EventArgs e)
{
string usercode = TxtUCode.Text.Trim();
string str1 = "Insert Into tdUserStop(UserCode,Addr,MeterCode,MeterSta,StopDate,SOperator,StopRea) Values(@UserCode,@Addr,@MeterCode,@MeterSta,@StopDate,@SOperator,@StopRea)";
string str2 = "UPDATE tbMeterUser SET MeterSta='报停' WHRE Code='" + usercode + "'";
string str3 = "UPDATE tbMeter SET MeterSta='报停' WHRE Code='" + usercode + "'";
string connstr = WebConfigurationManager.ConnectionStrings["waterConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(str1, conn);
cmd.Parameters.AddWithValue("@UserCode", TxtUCode.Text);
cmd.Parameters.AddWithValue("@Addr", TxtAddr.Text);
cmd.Parameters.AddWithValue("@MeterCode", TxtMCode.Text);
cmd.Parameters.AddWithValue("@MeterSta", TxtMSta.Text);
cmd.Parameters.AddWithValue("@StopDate", TxtSDate.Text);
cmd.Parameters.AddWithValue("@SOperator", TxtSOper.Text);
cmd.Parameters.AddWithValue("@StopRea", TxtSRea.Text);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('success!');</script>");
}
catch (Exception ex)
{
lblPrompt.Text = ex.Message;
}
}
protected void TxtMSta_TextChanged(object sender, EventArgs e)
{
}
protected void TxtSOper_TextChanged(object sender, EventArgs e)
{
}
}
说明:代码里面包括系统的后台数据库的连接,自来水用户具体资料的条件输入查询,然后进行报停业务的操作和存储,以及退出当前界面的功能,同时还有显示报停成功的功能。
水量统计代码设计
图4-2 水量统计模块
public partial class WaterStat : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
try
{
string str1 = "select usercode,sum(ActualWater) MonthActWater from tdwater where 1=1 ";
if (txtTheMonth.Text.Trim().Length != 0)
{
str1 += " and TheMonth='" + txtTheMonth.Text.Trim().ToString() + "'";
}
str1 += "group by UserCode order by usercode ";
string connstr = WebConfigurationManager.ConnectionStrings["waterConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(str1, conn);
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
da.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
GridView1.DataSource = dt;
GridView1.DataBind();
}
catch (Exception ex)
{
ex.ToString();
}
}
protected void btnStat_Click(object sender, EventArgs e)
{
BindData();
}
protected void btnExit_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
protected void btnSum_Click(object sender, EventArgs e)
{
try
{
string str1 = "select sum(ActualWater) MonthActWater from tdwater where 1=1 ";
if (txtTheMonth.Text.Trim().Length != 0)
{
str1 += " and TheMonth='" + txtTheMonth.Text.Trim().ToString() + "'";
}
string connstr = WebConfigurationManager.ConnectionStrings["waterConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connstr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(str1, conn);
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
da.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
DataRow Row = ds.Tables[0].Rows[0];
lblCount.Text = Row["MonthActWater"].ToString();
}
catch (Exception ex)
{
ex.ToString();
}
}
}
说明:代码里面包括用户用水量的分月查询并显示在对应的文本框,然后再对现实的水量进行计算,统计相应的月份用户用水的总量。
管理员名称修改模块代码设计
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>