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.Net;
using System.Globalization; 

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private void txtCelar()
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox10.Text = "";
        TextBox11.Text = "";
        TextBox12.Text = "";
        TextBox13.Text = "";
        TextBox14.Text = "";
        TextBox15.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        TextBox5.Text = "";
        TextBox6.Text = "";
        TextBox7.Text = "";
        TextBox8.Text = "";
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Label4.Visible = false;
        Label5.Visible = false;

        
        LSC_KhateratDataContext db = new LSC_KhateratDataContext();
        User Add = new User();
        FirstClass sb = new FirstClass();

        DataTable dt1 = new DataTable();
        DataTable dt2 = new DataTable();
        DataTable dt3 = new DataTable();

        dt1 = sb.dbOut(@"SELECT UserName FROM Users WHERE (UserName = N'" + TextBox1.Text + "')");
        dt3 = sb.dbOut(@"SELECT TOP 100 PERCENT EMail1 FROM Users WHERE (EMail1 = N'" + TextBox10.Text + "') ORDER BY EMail1 ");
        if (dt1.Rows.Count <= 0 && dt3.Rows.Count <= 0)
        {
            DateTime dDate = DateTime.Now;
            string strDate = dDate.ToString("h:mm:ss tt");

            string text1 = Dns.GetHostName(), text2;
            text2 = Dns.GetHostByName(text1).AddressList[0].ToString();

           

            Add.UserName = TextBox1.Text.Trim();
            Add.Password = TextBox3.Text.Trim();
            Add.Name = TextBox4.Text.Trim();
            Add.Sname = TextBox5.Text.Trim();
            Add.Phone = TextBox6.Text.Trim();
            Add.Fax = TextBox7.Text.Trim();
            Add.Mobile = TextBox8.Text.Trim();
            Add.EMail1 = TextBox10.Text.Trim();
            Add.WebSite1 = TextBox11.Text.Trim();
            Add.Shahrestan = TextBox12.Text.Trim();
            Add.Ostan = TextBox13.Text.Trim();
            Add.KeshVar = TextBox14.Text.Trim();
            Add.Address = TextBox15.Text.Trim();
            Add.Notes = TextBox2.Text.Trim();
            Add.Banded = Convert.ToBoolean(0);
            Add.UserIP1 = text2;
            Add.RegDate1 = DateTime.Now.Date.ToShortDateString();
            Add.RegTime1 = Convert.ToDateTime(strDate);
            Add.UserTypeID = 3;
            db.Users.InsertOnSubmit(Add);
            db.SubmitChanges();
            txtCelar();
            Panel1.Visible = false;
            Panel2.Visible = true;

        }
        else
        {
            if (dt1.Rows.Count > 0)
            {
                Label4.Visible = true;
                TextBox1.Text = "";
            }
            else if (dt3.Rows.Count > 0)
            {
                Label5.Visible = true;
                TextBox10.Text = "";
            }
        }
        dt1.Clear();
        dt3.Clear();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        txtCelar();
    }
}
