590 lines
26 KiB
C#
590 lines
26 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Text;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
namespace Mtxfw.shop
|
|
{
|
|
public partial class Member_Product_add : Mtxfw.Utility.MemberBase
|
|
{
|
|
public Mtxfw.DAL.P_Category daoCategory = new Mtxfw.DAL.P_Category();
|
|
public Mtxfw.DAL.P_Product daoProduct = new Mtxfw.DAL.P_Product();
|
|
public Mtxfw.DAL.user_info daoUser = new Mtxfw.DAL.user_info();
|
|
public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config();
|
|
protected String pid, cid, qid, TitName, strBody, ProductLB1 = "", ProductLB2 = "", ProductLB3 = "";
|
|
public string strimg = "", stryanse = "";
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
Page.Title = "发布商品 - " + config.webName;
|
|
//Select_Bind();
|
|
if (Request.UrlReferrer != null)
|
|
{
|
|
Hidd_Url.Value = Request.UrlReferrer.ToString();
|
|
}
|
|
}
|
|
string stryanseoption = "";
|
|
if (Request.QueryString["ID"] == null)
|
|
{
|
|
TitName = "发布商品";
|
|
if (!IsPostBack)
|
|
{
|
|
Btn_Update.Visible = false;
|
|
if (Session["P_CATEGORY1"] != null)
|
|
{
|
|
ProductLB1 = Session["P_CATEGORY1"].ToString();
|
|
}
|
|
if (Session["P_CATEGORY2"] != null)
|
|
{
|
|
ProductLB2 = Session["P_CATEGORY2"].ToString();
|
|
}
|
|
if (Session["P_CATEGORY3"] != null)
|
|
{
|
|
ProductLB3 = Session["P_CATEGORY3"].ToString();
|
|
}
|
|
Session["jiaoyouPhoto"] = "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
TitName = "修改商品";
|
|
Btn_Insert.Visible = false;
|
|
PanelCB.Visible = false;
|
|
}
|
|
Mtxfw.Model.P_Product model = daoProduct.GetModel(int.Parse(Request.QueryString["ID"]));
|
|
if (model != null)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
Text_P_NAME.Text = model.P_NAME;
|
|
Text_P_NAME2.Text = model.P_NAME2;
|
|
P_Market_P.Text = model.P_Market_P.ToString();
|
|
P_VIP_P.Text = model.P_VIP_P.ToString();
|
|
P_CB_P.Text = model.P_CB_P.ToString();
|
|
P_YH_P.Text = model.P_YH_P.ToString();
|
|
P_Inventory.Text = model.P_Inventory.ToString();
|
|
Text_P_EDESCRIPTION.Text = model.P_EDESCRIPTION;
|
|
if (!String.IsNullOrEmpty(model.P_images))
|
|
{
|
|
if (model.P_images.IndexOf("|") == -1)
|
|
{
|
|
Session["jiaoyouPhoto"] = model.P_images + "|";
|
|
}
|
|
else
|
|
{
|
|
Session["jiaoyouPhoto"] = model.P_images;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Session["jiaoyouPhoto"] = "";
|
|
}
|
|
|
|
|
|
}
|
|
|
|
if (model.P_yanse != "")
|
|
{
|
|
stryanse = model.P_yanse;
|
|
string[] Ayanse = stryanse.Split('|');
|
|
|
|
for (int i = 0; i < Ayanse.Length; i++)
|
|
{
|
|
if (Ayanse[i] != "")
|
|
{
|
|
string[] stra = Ayanse[i].Split('#');
|
|
stryanseoption += "<option value='" + Ayanse[i] + "'>" + stra[0] + "</option>";
|
|
}
|
|
}
|
|
|
|
}
|
|
strBody = model.P_DESCRIPTION;
|
|
string[] ACATEGORYs = model.P_CATEGORYs.Split(',');
|
|
if (ACATEGORYs.Length > 1)
|
|
{
|
|
ProductLB1 = ACATEGORYs[1];
|
|
}
|
|
if (ACATEGORYs.Length > 2)
|
|
{
|
|
ProductLB2 = ACATEGORYs[2];
|
|
}
|
|
if (ACATEGORYs.Length > 3)
|
|
{
|
|
ProductLB3 = ACATEGORYs[3];
|
|
}
|
|
}
|
|
}
|
|
if (Session["jiaoyouPhoto"] != null)
|
|
{
|
|
Y_Certificate.Value = Session["jiaoyouPhoto"].ToString();
|
|
string[] strjiaoyouPhotoA = Session["jiaoyouPhoto"].ToString().Split('|');
|
|
for (int i = 0; i < strjiaoyouPhotoA.Length; i++)
|
|
{
|
|
if (strjiaoyouPhotoA[i] != "")
|
|
{
|
|
string[] strPhoto = strjiaoyouPhotoA[i].Split(',');
|
|
strimg += "<li id='picli" + i + "'><img src='" + Mtxfw.Utility.Common.GetCoverPic(strPhoto[0], "100x100", "cut") + "' width='100'/><a href=javascript:DeletePic('" + strjiaoyouPhotoA[i] + "'," + i + ")>删除</a>";
|
|
if (i == 0)
|
|
{
|
|
strimg += " 已设为封面";
|
|
}
|
|
else
|
|
{
|
|
strimg += " <a href=javascript:SetPic('" + strjiaoyouPhotoA[i] + "'," + i + ")>设为封面</a>";
|
|
}
|
|
|
|
if (stryanseoption != "")
|
|
{
|
|
string stryanseoption2 = stryanseoption;
|
|
if (strPhoto.Length == 2)
|
|
{
|
|
if (strPhoto[1] != "")
|
|
{
|
|
stryanseoption2 = stryanseoption.Replace("value='" + strPhoto[1] + "'", "value='" + strPhoto[1] + "' selected");
|
|
}
|
|
}
|
|
strimg += "<br><select id='select_yanse_" + i + "'>" + stryanseoption2 + "</select>";
|
|
}
|
|
strimg += "</li>";
|
|
}
|
|
}
|
|
}
|
|
Btn_Insert.Click += delegate(object s, EventArgs ex)
|
|
{
|
|
try
|
|
{
|
|
bool b = true;
|
|
if (Text_P_NAME.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('商品名称不能为空!');</script>");
|
|
}
|
|
string strProductLB1 = "", strProductLB2 = "", strProductLB3 = "";
|
|
if (Request.Form["select_p1"] != null)
|
|
{
|
|
strProductLB1 = Request.Form["select_p1"].ToString();
|
|
}
|
|
if (Request.Form["select_p2"] != null)
|
|
{
|
|
strProductLB2 = Request.Form["select_p2"].ToString();
|
|
}
|
|
if (Request.Form["select_p3"] != null)
|
|
{
|
|
strProductLB3 = Request.Form["select_p3"].ToString();
|
|
}
|
|
if (strProductLB1 == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('分类一必须选择!');</script>");
|
|
}
|
|
if (strProductLB2 == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('分类二必须选择!');</script>");
|
|
}
|
|
if (P_Market_P.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('市场价不能为空!');</script>");
|
|
}
|
|
if (P_VIP_P.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('会员价不能为空!');</script>");
|
|
}
|
|
if (P_YH_P.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('运费不能为空!');</script>");
|
|
}
|
|
if (P_Inventory.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('库存不能为空!');</script>");
|
|
}
|
|
if (b)
|
|
{
|
|
Mtxfw.Model.P_Product model = new Mtxfw.Model.P_Product();
|
|
model.P_NAME = Text_P_NAME.Text;
|
|
model.P_NAME2 = Text_P_NAME2.Text;
|
|
|
|
model.P_State = "未处理";
|
|
model.P_CATEGORY = 0;
|
|
string P_CATEGORYs = "," + strProductLB1 + ",";
|
|
if (strProductLB2 != "")
|
|
{
|
|
P_CATEGORYs += strProductLB2 + ",";
|
|
}
|
|
if (strProductLB3 != "")
|
|
{
|
|
P_CATEGORYs += strProductLB3 + ",";
|
|
}
|
|
model.P_CATEGORYs = P_CATEGORYs;
|
|
Session["P_CATEGORY1"] = strProductLB1;
|
|
Session["P_CATEGORY2"] = strProductLB2;
|
|
Session["P_CATEGORY3"] = strProductLB3;
|
|
|
|
|
|
if (!String.IsNullOrEmpty(P_Market_P.Text))
|
|
{
|
|
model.P_Market_P = Convert.ToDouble(P_Market_P.Text);
|
|
}
|
|
if (!String.IsNullOrEmpty(P_VIP_P.Text))
|
|
{
|
|
model.P_VIP_P = Convert.ToDouble(P_VIP_P.Text);
|
|
}
|
|
|
|
model.P_VIP_P1 = 0;
|
|
model.P_VIP_P2 = 0;
|
|
|
|
model.P_M_P = 0;
|
|
if (!String.IsNullOrEmpty(P_CB_P.Text))
|
|
{
|
|
model.P_CB_P = Convert.ToDouble(P_CB_P.Text);
|
|
}
|
|
if (!String.IsNullOrEmpty(P_YH_P.Text))
|
|
{
|
|
model.P_YH_P = Convert.ToDouble(P_YH_P.Text);
|
|
}
|
|
else
|
|
{
|
|
model.P_YH_P = 0;
|
|
}
|
|
if (!String.IsNullOrEmpty(P_Inventory.Text))
|
|
{
|
|
model.P_Inventory = int.Parse(P_Inventory.Text);
|
|
}
|
|
model.P_M_Web = "";
|
|
model.P_DESCRIPTION = Hidd_myEditor.Value;
|
|
model.P_COMMENDF = false;
|
|
|
|
model.P_Orders = 0;
|
|
model.P_ADDATE = DateTime.Now;
|
|
model.P_HITED = 0;
|
|
model.utype = "0";
|
|
model.Province = "0";
|
|
model.City = "0";
|
|
model.County = "0";
|
|
model.P_JiangLi = 0;
|
|
model.P_JiangLi2 = 0;
|
|
model.P_JiangLi3 = 0;
|
|
model.P_EDESCRIPTION = Text_P_EDESCRIPTION.Text;
|
|
model.P_DESCRIPTION1 = "";
|
|
model.P_DESCRIPTION2 = "";
|
|
model.P_yanse = "";//(model.P_CATEGORYs.IndexOf(",152,") == -1 ? "黑色#000000|白色#ffffff" : "黑色#000000|灰色#55616F|绿蓝色#1CC29E")
|
|
model.P_UserID = Card;
|
|
string sels = model.P_yanse;
|
|
string[] asels = sels.Split('|');
|
|
|
|
string strPhotos = "";
|
|
if (Session["jiaoyouPhoto"] != null)
|
|
{
|
|
string[] strjiaoyouPhotoA = Session["jiaoyouPhoto"].ToString().Split('|');
|
|
for (int i = 0; i < strjiaoyouPhotoA.Length; i++)
|
|
{
|
|
if (strjiaoyouPhotoA[i] != "")
|
|
{
|
|
string[] strPhoto = strjiaoyouPhotoA[i].Split(',');
|
|
if (sels != "")
|
|
{
|
|
try
|
|
{
|
|
strPhotos += strPhoto[0] + "," + asels[i] + "|";
|
|
}
|
|
catch
|
|
{
|
|
strPhotos += strPhoto[0] + "|";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
strPhotos += strPhoto[0] + "|";
|
|
}
|
|
}
|
|
}
|
|
Session["jiaoyouPhoto"] = "";
|
|
}
|
|
model.P_images = strPhotos;
|
|
|
|
daoProduct.Add(model);
|
|
daoCategory.Update2(model.P_CATEGORY, 1);
|
|
if (Session["UploadFileIng"] != null)
|
|
{
|
|
string[] stra = Session["UploadFileIng"].ToString().Split(',');
|
|
foreach (string str in stra)
|
|
{
|
|
if (str.Trim() != "")
|
|
{
|
|
if (model.P_DESCRIPTION.IndexOf(str.Trim()) == -1)
|
|
{
|
|
if (System.IO.File.Exists(Server.MapPath(str.Trim())))
|
|
{
|
|
System.IO.File.Delete(Server.MapPath(str.Trim()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session.Remove("UploadFileIng");
|
|
System.Collections.IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
|
|
while (CacheEnum.MoveNext())
|
|
{
|
|
Cache.Remove(CacheEnum.Key.ToString());
|
|
}
|
|
Response.Redirect("/Member_Product_List.aspx");
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
};
|
|
|
|
Btn_Update.Click += delegate(object s, EventArgs ex)
|
|
{
|
|
try
|
|
{
|
|
bool b = true;
|
|
if (Text_P_NAME.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('商品名称不能为空!');</script>");
|
|
}
|
|
string strProductLB1 = "", strProductLB2 = "", strProductLB3 = "";
|
|
if (Request.Form["select_p1"] != null)
|
|
{
|
|
strProductLB1 = Request.Form["select_p1"].ToString();
|
|
}
|
|
if (Request.Form["select_p2"] != null)
|
|
{
|
|
strProductLB2 = Request.Form["select_p2"].ToString();
|
|
}
|
|
if (Request.Form["select_p3"] != null)
|
|
{
|
|
strProductLB3 = Request.Form["select_p3"].ToString();
|
|
}
|
|
if (strProductLB1 == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('分类一必须选择!');</script>");
|
|
}
|
|
if (strProductLB2 == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('分类二必须选择!');</script>");
|
|
}
|
|
if (P_Market_P.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('市场价不能为空!');</script>");
|
|
}
|
|
if (P_VIP_P.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('会员价不能为空!');</script>");
|
|
}
|
|
if (P_YH_P.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('运费不能为空!');</script>");
|
|
}
|
|
if (P_Inventory.Text.Trim() == "")
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('库存不能为空!');</script>");
|
|
}
|
|
Int32 P_ID = int.Parse(Request.QueryString["ID"]);
|
|
Mtxfw.Model.P_Product model = daoProduct.GetModel(P_ID);
|
|
if (model != null)
|
|
{
|
|
if (model.P_UserID != Card)
|
|
{
|
|
b = false;
|
|
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('请不要修改不属于您的商品!');</script>");
|
|
}
|
|
}
|
|
if (b && model != null)
|
|
{
|
|
|
|
model.P_ID = P_ID;
|
|
model.P_NAME = Text_P_NAME.Text;
|
|
model.P_NAME2 = Text_P_NAME2.Text;
|
|
model.P_CATEGORY = 0;
|
|
string P_CATEGORYs = "," + strProductLB1 + ",";
|
|
if (strProductLB2 != "")
|
|
{
|
|
P_CATEGORYs += strProductLB2 + ",";
|
|
}
|
|
if (strProductLB3 != "")
|
|
{
|
|
P_CATEGORYs += strProductLB3 + ",";
|
|
}
|
|
model.P_CATEGORYs = P_CATEGORYs;
|
|
|
|
if (!String.IsNullOrEmpty(P_Market_P.Text))
|
|
{
|
|
model.P_Market_P = Convert.ToDouble(P_Market_P.Text);
|
|
}
|
|
if (!String.IsNullOrEmpty(P_VIP_P.Text))
|
|
{
|
|
model.P_VIP_P = Convert.ToDouble(P_VIP_P.Text);
|
|
}
|
|
if (!String.IsNullOrEmpty(P_YH_P.Text))
|
|
{
|
|
model.P_YH_P = Convert.ToDouble(P_YH_P.Text);
|
|
}
|
|
if (!String.IsNullOrEmpty(P_Inventory.Text))
|
|
{
|
|
model.P_Inventory = int.Parse(P_Inventory.Text);
|
|
}
|
|
model.P_DESCRIPTION = Hidd_myEditor.Value;
|
|
model.P_EDESCRIPTION = Text_P_EDESCRIPTION.Text;
|
|
|
|
string sels = model.P_yanse;
|
|
string[] asels = sels.Split('|');
|
|
|
|
string strPhotos = "";
|
|
if (Session["jiaoyouPhoto"] != null)
|
|
{
|
|
string[] strjiaoyouPhotoA = Session["jiaoyouPhoto"].ToString().Split('|');
|
|
for (int i = 0; i < strjiaoyouPhotoA.Length; i++)
|
|
{
|
|
if (strjiaoyouPhotoA[i] != "")
|
|
{
|
|
string[] strPhoto = strjiaoyouPhotoA[i].Split(',');
|
|
if (sels != "")
|
|
{
|
|
try
|
|
{
|
|
strPhotos += strPhoto[0] + "," + asels[i] + "|";
|
|
}
|
|
catch
|
|
{
|
|
strPhotos += strPhoto[0] + "|";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
strPhotos += strPhoto[0] + "|";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
model.P_images = strPhotos;
|
|
|
|
daoProduct.Update(model);
|
|
|
|
if (Session["UploadFileIng"] != null)
|
|
{
|
|
string[] stra = Session["UploadFileIng"].ToString().Split(',');
|
|
foreach (string str in stra)
|
|
{
|
|
if (str.Trim() != "")
|
|
{
|
|
if (model.P_DESCRIPTION.IndexOf(str.Trim()) == -1)
|
|
{
|
|
if (System.IO.File.Exists(Server.MapPath(str.Trim())))
|
|
{
|
|
System.IO.File.Delete(Server.MapPath(str.Trim()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Session.Remove("UploadFileIng");
|
|
System.Collections.IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
|
|
while (CacheEnum.MoveNext())
|
|
{
|
|
Cache.Remove(CacheEnum.Key.ToString());
|
|
}
|
|
Response.Redirect(Hidd_Url.Value);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
/*protected void Select_Bind()
|
|
{
|
|
string remark = null;
|
|
int lbConut2 = 0;
|
|
DataSet ds = daoCategory.GetList("ttype=0 Order By C_Layer asc,C_LinkID asc");
|
|
foreach (DataRowView drv2 in ds.Tables[0].DefaultView)//绑定根结点
|
|
{
|
|
lbConut2 = Convert.ToInt32(drv2["C_Layer"].ToString());
|
|
string LB = drv2["C_NAME"].ToString();
|
|
string Pid = drv2["C_PARENTID"].ToString();
|
|
string id = drv2["C_ID"].ToString();
|
|
remark = "";
|
|
for (int l = 0; l < lbConut2; l++)
|
|
{
|
|
remark += "├";
|
|
}
|
|
if (lbConut2 == 1)
|
|
{
|
|
Drop_Cls.Items.Add(new ListItem(remark + LB, id + "|" + Pid));
|
|
}
|
|
else
|
|
{
|
|
int jj = 0;
|
|
for (int j = 0; j < Drop_Cls.Items.Count; j++)
|
|
{
|
|
string[] lbpid = Drop_Cls.Items[j].Value.Split('|');
|
|
if (lbpid.Length == 2)
|
|
{
|
|
if (Pid == lbpid[1])
|
|
{
|
|
jj += 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int j = 0; j < Drop_Cls.Items.Count; j++)
|
|
{
|
|
string[] lbpid = Drop_Cls.Items[j].Value.Split('|');
|
|
if (lbpid.Length == 2)
|
|
{
|
|
if (Pid == lbpid[0])
|
|
{
|
|
if (jj != 0)
|
|
{
|
|
Drop_Cls.Items.Insert(j + jj + 1, new ListItem(remark + LB, id + "|" + Pid));
|
|
}
|
|
else
|
|
{
|
|
Drop_Cls.Items.Insert(j + 1, new ListItem(remark + LB, id + "|" + Pid));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ds.Clear();
|
|
|
|
}*/
|
|
protected string getProductLB()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
Mtxfw.DAL.province daoPro = new Mtxfw.DAL.province();
|
|
System.Data.DataSet Ds = daoCategory.GetCacheList("", "ttype=0 And C_Layer=1 Order By C_Layer asc,C_LinkID asc", "ProductLB1");
|
|
System.Data.DataTable Dt = (Ds != null && Ds.Tables[0] != null) ? Ds.Tables[0] : null;
|
|
foreach (System.Data.DataRow Dr in Dt.Rows)
|
|
{
|
|
sb.Append("<option value=\"" + Dr["C_ID"] + "\">" + Dr["C_NAME"] + "</option>\r\n");
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
} |