class Membership
اینم فرم اعضا در وب به زبان سی شارپ
Ashiyane
کد PHP:
using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
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 Membership : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.lblSuffix.Visible = this.lblSize.Visible = this.lblMsg.Visible = this.lblEmpty.Visible = false;
Lib.Constr();
SqlDataAdapter sda = new SqlDataAdapter("select * from TCity",Lib.con);
sda.SelectCommand.CommandType = CommandType.Text;
DataSet ds = new DataSet();
sda.Fill(ds,"TCity");
this.ddlCity.DataSource=ds.Tables["TCity"];
this.ddlCity.DataTextField="CityName";
this.ddlCity.DataValueField = "ID";
if (!IsPostBack)
this.ddlCity.DataBind();
}
protected void btnReg_Click(object sender, EventArgs e)
{
if (this.FileUpload1.PostedFile.FileName == "")
{
this.lblEmpty.Visible = true;
return;
}
if (this.FileUpload1.PostedFile.ContentLength > 300 * 1024)
{
this.lblSize.Visible = true;
return;
}
FileInfo fi = new FileInfo(this.FileUpload1.PostedFile.FileName);
if (fi.Extension.ToLower() != ".jpg" && fi.Extension.ToLower() != ".png")
{
this.lblSuffix.Visible = true;
return;
}
string ServerPath = this.Request.PhysicalApplicationPath;
FileStream fs = new FileStream(ServerPath + "Images\\" + fi.Name, System.IO.FileMode.Create);
Stream st = this.FileUpload1.PostedFile.InputStream;
byte[] b = new byte[st.Length];
st.Read(b, 0, b.Length);
fs.Write(b, 0, b.Length);
st.Close();
fs.Close();
SqlCommand cmd = new SqlCommand(@"insert into TMembers(FName,LName,Gender,Email,Website,NationalCode,Tel,BirthDay,
UserName,Password,CityID,MemberImage)values(@fn,@ln,@g,@e,@w,@nc,@t,@bd,@un,@pa,@cid,@img)",Lib.con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@fn", this.tbxName.Text);
cmd.Parameters.AddWithValue("@ln", this.tbxFamily.Text);
cmd.Parameters.AddWithValue("@g", this.rdbGender.SelectedValue);
cmd.Parameters.AddWithValue("@e", this.tbxEmail.Text);
cmd.Parameters.AddWithValue("@w", this.tbxWeb.Text);
cmd.Parameters.AddWithValue("@nc", this.tbxNCode.Text);
cmd.Parameters.AddWithValue("@t", this.tbxTel.Text);
cmd.Parameters.AddWithValue("@bd", this.tbxYear.Text+this.ddlMonth.SelectedValue+this.tbxDay.Text);
cmd.Parameters.AddWithValue("@un", this.tbxUser.Text);
cmd.Parameters.AddWithValue("@pa", this.tbxPass.Text);
cmd.Parameters.AddWithValue("@cid", this.ddlCity.SelectedValue);
cmd.Parameters.AddWithValue("@img", "images/"+fi.Name);
Lib.con.Open();
cmd.ExecuteNonQuery();
Lib.con.Close();
this.lblMsg.Visible = true;
}
}