📄 addshop.aspx.cs
字号:
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;
using System.Collections.Generic;
using System.IO;
using Shop.Web.UI;
namespace YXShop.Web.Admin.Shop
{
public partial class AddShop : System.Web.UI.Page
{
YXShop.BLL.YXShop_Shop sBll = new YXShop.BLL.YXShop_Shop();
BasePage bp = new BasePage();
protected void Page_Load(object sender, EventArgs e)
{
if (!PowerTree.PowerPass.isPass("014003002", PowerTree.PowerPanel.PowerType.add))
{
bp = new BasePage();
bp.PageError("对不起,你没有添加店铺的权限!", "../index.aspx");
}
if (!Page.IsPostBack)
{
BindDropDownList(DropDownList3, -1);
BindRadionList(RadioButtonList1, -1, -1);
BindDropDownList2(DropDownList2, -1);
}
}
private void BindRadionList(RadioButtonList rBtnList, int shopRank, int minDay)
{
//用户不能修改为比已使用天数更少的规模方案
rBtnList.Items.Clear();
YXShop.BLL.YXShop_ShopType stBll = new YXShop.BLL.YXShop_ShopType();
List<YXShop.Model.YXShop_ShopType> stList = stBll.GetListByColumn();
ListItem lItem = null;
foreach (YXShop.Model.YXShop_ShopType stModel in stList)
{
lItem = new ListItem();
lItem.Value = String.Format("{0},{1}", stModel.STID, stModel.ExpendDays);
lItem.Text = String.Format("<font style='color:red;'>{0}</font> 租金:{1}元,经营商品数量为{2}个,空间大小{3}kb,可使用[{4}]天数", stModel.STName, stModel.STPrice, stModel.ProCount, stModel.ShopSpace, stModel.ExpendDays);
if (shopRank == stModel.STID)
{
lItem.Selected = true;
}
if (minDay == 1) //隐藏所有项,用户不能修改
{
lItem.Enabled = false;
}
//if (minDay >= stModel.ExpendDays)
//{
// lItem.Enabled = false;
//}
rBtnList.Items.Add(lItem);
lItem = null;
}
}
private void BindDropDownList(DropDownList ddl, int TypeID)
{
List<YXShop.Model.Pro_Categories> pcList = ItemsSort();
ListItem lItem = null;
foreach (YXShop.Model.Pro_Categories pcModel in pcList)
{
string pre = "";
for (int i = 1; i < pcModel.ProC_ParentPath.Split(',').Length; i++)
{
pre += "|__";
}
lItem = new ListItem();
lItem.Value = pcModel.ProC_ID.ToString();
lItem.Text = pre + pcModel.ProC_CategroiesName;
if (TypeID == pcModel.ProC_ID)
{
lItem.Selected = true;
}
ddl.Items.Add(lItem);
lItem = null;
}
}
private void BindDropDownList2(DropDownList ddl, int TypeID)
{
YXShop.BLL.ShopCategory scBll = new YXShop.BLL.ShopCategory();
List<YXShop.Model.ShopCategory> scList = scBll.GetAll();
ListItem lItem = null;
foreach (YXShop.Model.ShopCategory scModel in scList)
{
lItem = new ListItem();
lItem.Value = scModel.scID.ToString();
lItem.Text = scModel.scName;
if (TypeID == scModel.scID)
{
lItem.Selected = true;
}
ddl.Items.Add(lItem);
lItem = null;
}
}
private List<YXShop.Model.Pro_Categories> ItemsSort()
{
YXShop.BLL.Pro_Categories pcBll = new YXShop.BLL.Pro_Categories();
List<YXShop.Model.Pro_Categories> pcList = pcBll.GetAll();
List<YXShop.Model.Pro_Categories> newPcList = new List<YXShop.Model.Pro_Categories>(pcList.Count + 5);
foreach (YXShop.Model.Pro_Categories pcModel in pcList)
{
if (pcModel.ProC_CategroiesID == 0)
{
newPcList.Add(pcModel);
GetChildItems(ref newPcList, ref pcList, pcModel.ProC_ID);
}
}
return newPcList;
}
private void GetChildItems(ref List<YXShop.Model.Pro_Categories> newPcList, ref List<YXShop.Model.Pro_Categories> oldPcList, int parID)
{
foreach (YXShop.Model.Pro_Categories pcModel in oldPcList)
{
if (pcModel.ProC_CategroiesID == parID)
{
//if (newPcList.Find(IsTrue) == null)
//{
newPcList.Add(pcModel);
GetChildItems(ref newPcList, ref oldPcList, pcModel.ProC_ID);
//}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string path = ConfigurationManager.AppSettings["ShopRoot"].ToString();
path = path.StartsWith("/") ? path : ("/" + path);
path = path.EndsWith("/") ? (path + TextBox1.Text.Trim()) : (path + "/" + TextBox1.Text.Trim());
string DicPath = HttpContext.Current.Server.MapPath("~") + path;
if (!Directory.Exists(DicPath))//如果指定的文件夹不存在,就创建它
Directory.CreateDirectory(DicPath);
string path1 = DicPath.EndsWith("/") ? DicPath + "ShopSign" : DicPath + "/ShopSign";
string path2 = DicPath.EndsWith("/") ? DicPath + "AttestationPic" : DicPath + "/AttestationPic";
if (!Directory.Exists(path1))
Directory.CreateDirectory(path1);
if (!Directory.Exists(path2))
Directory.CreateDirectory(path2);
int id = GetID((Button)sender);
DateTime startDateTime = DateTime.Now;
#region 图片上传
string imgAddr1 = "", imgAddr2 = "";
if (FileUpload1.HasFile)
{
//删除已经存在的文件
foreach (string file in Directory.GetFileSystemEntries(path1))
{
if (File.Exists(file))
File.Delete(file); //直接删除其中的文件
}
//会员路径
string fileUpPath = ConfigurationSettings.AppSettings["memberImgFile"].ToString();
string imgPre = ConfigurationSettings.AppSettings["imgFilePre"].ToString();
imgAddr1 = YXShop.DBUtility.UploadFile.UploadPicFile(FileUpload1, fileUpPath, imgPre);
if (imgAddr1.StartsWith("error"))
{
YXShop.Common.alert.Show(this, imgAddr1.Replace("error:", ""));
return;
}
}
if (FileUpload2.HasFile)
{
//删除已经存在的文件
foreach (string file in Directory.GetFileSystemEntries(path2))
{
if (File.Exists(file))
File.Delete(file); //直接删除其中的文件
}
string fileUpPath = ConfigurationSettings.AppSettings["memberImgFile"].ToString();
string imgPre = ConfigurationSettings.AppSettings["imgFilePre"].ToString();
imgAddr2 = YXShop.DBUtility.UploadFile.UploadPicFile(FileUpload2, fileUpPath, imgPre);
if (imgAddr2.StartsWith("error"))
{
YXShop.Common.alert.Show(this, imgAddr1.Replace("error:", ""));
return;
}
}
#endregion
#region 参数配置
int shopRank = 0, addDay = 0;
string[] arr = RadioButtonList1.SelectedValue.Split(',');
if (arr.Length == 2)
{
shopRank = YXShop.Common.WebUtility.isNumeric(arr[0]) ? Convert.ToInt32(arr[0]) : 0;
addDay = YXShop.Common.WebUtility.isNumeric(arr[1]) ? Convert.ToInt32(arr[1]) : 0;
}
YXShop.Model.YXShop_Shop sModel = new YXShop.Model.YXShop_Shop();
sModel.UID = SelectMembers1.UID;
sModel.ShopName = YXShop.Common.WebUtility.replaceStr(TextBox1.Text);
sModel.ShopType = YXShop.Common.WebUtility.isNumeric(DropDownList2.SelectedValue) ? Convert.ToInt32(DropDownList2.SelectedValue) : 0;
sModel.Categories = YXShop.Common.WebUtility.isNumeric(DropDownList3.SelectedValue) ? Convert.ToInt32(DropDownList3.SelectedValue) : 0;
sModel.ShopRank = shopRank;
sModel.Affiche = "";
sModel.Discription = TextBox3.Text;
sModel.StartDate = startDateTime;
sModel.EndDate = Convert.ToDateTime(sModel.StartDate).AddDays(addDay);//结束时间
sModel.State = 0;
sModel.ShopSign = String.IsNullOrEmpty(imgUrlHid1.Value) ? imgAddr1 : imgUrlHid1.Value;
sModel.ShopStyle = YXShop.Common.WebUtility.isNumeric(TextBox4.Text) ? Convert.ToInt32(TextBox4.Text) : 0;
sModel.TWODomainName = TextBox2.Text;
sModel.AttestationPic = String.IsNullOrEmpty(imgUrlHid2.Value) ? imgAddr2 : imgUrlHid2.Value;
sModel.AttestationState = 0;
sModel.PrestigeRank = 0;
sModel.VisitNo = 0;
sModel.Attribute = "0,0,0,0,0,0";
sModel.AddTime = DateTime.Now;
sModel.UpDateTime = DateTime.Now;
sModel.ShopState = 0;
sModel.ShopNum = GetUniqueID(Convert.ToInt32(sModel.UID));
#endregion
if (id > 0)
{//update
try
{
sModel.SID = id;
sBll.Amend(sModel);
bp.PageRight("店铺信息已经更新!<font color=\"red\">现在就跳转到用户首页!</font></a></li>", "MemberCenter.aspx");
}
catch { }
}
else
{//create
if (CheckShopName(YXShop.Common.WebUtility.replaceStr(TextBox1.Text.Trim())))
{
try
{
if (sBll.Create(sModel) > 0)
{
YXShop.BLL.UserCommon datab = new YXShop.BLL.UserCommon();
datab.Amend(SelectMembers1.UID, "UserType", 2);
bp.PageRight("店铺创建成功!<font color=\"red\">现在就跳回用户首页!</font></a></li>", "ShopManager.aspx");
}
}
catch { }
}
else
{
//该店铺名称已经存在
bp.PageError("该店铺已经存在!<font color=\"red\">返回重新填写店铺信息!</font></a></li>", "AddShop.aspx");
}
}
}
private string GetUniqueID(int uid)
{
int len = uid.ToString().Length;
string pre = "";
for (int i = 0; i < 6 - len; i++)
{
pre += "0";
}
return pre + uid.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="btn"></param>
/// <returns></returns>
private int GetID(Button btn)
{
int reInt = 0;
if (YXShop.Common.WebUtility.isNumeric(btn.CommandArgument))
reInt = Convert.ToInt32(btn.CommandArgument);
return reInt;
}
/// <summary>
/// 检查店铺名称
/// </summary>
/// <param name="shopName"></param>
/// <returns>存在就返回false,表示不能用,否则返回true</returns>
private bool CheckShopName(string shopName)
{
List<YXShop.Model.YXShop_Shop> sList = sBll.GetListByColumn("ShopName", shopName);
if (sList.Count > 0)
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// 是否存在
/// </summary>
/// <param name="name"></param>
/// <returns>存在就返回false,表示不能用,否则返回true</returns>
private bool CheckName(string name)
{
List<YXShop.Model.YXShop_Shop> sList = sBll.GetListByColumn("TWODomainName", name);
if (sList.Count > 0)
{
return false;
}
else
{
return true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -