using BLL;
using Common;
using Model;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using wms;
using Json;
using Lib;
using System.Collections;
using System.Data;
using Commom.BarCodePrint;
namespace wms.Areas.BasicInfo.Controllers
{
public class TrayAjaxController : AjaxPage
{
// GET: BasicInfo/TrayAjax
///
/// 查询托盘
///
///
public ActionResult GetTrayList()
{
try
{
var dd = Request["ajaxdata"];
var trayModels = new JavaScriptSerializer().Deserialize(dd);
if (trayModels != null)
{
// 实例化分页信息
PageInfo pageInfo = new PageInfo()
{
PageIndex = trayModels.pageIndex,
PageSize = trayModels.pageSize
};
// 数据库交互,获取托盘信息and分页信息。
DALTray provider = new DALTray();
List entity = provider.GetList(trayModels, ref pageInfo).ToList();
// Data =》json
string json = JsonHelper.IListToJson(entity, "List");
string pjson = ConvertJson.Serializer(pageInfo);
// controller => view
ReturnJson.AddProperty("Result", new JsonObject(json));
ReturnJson.AddProperty("PageInfo", new JsonObject(pjson));
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "加载托盘信息成功!");
return Content(this.ReturnJson.ToString());
}
return Content(null);
}
catch (System.Exception)
{
return Content(null);
}
}
///
/// 新增编辑托盘信息
///
///
public ActionResult AddEdit()
{
try
{
var dd = Request["ajaxdata"];
var trayModels = new JavaScriptSerializer().Deserialize(dd);
if (trayModels != null)
{
// 数据库交互
DALTray provider = new DALTray();
if (provider.AddEdit(trayModels))
{
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "保存成功!");
}
else
{
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "保存失败!");
}
}
return Content(this.ReturnJson.ToString());
}
catch (System.Exception)
{
return Content(null);
}
}
///
/// 删除托盘
///
///
public ActionResult Delete()
{
try
{
string dd = Request["list"];
ArrayList models = new JavaScriptSerializer().Deserialize(dd);
string[] list = (string[])models.ToArray(typeof(string));
if (models != null)
{
// 数据库交互
DALTray provider = new DALTray();
if (provider.Delete(list))
{
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "删除成功!");
}
else
{
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "删除失败!");
}
}
return Content(this.ReturnJson.ToString());
}
catch (System.Exception)
{
return Content(null);
}
}
///
/// 打印托盘条形码
///
///
public ActionResult PrintBarCode()
{
ReturnJson.AddProperty("SubCode", 0);
ReturnJson.AddProperty("SubMessage", "");
try
{
var dd = Request["list"];
ArrayList models = new JavaScriptSerializer().Deserialize(dd);
string[] list = (string[])models.ToArray(typeof(string));
if (models != null)
{
string palno = list[0];
DALTray provider = new DALTray();
DataTable trayDt = provider.GetTrayPrint("", palno);
string StorageName = trayDt.Rows[0]["StorageName"].ToString();
string addre = trayDt.Rows[0]["Addre"].ToString();
TSC1.TSCPrint(StorageName + "-" + addre, palno);
ReturnJson.AddProperty("Code", 1);
ReturnJson.AddProperty("Message", "条码打印完成!");
}
return Content(this.ReturnJson.ToString());
}
catch (System.Exception ex)
{
ReturnJson.AddProperty("Code", -1);
ReturnJson.AddProperty("Message", "条码打印失败! " + ex.Message);
return Content(this.ReturnJson.ToString());
}
}
}
}