using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = ConfigurationManager.AppSettings["WebTitle"].ToString() + "--在线订单";
    }
    //保存订单
    public int InsertOrder(string sTitle, string sContent, string sLxr, string sLxdh, string sLxdw)
    {
        int nResult = -1;
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MYCONNECTIONSTRING"].ConnectionString);
        string cmdText = "INSERT INTO Myorder(Title,Content,Lxr,Lxdh,Lxdw,Createdate) VALUES('" +
            sTitle + "','" +
            sContent + "','" +
            sLxr + "','" +
            sLxdh + "','" +
            sLxdw + "',GetDate())";
        SqlCommand myCommand = new SqlCommand(cmdText, myConnection);
        try
        {
            myConnection.Open();
            nResult = myCommand.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myConnection.Close();
        }
        return nResult;
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string title = txtTitle.Text.Trim().ToString();
        string content = txtContent.Text.ToString();
        string lxr = txtName.Text.ToString();
        string lxdh = txtPhone.Text.ToString();
        string lxdw = txtDanwei.Text.ToString();
        if (title.Length < 2 || content.Length < 2 || lxr.Length < 2 || lxdh.Length < 2)
        {
            lblNote.Text = "必填的项目必须认真填写，以便及时联系！";
            return;
        }
        int nResult = InsertOrder(title, content, lxr, lxdh, lxdw);
        if (nResult == 1)
        {
            lblNote.Text = "订单提交成功，我们会在第一时间与你联系，谢谢！";
            clearall();
        }
        else
        {
            lblNote.Text = "订单提交失败！";
        }
    }
    private void clearall()
    {
        txtDanwei.Text = "";
        txtName.Text = "";
        txtPhone.Text = "";
        txtTitle.Text = "";
        txtContent.Text = "";
        
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        clearall();
    }
}
