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;

public partial class manage_Inputcontactus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Loginjudge();
        if (!Page.IsPostBack)
        {
            Getcontact();
        }
    }
    private void Getcontact()
    {
        INews shownews = new Mynews();
        SqlDataReader dr = shownews.SqlGetinfo("SELECT Corpname,Myname,Myphone,Myfax,Mymobile,Myemail,Mypost,Myaddress,Mypage FROM Corp");
        if (dr.Read())
        {
            txtCorpname.Text = dr["Corpname"].ToString();
            txtName.Text = dr["Myname"].ToString();
            txtPhone.Text = dr["Myphone"].ToString();
            txtFax.Text = dr["Myfax"].ToString();
            txtMobile.Text = dr["Mymobile"].ToString();
            txtEmail.Text = dr["Myemail"].ToString();
            txtPost.Text = dr["Mypost"].ToString();
            txtAddress.Text = dr["Myaddress"].ToString();
            txtWeb.Text = dr["Mypage"].ToString();
        }
        dr.Close();
    }
    private int Insertcontact(string sCorpname,string sName,string sPhone,string sFax,string sMobile,string sEmail,string sPost,string sAddress,string sPage)
    {
        INews shownews = new Mynews();
        int nResult = -1;        
        nResult = shownews.Executeinfo("UPDATE Corp SET " +
            "Corpname='" + sCorpname + "'," +
            "Myname='" + sName + "'," +
            "Myphone='" + sPhone + "'," +
            "Myfax='" + sFax + "'," +
            "Mymobile='" + sMobile + "'," +
            "Myemail='" + sEmail + "'," +
            "Mypost='" + sPost + "'," +
            "Myaddress='" + sAddress + "'," +
            "Mypage='" + sPage + "'");
        return nResult;

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string corpname = txtCorpname.Text.ToString();
        string name = txtName.Text.ToString();
        string phone = txtPhone.Text.ToString();
        string fax = txtFax.Text.ToString();
        string mobile = txtMobile.Text.ToString();
        string email = txtEmail.Text.ToString();
        string post = txtPost.Text.ToString();
        string address = txtAddress.Text.ToString();
        string web = txtWeb.Text.ToString();
        int nResult=Insertcontact(corpname, name, phone, fax, mobile, email, post,address,web);
        if (nResult == 1)
        {
            lblError.Text = "更新成功！";
        }
        else
        {
            lblError.Text = "更新失败！";
        }
    }
    private void Loginjudge()
    {
        if (Session["Login"] == null)
        {
            Response.Redirect("Error.aspx");
        }
        else
        {
            if (Session["Login"] != "pass")
            {
                Response.Redirect("Error.aspx");
            }

        }
    }
}
