/**
* OrderList.aspx.cs
*
* 功 能: 订单列表
* 类 名: OrderList
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
* V0.01 2013-5-6 9:16 吴崎均 初版
* V0.02 2013-5-6 18:02 吴崎均 完成分页查询
* V0.03 2013-5-7 17:28 吴崎均 增加订单状态设置(置为:生产、完成)并加上以限制(如:线上订单不可置为完成)、
* 增加批量删除并予以限制(只能删除未受理的厂商新增订单)、
* 增加受理操作并加以限制(只有未受理的订单才能受理)
*
*
*
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.EC;
using CY.Model;
using CY.BLL.Sys;
using CY.Infrastructure.Common;
using CY.BLL;
using CY.WebForm.Pages.common;
using System.IO;
using CY.Infrastructure.Query;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
namespace CY.WebForm.Pages.business
{
///
/// 订单列表界面类
///
public partial class ShejiOrderList : BasePage
{
EC_OrderBasicBLL _eC_OrderBasicBLL = null;
OA_StaffBLL bll_OA_StaffBLL = null;
LF_OrderFileBLL _lF_OrderFileBLL = null;
///
/// 初始化构造
///
public ShejiOrderList()
{
_eC_OrderBasicBLL = new EC_OrderBasicBLL();
bll_OA_StaffBLL = new OA_StaffBLL();
_lF_OrderFileBLL = new LF_OrderFileBLL();
}
///
/// 加载事件
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Request["isSession"] != null)
{
if (!IsPostBack && !IsCallback)
Session["ShejiOrderList"] = null;
}
if (Request["downId"] != null)
{
int iDownId = Convert.ToInt32(Request["downId"]);
LF_OrderFile model = _lF_OrderFileBLL.GetModel(iDownId);
model.FileState = 1;
_lF_OrderFileBLL.UpdateModel(model);
string fileName = "";//客户端保存的文件名
string filePath = "";//路径
if (model != null)
{
fileName = model.FileName;//客户端保存的文件名
filePath = model.FilePath;//路径
}
else
{
JavaScript.MessageBox("文件不存在", this);
return;
}
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
if (fileInfo.Exists == true)
{
const long ChunkSize = 102400;//100K 每次读取文件,只读取100K,这样可以缓解服务器的压力
byte[] buffer = new byte[ChunkSize];
Response.Clear();
System.IO.FileStream iStream = System.IO.File.OpenRead(filePath);
long dataLengthToRead = iStream.Length;//获取下载的文件总大小
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName));
while (dataLengthToRead > 0 && Response.IsClientConnected)
{
int lengthRead = iStream.Read(buffer, 0, Convert.ToInt32(ChunkSize));//读取的大小
Response.OutputStream.Write(buffer, 0, lengthRead);
Response.Flush();
dataLengthToRead = dataLengthToRead - lengthRead;
}
Response.Close();
}
Response.Redirect("/Pages/business/ShejiOrderList.aspx");
return;
}
switch (Request["Target"])
{
case "AcceptOrder":
Accept();
break;
case "SuodanOrder":
Suodan();
break;
case "AcceptOrderAll":
AcceptAll();
break;
case "ChangeState":
//ChangeOrderState();
break;
case "BatchDelete":
CY.WebForm.cs.WebUtil.DeleteData(_eC_OrderBasicBLL.DeleteDataByIds, CurrentUser.ShortName);//调用通用删除方法
break;
case "BatchToOver":
UpdataState(-1);//设置状态为完成(不能是1'未受理'或2'已受理')
break;
case "BatchToProduction":
//UpdataState(3);//设置状态为生产中(不能是1'未受理'或2'已受理')
break;
case "BatchToSend":
UpdataState(4);//设置状态为已完工 (不能是1'未受理'或2'已受理')
break;
case "ToAccountDelay":
Delay(1);//请求打款延期
break;
case "DeliveryDelay":
Delay(2);//请求交货延期
break;
case "OrderRepeal":
Delay(3);//请求撤单
break;
case "ReplyRequest"://答复订单请求
RequestReply();
break;
case "RetireOrderBySeller": //卖家直接撤单,或者
RetireOrderBySeller();
break;
case "CanPrintAwb":
CanPrintAwb();
break;
default:
Page_Load_Default();
return;
}
}
catch (Exception ex)
{
PAGEHandleException(ex);
Response.Clear();
//Response.Write("参数错误");
Response.Write(ex.Message);
}
Response.End();
}
///
/// 判断是否可以批量打印送货单
///
public void CanPrintAwb()
{
EC_AcceptWayByOrderBLL _AcceptWayByOrderBLL = new EC_AcceptWayByOrderBLL();
string orderIds = Request["orderIds"].ToString();
string[] orderIdArry = orderIds.Split(',');
bool IsFirst = true;
string firstAccepterAddress = string.Empty;
string result = string.Empty;
string jsonStr = "IsCan:'true'";
string msg = "只有送货上门且送货地址相同的订单才能打印送货单";
Guid? DeliveryOrderId = Guid.Empty;
foreach (string orderIdStr in orderIdArry)
{
int orderId = orderIdStr.ToInt32().Value;
EC_AcceptWayByOrder model = _AcceptWayByOrderBLL.GetModelByTargetId(orderId);
EC_OrderBasic eC_OrderBasic = _eC_OrderBasicBLL.SelectModelById(orderId);
if (model == null)
continue;
if (IsFirst)
{
firstAccepterAddress = model.AccepterAddress.Trim();
DeliveryOrderId = eC_OrderBasic.DeliveryOrderId;
}
if (model.AcceptTypeId.Value != 106)
{
jsonStr = "IsCan:'false',Msg:'" + msg + "'";
break;
}
if (model.AccepterAddress.Trim() != firstAccepterAddress)
{
jsonStr = "IsCan:'false',Msg:'" + msg + "'";
break;
}
if (!eC_OrderBasic.DeliveryOrderId.Equals(DeliveryOrderId))
{
jsonStr = "IsCan:'false',Msg:'订单属于不同的送货单!'";
break;
}
IsFirst = false;
}
result = "{" + jsonStr + "}";
Response.Write(result);
}
///
/// 更新状态
///
private void UpdataState(int stateId)
{
Response.Clear();
if (1 == stateId || 2 == stateId)
{
HttpContext.Current.Response.Write(-2);
return;
}
string paramValue = HttpContext.Current.Request["ids"];
//string stateStr=HttpContext.Current.Request["state"];
string remark = string.Format("{0}", Request["remark"]);
int? tempId;
//tempId = string.IsNullOrEmpty(stateStr)?null:MyConvert.ConvertToInt32(stateStr);
if (string.IsNullOrEmpty(paramValue)/*||!tempId.HasValue*/)
{
HttpContext.Current.Response.Write(-2);
return;
}
else
{
}
//int stateId=tempId.Value;
string[] splitResult = paramValue.Split(',');
int i = -1;
List oprates = new List();
while (++i < splitResult.Length)
{
tempId = MyConvert.ConvertToInt32(splitResult[i]);
if (!tempId.HasValue)
{
HttpContext.Current.Response.Write(-2);
return;
}
else
{
}
oprates.Add(new EC_OrderOperate()
{
OperateType = stateId,
OrderId = tempId.Value,
Operator = CurrentUser.ShortName,
Remark = remark
});
}
HttpContext.Current.Response.Write((_eC_OrderBasicBLL.UpdateOrderState(oprates.ToArray()) ? 1 : 0));
}
///
/// 受理订单(全部订单受理)
///
private void Accept()
{
Response.Clear();
PayAbout payAbout = new PayAbout();
payAbout.LoadNewestPaymentAccount(true);
double? commission = MyConvert.ConvertToDouble(CY.Config.WebInfo.Instance.FirmOrderAgencyFee);
int? orderId = string.IsNullOrEmpty(Request["id"]) ? null : MyConvert.ConvertToInt32(Request["id"]);
if (!orderId.HasValue || !commission.HasValue)
{
Response.Write("-2");
return;
}
else
{
}
Response.Write(_eC_OrderBasicBLL.AcceptOrder(orderId.Value, commission.Value) ? "1" : "0");
}
///
/// 锁单
///
private void Suodan()
{
Response.Clear();
int? orderId = string.IsNullOrEmpty(Request["id"]) ? null : MyConvert.ConvertToInt32(Request["id"]);
if (!orderId.HasValue)
{
Response.Write("-2");
return;
}
else
{
}
Response.Write(_eC_OrderBasicBLL.SuodingOrder(orderId.Value, CurrentUser.ShortName) ? "1" : "0");
}
///
/// 批量受理订单
///
public void AcceptAll()
{
Response.Clear();
PayAbout payAbout = new PayAbout();
payAbout.LoadNewestPaymentAccount(true);
double? commission = MyConvert.ConvertToDouble(CY.Config.WebInfo.Instance.FirmOrderAgencyFee);
string orderIds = string.Empty;
;
if (Request["ids"] != null)
{
orderIds = Request["ids"].ToString();
}
if (string.IsNullOrEmpty(orderIds) || !commission.HasValue)
{
Response.Write("-2");
return;
}
else
{
}
Response.Write(_eC_OrderBasicBLL.AcceptOrderAll(orderIds, commission.Value) ? "1" : "0");
}
///
/// 改变订单状态(暂时不启用)
///
private void ChangeOrderState()
{
Response.Clear();
string idsStr = Request["ids"];
string stateIdStr = Request["stateId"];
string remark = string.Format("{0}", Request["remark"]);
int? stateId = string.IsNullOrEmpty(stateIdStr) ? null : MyConvert.ConvertToInt32(stateIdStr);
if (string.IsNullOrEmpty(idsStr) || !stateId.HasValue)
{
Response.Write("-2");
return;
}
else
{
}
string[] ids = idsStr.Split(',');
int i = -1;
int? tempId = null;
List operaters = new List();
while (++i < ids.Length)
{
tempId = string.IsNullOrEmpty(ids[i]) ? null : MyConvert.ConvertToInt32(ids[i]);
if (!tempId.HasValue)
{
operaters = null;
break;
}
else
{
}
operaters.Add(new EC_OrderOperate()
{
OrderId = tempId.Value,
Operator = CurrentUser.ShortName,
OperateType = stateId.Value,
Remark = remark
});
}
if (null == operaters)
{
Response.Write("-2");
return;
}
else
{
}
Response.Write(_eC_OrderBasicBLL.UpdateOrderState(operaters.ToArray()) ? "1" : "0");
}
///
/// 卖家退单
///
public void RetireOrderBySeller()
{
string orderidStr = Request["orderid"];
string tovalueStr = Request["tovalue"];
int orderId = orderidStr.ToInt32().Value;
decimal retireMony = tovalueStr.ToDecimal2().Value;
string operatorName = CurrentUser.ShortName;
Response.Write(_eC_OrderBasicBLL.RetireOrderBySeller(orderId, retireMony, operatorName));
}
///
/// 请求延期
///
/// 请求类型
private void Delay(int typeId)
{
Response.Clear();
string receiverStr = Request["receiver"];
string orderidStr = Request["orderid"];
string tovalueStr = Request["tovalue"];
if (string.IsNullOrEmpty(receiverStr) || string.IsNullOrEmpty(orderidStr) || string.IsNullOrEmpty(tovalueStr))
{
Response.Write(0);
return;
}
else
{
}
int? orderid = MyConvert.ConvertToInt32(orderidStr);
int? tovalue = MyConvert.ConvertToInt32(tovalueStr);
Guid receiver = MyConvert.ConvertToGuid(receiverStr);
if (Guid.Empty == receiver || !orderid.HasValue || !tovalue.HasValue)
{
Response.Write(0);
return;
}
else
{
}
EC_OrderDialogue _eC_OrderDialogue = new EC_OrderDialogue();
_eC_OrderDialogue.ReceiverId = receiver;
_eC_OrderDialogue.TargetOrder = orderid;
_eC_OrderDialogue.TargetValue = tovalue;
_eC_OrderDialogue.DialogueTypeId = typeId;
_eC_OrderDialogue.InitiatorId = CurrentUser.MemberId;
_eC_OrderDialogue.DialogueContent = string.Format("{0}", Request["dialoguecontent"]);
//开始请求
Response.Write(_eC_OrderBasicBLL.OrderPropertyChangeRequest(_eC_OrderDialogue));
}
///
/// 答复清单请求
///
private void RequestReply()
{
Response.Clear();
string ridStr = Request["did"];
string isAllowStr = Request["isAllow"];
Guid rid = MyConvert.ConvertToGuid(ridStr);
bool? isAllow = Convert.ToBoolean(isAllowStr);
if (Guid.Empty == rid || !isAllow.HasValue)
{
Response.Write(0);
return;
}
else
{
}
Response.Write(_eC_OrderBasicBLL.OrderPropertyChangeReply(rid, CurrentUser.MemberId, isAllow.Value));
}
///
/// 默认执行方法
///
private void Page_Load_Default()
{
UCPager1.AspNetPager.PageChanged += AspNetPager_PageChanged;
btn_Search.Click += btn_Search_Click;
txtCommission.Value = CY.Config.WebInfo.Instance.FirmOrderAgencyFee;
//List dialogues = _eC_OrderBasicBLL.SelectPropertyChangeRequest(CurrentUser.MemberId) as List;
if (!IsPostBack && !IsCallback)
{
Sys_DictionaryBLL _sys_DictionaryBLL = new Sys_DictionaryBLL();//字典业务逻辑操作类对象
SysInquiry_PrintingTypeBLL _sysInquiry_PrintingTypeBLL = new SysInquiry_PrintingTypeBLL();//印刷业务类型业务逻辑操作类对象
this.selPrintTypes.DataSource = _sysInquiry_PrintingTypeBLL.SelectUsedModles();
this.selPrintTypes.DataBind();
this.selPrintTypes.Items.Insert(0, new ListItem("全部", ""));
this.selPrintTypes.Items.Add(new ListItem("其他", "-1"));
this.selBusinessManager.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, true, false);
this.selBusinessManager.DataTextField = "Name";
this.selBusinessManager.DataValueField = "Keyid";
this.selBusinessManager.DataBind();
this.selBusinessManager.Items.Insert(0, new ListItem("全部", ""));
this.selShejirenyuan.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, null, null).Where(x => x.DepartmentId == 13); ;
this.selShejirenyuan.DataBind();
this.selShejirenyuan.Items.Insert(0, new ListItem("全部", ""));
this.txtBeginData.Value = DateTime.Now.AddDays(-14).ToString("yyyy-MM-dd");
this.txtEndDate.Value = DateTime.Now.ToString("yyyy-MM-dd");
//初次数据加载
btn_Search_Click(btn_Search, new EventArgs());
}
}
#region 查询
///
/// 搜索按钮点击事件
///
///
///
private void btn_Search_Click(object sender, EventArgs e)
{
Dictionary searchParam = new Dictionary();
UCPager1.AspNetPager.CurrentPageIndex = 1;//重置页数
//再次查询
AspNetPager_PageChanged(UCPager1.AspNetPager, new EventArgs());
}
///
/// 分页事件
///
///
///
private void AspNetPager_PageChanged(object sender, EventArgs e)
{
//UCPager1.AspNetPager.PageSize = 3;
Infrastructure.Query.Pagination pagination = new Infrastructure.Query.Pagination()
{
PageSize = UCPager1.AspNetPager.PageSize,
PageIndex = UCPager1.AspNetPager.CurrentPageIndex
};
IEnumerable result = _eC_OrderBasicBLL.SelectModelPageSheji(pagination, CurrentUser.MemberId,this.txtBeginData.Value,this.txtEndDate.Value,this.txtOrderId.Value
,this.selPrintTypes.Value,this.selBusinessManager.Value,this.selShejirenyuan.Value,this.txtBuyerName.Value,this.txtDocumentName.Value,this.selShejiStatus.SelectedValue);
foreach (var eC_OrderBasic in result)
{
if(eC_OrderBasic.BusinessManagerId.HasValue && eC_OrderBasic.BusinessManagerId.Value > 0)
{
var oA_Staff = bll_OA_StaffBLL.GetModelByKeyid(eC_OrderBasic.BusinessManagerId);
if (oA_Staff != null)
{
eC_OrderBasic.BusinessManager = oA_Staff.Name;
}
}
eC_OrderBasic.Shejiticheng = eC_OrderBasic.ShejirenyuanName + eC_OrderBasic.Shejicount + "*" + (eC_OrderBasic.ShejiUnitPrice.HasValue? eC_OrderBasic.ShejiUnitPrice.Value.ToString("G29"):"0") + "=" + (eC_OrderBasic.ShejiSumPrice.HasValue ? eC_OrderBasic.ShejiSumPrice.Value.ToString("G29") : "0");
if (eC_OrderBasic.PrintTypeId == 6 || eC_OrderBasic.PrintTypeId == 15 || eC_OrderBasic.PrintTypeId == 38)
{
eC_OrderBasic.Shejiticheng += "
" + eC_OrderBasic.ShejirenyuanNameneiye + eC_OrderBasic.Shejicountneiye + "*" + (eC_OrderBasic.ShejiUnitPriceneiye.HasValue ? eC_OrderBasic.ShejiUnitPriceneiye.Value.ToString("G29") : "0") + "=" + (eC_OrderBasic.ShejiSumPriceneiye.HasValue ? eC_OrderBasic.ShejiSumPriceneiye.Value.ToString("G29") : "0");
}
eC_OrderBasic.Shejicountneiyename = (eC_OrderBasic.Shejicountneiye.HasValue && eC_OrderBasic.Shejicountneiye.Value > 0) ? eC_OrderBasic.Shejicountneiye.Value.ToString() : "";
}
rptData.DataSource = result;
rptData.DataBind();
UCPager1.AspNetPager.RecordCount = pagination.RecordCount;
}
//查询事件
protected void btn_Daochu_Click(object src, EventArgs e)
{
byte[] fileBytes = ExportToExcel();
if (fileBytes != null)
{
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("Content-Disposition", "attachment; filename=订单导出.xlsx");
Response.BinaryWrite(fileBytes);
Response.End();
}
else
{
// 处理导出失败的情况
Response.Write("导出失败,请稍后重试!");
}
}
public byte[] ExportToExcel()
{
byte[] bt = null;
try
{
Pagination pa = new Pagination();
pa.PageSize = 500;
pa.PageIndex = 1;
var result = _eC_OrderBasicBLL.SelectModelPageSheji(pa, CurrentUser.MemberId, this.txtBeginData.Value, this.txtEndDate.Value, this.txtOrderId.Value
, this.selPrintTypes.Value, this.selBusinessManager.Value, this.selShejirenyuan.Value, this.txtBuyerName.Value, this.txtDocumentName.Value, this.selShejiStatus.SelectedValue);
foreach (var eC_OrderBasic in result)
{
if (eC_OrderBasic.BusinessManagerId.HasValue && eC_OrderBasic.BusinessManagerId.Value > 0)
{
var oA_Staff = bll_OA_StaffBLL.GetModelByKeyid(eC_OrderBasic.BusinessManagerId);
if (oA_Staff != null)
{
eC_OrderBasic.BusinessManager = oA_Staff.Name;
}
}
eC_OrderBasic.Shejiticheng = eC_OrderBasic.ShejirenyuanName + eC_OrderBasic.Shejicount + "*" + eC_OrderBasic.ShejiUnitPrice + "=" + eC_OrderBasic.ShejiSumPrice;
if (eC_OrderBasic.PrintTypeId == 6 || eC_OrderBasic.PrintTypeId == 15 || eC_OrderBasic.PrintTypeId == 38)
{
eC_OrderBasic.Shejiticheng += " " + eC_OrderBasic.ShejirenyuanNameneiye + eC_OrderBasic.Shejicountneiye + "*" + eC_OrderBasic.ShejiUnitPriceneiye + "=" + eC_OrderBasic.ShejiSumPriceneiye;
}
eC_OrderBasic.Shejicountneiyename = (eC_OrderBasic.Shejicountneiye.HasValue && eC_OrderBasic.Shejicountneiye.Value > 0) ? eC_OrderBasic.Shejicountneiye.Value.ToString() : "";
}
// 创建工作簿
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet = workbook.CreateSheet("导出数据");
// 创建表头
IRow headerRow = sheet.CreateRow(0);
headerRow.CreateCell(0).SetCellValue("编号");
headerRow.CreateCell(1).SetCellValue("订单号");
headerRow.CreateCell(2).SetCellValue("客户单位");
headerRow.CreateCell(3).SetCellValue("业务经理");
headerRow.CreateCell(4).SetCellValue("订单类型");
headerRow.CreateCell(5).SetCellValue("印件名称");
headerRow.CreateCell(6).SetCellValue("内页页码");
headerRow.CreateCell(7).SetCellValue("印刷数量");
headerRow.CreateCell(8).SetCellValue("单价");
headerRow.CreateCell(9).SetCellValue("金额");
headerRow.CreateCell(10).SetCellValue("设计提成");
// 添加数据
int rowIndex = 1;
foreach (var order in result)
{
IRow row = sheet.CreateRow(rowIndex++);
row.CreateCell(0).SetCellValue((rowIndex - 1).ToString());
row.CreateCell(1).SetCellValue(order.SellerOrderId);
row.CreateCell(2).SetCellValue(order.BuyerName);
row.CreateCell(3).SetCellValue(order.BusinessManager);
row.CreateCell(4).SetCellValue(order.PrintType.PrintName);
row.CreateCell(5).SetCellValue(order.DocumentName);
row.CreateCell(6).SetCellValue((order.Shejicountneiye.HasValue&& order.Shejicountneiye.Value>0) ? order.Shejicountneiye.Value.ToString() : "");
row.CreateCell(7).SetCellValue(order.OrderExtend.PrintNum.HasValue ? order.OrderExtend.PrintNum.Value : 0);
row.CreateCell(8).SetCellValue(order.UnitPrice.HasValue ? order.UnitPrice.Value.ToDouble2().Value : 0);
row.CreateCell(9).SetCellValue(order.SumPrice.HasValue ? order.SumPrice.Value.ToDouble2().Value : 0);
row.CreateCell(10).SetCellValue(order.Shejiticheng);
}
// 将工作簿写入内存流
using (var ms = new MemoryStream())
{
workbook.Write(ms);
bt = ms.ToArray();
}
}
catch (Exception e)
{
bt = null;
// 记录日志
}
return bt;
}
///
/// 是否已经操作
///
///
///
///
///
public bool IsOpearted(object keyidObj, object orderStateObj, object opTypeObj)
{
int keyid = (int)keyidObj;
int orderState = (int)orderStateObj;
string opType = (string)opTypeObj;
return _eC_OrderBasicBLL.IsOpearted(keyid, orderState, opType);
}
#endregion
}
}