using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
//该源码首发自www.51aspx.com(５１ａsｐｘ．ｃｏｍ)

public partial class LeaseManage_AddLeaseInfo : System.Web.UI.Page
{
    private static readonly string sqlcmdd = "select * from EMPLOYEE";
	private static readonly string sqlcmd = "insert into EXPENSES (EMP_ID,EXPENSES_PRICE,UES,INSERT_DATE_TIME,MOME)values(@EMP_ID,@EXPENSES_PRICE,@UES,@INSERT_DATE_TIME,@MOME)";

    protected void Page_Load(object sender, EventArgs e)
    {
		DropDownList1.Attributes.Add("OnClick", "bind()");

        if (Convert.ToString(Session["username"]) == "")
        {
            Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
        }
        if(!IsPostBack)
        {
            using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
            {
                sqlconn.Open();
                SqlDataAdapter sa = new SqlDataAdapter(sqlcmdd, sqlconn);
                DataSet ds = new DataSet("EMPLOYEE");
                sa.Fill(ds, "EMPLOYEE");
                DropDownList1.DataSource = ds.Tables["EMPLOYEE"];
                DropDownList1.AutoPostBack = true;
                DropDownList1.DataTextField = "NAME";
                DropDownList1.DataBind();
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = Request["name"];
        string price = Request["price"];
        string ues = Request["ues"];
        string mome = Request["mome"];
		string sqlcmd1 = "select id from dbo.EMPLOYEE where name='"+name+"'";
        using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
        {
            try
            {
                sqlconn.Open();
				SqlCommand cmd = new SqlCommand(sqlcmd1, sqlconn);
				int id = Convert.ToInt32(cmd.ExecuteScalar());
				cmd.CommandText = sqlcmd;
				cmd.Parameters.Add("@EMP_ID", SqlDbType.Int, 10).Value = id;
				cmd.Parameters.Add("@EXPENSES_PRICE", SqlDbType.VarChar, 50).Value = price;
				cmd.Parameters.Add("@UES", SqlDbType.VarChar, 50).Value = ues;
				cmd.Parameters.Add("@INSERT_DATE_TIME", SqlDbType.DateTime).Value = DateTime.Now;
				cmd.Parameters.Add("@MOME", SqlDbType.VarChar, 50).Value = mome;
                cmd.ExecuteNonQuery();
				Response.Write("<script>alert('添加成功');location='ExpenseManage.aspx'</script>");
            }
            catch
            {
				Response.Write("<script>alert('操作失败');location='AddExpenseInfo.aspx'</script>");
            }
        }
    }
}
