/// <summary> /// 查询货架名是否重复 /// </summary> /// <param name="shelves">货架实体对象</param> /// <returns></returns> public int selectByName(GoodsShelves shelves) { //货架ID string cmdText = "select count(goodsShelvesId) from T_GoodsShelves where goodsShelvesId=@goodsShelvesId"; String[] param = { "@goodsShelvesId" }; String[] values = { shelves.GoodsShelvesId }; int row = Convert.ToInt32(db.ExecuteScalar(cmdText, param, values)); //货架名称 string cmdTexts = "select count(goodsShelvesId) from T_GoodsShelves where regionId = @regionId and shelvesName=@shelvesName"; String[] parames = { "@shelvesName", "@regionId" }; String[] valuess = { shelves.ShelvesName, shelves.RegionId.RegionId.ToString() }; int rows = Convert.ToInt32(db.ExecuteScalar(cmdTexts, parames, valuess)); if (row > 0 && rows > 0)//都重复 { return(2); } else if (row > 0 && rows <= 0)//货架ID重复 { return(1); } else if (rows > 0 && row <= 0)//货架名称重复 { return(-1); } else//都不重复 { return(0); } }
/// <summary> /// 添加 /// </summary> /// <param name="shelves">货架</param> /// <returns>受影响行数</returns> public int Insert(GoodsShelves shelves) { string cmdText = "insert into T_GoodsShelves(goodsShelvesId,shelvesName,regionId) values(@goodsShelvesId,@shelvesName,@regionId)"; String[] param = { "@goodsShelvesId", "@shelvesName", "@regionId" }; String[] values = { shelves.GoodsShelvesId, shelves.ShelvesName, shelves.RegionId.RegionId.ToString() }; int row = db.ExecuteNoneQuery(cmdText, param, values); return(row); }
/// <summary> /// 添加书架方法 /// </summary> /// <param name="shelves">书架</param> /// <returns>返回结果</returns> public Result Insert(GoodsShelves shelves) { int row = shelvesdao.Insert(shelves); if (row > 0) { return(Result.添加成功); } else { return(Result.添加失败); } }
/// <summary> /// 查询货架名是否重复 /// </summary> /// <param name="shelves">货架实体对象</param> /// <returns></returns> public int selectByName(GoodsShelves shelves) { return(shelvesdao.selectByName(shelves)); //int row = shelvesdao.selectByName(shelves); //if (row>0) //{ // return Result.记录存在; //} //else //{ // return Result.记录不存在; //} }
protected void Page_Load(object sender, EventArgs e) { permission(); //getData(); string op = Request["op"]; if (op == "paging") { getData(); } if (op == "add") { int regionId; if (user.RoleId.RoleName == "超级管理员") { regionId = int.Parse(Request["regionId"]); } else { regionId = user.ReginId.RegionId; } string shelfName = Request["shelfName"]; string shelfNo = Request["shelfNo"]; Region reg = new Region() { RegionId = regionId }; GoodsShelves shelves = new GoodsShelves() { GoodsShelvesId = shelfNo, ShelvesName = shelfName, RegionId = reg }; int row = shelvesbll.selectByName(shelves); if (row == 0) { Result result = shelvesbll.Insert(shelves); if (result == Result.添加成功) { Response.Write("添加成功"); Response.End(); } else { Response.Write("添加成功"); Response.End(); } } else if (row == 1) { Response.Write("货架编号已存在"); Response.End(); } else if (row == -1) { Response.Write("货架名称已存在"); Response.End(); } else { Response.Write("货架编号,货架名称已存在"); Response.End(); } //Result row = shelvesbll.selectByName(shelves); //if (row == Result.记录不存在) //{ // Result result = shelvesbll.Insert(shelves); // if (result == Result.添加成功) // { // Response.Write("添加成功"); // Response.End(); // } // else // { // Response.Write("添加成功"); // Response.End(); // } //} //else //{ // Response.Write("货架名已存在"); // Response.End(); //} } if (op == "del") { string shelfId = Request["shelfId"]; Result result = isDelete(); if (result == Result.记录不存在) { Result row = shelvesbll.DeleteTrue(shelfId); if (row == Result.除成功) { Response.Write("删除成功"); Response.End(); } else { Response.Write("删除失败"); Response.End(); } } else { Response.Write("已关联引用,无法删除"); Response.End(); } } if (op == "logout") { //删除身份凭证 FormsAuthentication.SignOut(); //设置Cookie的值为空 Response.Cookies[FormsAuthentication.FormsCookieName].Value = null; //设置Cookie的过期时间为上个月今天 Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddMonths(-1); } if (op == "import") { DataTable dtInsert = new DataTable(); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); dtInsert = differentDt(); //赋给新table TimeSpan ts = watch.Elapsed; dtInsert.TableName = "T_GoodsShelves"; //导入的表名 int a = userBll.BulkInsert(dtInsert); watch.Stop(); double minute = ts.TotalMinutes; //计时 string m = minute.ToString("0.00"); int cf = row - a; if (a > 0) { Response.Write("导入成功,总数据有" + row + "条,共导入" + a + "条数据" + ",共用时:" + m + "分钟"); Response.End(); } else { Response.Write("导入失败,总数据有" + row + "条,共导入" + a + "条数据,重复数据有" + cf); Response.End(); } } if (op == "check") { check(); } }