using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class manage_memberspayadd : System.Web.UI.Page
{
    public static Int32 memid, serid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sql0 = "select * from service";
            DropDownList1.DataSource = oper.dt(sql0);
            DropDownList1.DataTextField = "stitle";
            DropDownList1.DataValueField = "sid";
            DropDownList1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sql0 = "select count(*) from members where mname='" + TextBox1.Text + "'";
        if (oper.isfind(sql0))
        {
            Panel1.Visible = true;
            lblerror.Visible = false;
            string sql1 = "select * from members where mname='" + TextBox1.Text + "'";
            DataRow dr = oper.dr(sql1);
            memid = Convert.ToInt32(dr["mid"].ToString());
            Label1.Text = dr["mname"].ToString();
            Label2.Text = dr["mcartype"].ToString();
            Label3.Text = dr["mcarno"].ToString();
            Label4.Text = dr["mmoney"].ToString();
            Image1.ImageUrl = "../" + dr["mcarpic"].ToString();
        }
        else
        {
            Panel1.Visible = false;
            lblerror.Visible = true;
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        serid=Convert.ToInt32(DropDownList1.SelectedValue);
        string sql2 = "select * from service where sid=" + serid;
        DataRow dr = oper.dr(sql2);
        Label5.Text = dr["stitle"].ToString();
        Label6.Text = dr["sprice"].ToString();
    }
    protected void btnok_Click(object sender, EventArgs e)
    {
        string sql3 = "insert into pays(serid,memid,pcheap) values(" + serid + "," + memid + "," + Convert.ToInt32(TextBox2.Text) + ")";
        Int32 pmoney=Convert.ToInt32(Label6.Text)-Convert.ToInt32(TextBox2.Text);
        string sql4 = "update members set mmoney=mmoney-" + pmoney + " where mid=" + memid;
        oper.opertb(sql3);
        oper.opertb(sql4);
        Response.Redirect("memberspayadd.aspx");
    }
}
