using System;
using System.Collections;
using System.Configuration;
using System.Data;
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;
public partial class FrontPage_DeputyManOrder : System.Web.UI.Page
{
SHOP.BLL.BLLDeputyMan UIDGlink = new SHOP.BLL.BLLDeputyMan();
SHOP.BLL.BLLDeputyBuy UIDGbuy = new SHOP.BLL.BLLDeputyBuy();
SHOP.BLL.ProductTypeA pta = new SHOP.BLL.ProductTypeA();//商品一级分类表
SHOP.BLL.ProductTypeB ptb = new SHOP.BLL.ProductTypeB();//商品二级分类表
SHOP.BLL.UsersInfo UIuifo = new SHOP.BLL.UsersInfo();
protected void Page_Load(object sender, EventArgs e)
{
//系统加载的时候不添加一条动态的产品代购框
if (ViewState["sx"] != null)
{
for (int i = 0; i < Convert.ToInt32(ViewState["sx"]); i++)
{
AddTextBoxs();
}
}
else
{
AddTextBoxs();
}
if (!IsPostBack)
{
NavigationBind();//商品二级列表
if (Request.Cookies["Login"] != null)
{
//得到用户的ID
int uiid = Convert.ToInt32(Request.Cookies["Login"]["UsersID"]);
DataTable dt = UIuifo.getUInfo(uiid).Tables[0];
txtNameDG.Text = dt.Rows[0]["uiName"].ToString(); //当用户登录的时候把 用户信息显示出来..用户姓名
txtPhoneDG.Text = dt.Rows[0]["uiTel"].ToString();//当用户登录的时候把 用户信息显示出来..用户电话
if (txtPhoneDG.Text == "")
{
txtPhoneDG.Text = dt.Rows[0]["uiPhone"].ToString();
}
txtNameDG.Attributes.Add("onmouseover", "this.select()");
txtPhoneDG.Attributes.Add("onmouseover", "this.select()");
}
}
}
/// <summary>
/// 所以商品导航绑定
/// </summary>
public void NavigationBind()
{
dlstNavigation.DataSource = pta.getProductTypeA();
dlstNavigation.DataBind();
}
/// <summary>
/// 返回二级列表
/// </summary>
/// <param name="ptbid"></param>
/// <returns></returns>
public DataTable getTowList(object id)
{
return ptb.getProB(id.ToString());
}
/// <summary>
/// 字符串截取方法
/// </summary>
/// <param name="sString"></param>
/// <param name="nLeng"></param>
/// <returns></returns>
public string SubStr(string sString, int nLeng)
{
if (sString.Length <= nLeng)
{
return sString;
}
string sNewStr = sString.Substring(0, nLeng);
sNewStr = sNewStr + "...";
return sNewStr;
}
//添加一条记录动态生成的填写代购的文本框
private void AddTextBoxs()
{
HtmlTableRow tr = new HtmlTableRow();
//添加lable 文本显示
HtmlTableCell tc1 = new HtmlTableCell();
Label lblName = new Label();
lblName.Text = "品牌:";
lblName.Font.Size = 10;
tc1.Controls.Add(lblName);
//添加名称文本框。。
HtmlTableCell tc2 = new HtmlTableCell();
TextBox txtName = new TextBox();
txtName.ID = "txtName" + Table1.Rows.Count;
txtName.Width = 80;
tc2.Controls.Add(txtName);
//------------------------------------------
HtmlTableCell tc3 = new HtmlTableCell();
Label lblNameD = new Label();
lblNameD.Text = "型号";
lblNameD.Font.Size = 10;
tc3.Controls.Add(lblNameD);
HtmlTableCell tc4 = new HtmlTableCell();
TextBox txtName1 = new TextBox();
txtName1.Width = 80;
txtName1.ID = "txt" + Table1.Rows.Count;
tc4.Controls.Add(txtName1);
HtmlTableCell tc6 = new HtmlTableCell();
Label lblReplce = new Label();
lblReplce.Text = "可替换";
lblReplce.Font.Size = 10;
tc6.Controls.Add(lblReplce);
HtmlTableCell tc7 = new HtmlTableCell();
CheckBox cbReplce = new CheckBox();
cbReplce.ID = "checksel" + Table1.Rows.Count;
tc7.Controls.Add(cbReplce);//
HtmlTableCell tc8 = new HtmlTableCell();
Label lblnomber = new Label();
lblnomber.Font.Size = 10;
lblnomber.Width = 30;
lblnomber.Text = "数量";
tc8.Controls.Add(lblnomber);
HtmlTableCell tc9 = new HtmlTableCell();
TextBox txtNumber = new TextBox();
txtNumber.ID = "txtNumber" + Table1.Rows.Count;
txtNumber.Width = 35;
tc9.Controls.Add(txtNumber);
HtmlTableCell tc10 = new HtmlTableCell();
Label lblPrice = new Label();
lblPrice.Text = "理想价¥";
lblPrice.Font.Size = 10;
tc10.Controls.Add(lblPrice);
HtmlTableCell tc11 = new HtmlTableCell();
TextBox txtPrice = new TextBox();
txtPrice.ID = "txtPric" + Table1.Rows.Count;
txtPrice.Width = 45;
tc11.Controls.Add(txtPrice);
HtmlTableCell tc12 = new HtmlTableCell();
Label lblSupport = new Label();
lblSupport.Text = "技术要求";
lblSupport.Font.Size = 10;
tc12.Controls.Add(lblSupport);
HtmlTableCell tc13 = new HtmlTableCell();
TextBox txtSupport = new TextBox();
txtSupport.ID = "txtSupport" + Table1.Rows.Count;
txtSupport.Width = 160;
tc13.Controls.Add(txtSupport);
//添加按钮删除按钮
HtmlTableCell tc5 = new HtmlTableCell();
Button btn = new Button();
btn.ID = "bt" + Table1.Rows.Count;
btn.Text = "删除";
btn.Width = 49;
btn.CommandArgument = Table1.Rows.Count.ToString();
btn.Click += new EventHandler(btn_Click);
tc5.Controls.Add(btn);
tr.Cells.Add(tc1); //名字这个添加的
tr.Cells.Add(tc2);
tr.Cells.Add(tc3); //
tr.Cells.Add(tc4);
tr.Cells.Add(tc6);
tr.Cells.Add(tc7);
tr.Cells.Add(tc8);
tr.Cells.Add(tc9);
tr.Cells.Add(tc10);
tr.Cells.Add(tc11);
tr.Cells.Add(tc12);
tr.Cells.Add(tc13);
tr.Cells.Add(tc5);//添加删除按钮
Table1.Rows.Add(tr);
}
/// <summary>
/// 得到文本框的值。 点击确定 代购 的时候 网数据库中 加入批量的商品 代购产品
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnInsert_Click(object sender, EventArgs e)
{
string dmID = "";
try
{
if (txtNameDG.Text.Trim() != "" && txtPhoneDG.Text.Trim() != "")
{
Random random = new Random(47);
string num = "DG" + DateTime.Now.ToString("yyyyMMddhhmmss") + random.Next(100, 1000).ToString(); //生成一个随机的编号,给客户
//点击确定的时候往数据库中加入用户姓名 和联系电话
//预留。等待用户登录的时候 网站整合的时候
if (Request.Cookies["Login"] != null) //判断是不是会员登录的 如果是 就输入会员id 如果不是就默认 为 0
{
UIDGlink.BLLinsert(Request.Cookies["Login"]["UsersID"], txtNameDG.Text, txtPhoneDG.Text, num);
}
else
{
//往数据库中添加颚用户信息
// 0 是关联会员ID 默认的 会员ID 0 因为是 匿名用户 没会员的
UIDGlink.BLLinsert("0", txtNameDG.Text.Trim(), txtPhoneDG.Text.Trim(), num);
}
//从数据库中查出 由 页面文本框 对应的 ID 给下面产品 使用。·。
DataTable dt = UIDGlink.BLLselUiID(txtNameDG.Text.Trim());
dmID = dt.Rows[0]["dmID"].ToString(); //把查出的ID 赋值给 dmid 让它关联第二个表
//定义动态生成的 用户的产品文本框的变量用于循环判断增加值
string pinpai = "", name = "", sumNumber = "", dreamPrice = "", txtjishuzhichi = "";
string checkselect = "";
//遍历得到用户输入的值
for (int i = 0; i < Table1.Rows.Count; i++)
{
if (Table1.Rows[i].Visible == true)
{
TextBox txt = (TextBox)Table1.Rows[i].FindControl("txtName" + i);
pinpai += txt.Text + ","; //代购品牌的值
TextBox txtName = (TextBox)Table1.Rows[i].FindControl("txt" + i);
name += txtName.Text + ","; //代购名字
//是否可以替换
CheckBox cbselect = (CheckBox)Table1.Rows[i].FindControl("checksel" + i);
//判断是否被选中
if (cbselect.Checked == true)
{
checkselect += "1" + ",";
}
else
{
checkselect += "0" + ",";
}
//得到数量
TextBox txtn = (TextBox)Table1.Rows[i].FindControl("txtNumber" + i);
sumNumber += txtn.Text + ",";
//得到理想价格值
TextBox txtDreamPrice = (TextBox)Table1.Rows[i].FindControl("txtPric" + i);
dreamPrice += txtDreamPrice.Text + ",";
//得到技术要求值
TextBox txtjishu = (TextBox)Table1.Rows[i].FindControl("txtSupport" + i);
txtjishuzhichi += txtjishu.Text + ",";
}
}
string[] pin = pinpai.Split(new char[] { ',' }); //定义到得品牌的数组分割
string[] namegroup = name.Split(new char[] { ',' }); //得到产品名字进行数组分割
string[] sumNumberGroup = sumNumber.Split(new char[] { ',' }); //得到商品数量进行分割
string[] dreamPriceGroup = dreamPrice.Split(new char[] { ',' }); //得到用户的理想价格 分割
string[] txtjishuzhichiGroup = txtjishuzhichi.Split(new char[] { ',' }); //技术支持
string[] checkselectGroup = checkselect.Split(new char[] { ',' }); // 是否可以替换
int countCinsert = 0; //用来判断是否对数据库操作成功 0 不 0 成功
for (int i = 0; i < pin.Length - 1; i++)
{
if (pin[i] != "" && namegroup[i] != "" && dreamPriceGroup[i] != "" && sumNumberGroup[i] != "")
{
//往数据库中动态的添加循环得到的数据
countCinsert = UIDGbuy.BLLinsertbuy(Convert.ToInt32(dmID), pin[i], namegroup[i], dreamPriceGroup[i], txtjishuzhichiGroup[i], Convert.ToInt32(sumNumberGroup[i]), Convert.ToInt32(checkselectGroup[i]));
if (countCinsert > 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "cheg", "<script>alert('你的数据已经提交,我们会以最快的速度给你回复,谢谢订购!!!\\n这是你的订单编号请你记好: " + num + "')</script>");
//现在是清空数据
}
else
{
//由于代购失败, 把已经添加进去的代购人给删除
int countdeldmID = UIDGlink.BLLDelDGlinkPeople(dmID);
if (countdeldmID > 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "price", "<script>alert('代购是失败,价格输入错误,只能输入 数字')</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "price", "<script>alert('代购是失败,价格输入错误,只能输入 数字_____________')</script>");
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "asdsa", "<script>alert('输入有空或者删除空的一行,请正确输入!')</script>");
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "asdsa", "<script>alert('姓名或者联系方式为空,请正确输入!')</script>");
}
}
catch (Exception)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "asdsa", "<script>alert('程序异常,请检查是否输入错误 !')</script>");
}
finally
{
if (Table1.Rows[0].Visible == false)
{
int countdeldmID = UIDGlink.BLLDelDGlinkPeople(dmID);
if (countdeldmID > 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "price", "<script>alert('代购是失败,请输入 至少一项 代购产品...')</script>");
}
}
}
}
//增加一个动态条
protected void btnAdd_Click(object sender, EventArgs e)
{
AddTextBoxs();
ViewState["sx"] = Convert.ToInt32(ViewState["sx"]) + 1;
}
//删除一条记录
void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
Table1.Rows[Convert.ToInt16(btn.CommandArgument)].Visible = false;
}
}