/**
* 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;
namespace CY.WebForm.Pages.business
{
///
/// 订单列表界面类
///
public partial class OrderList : BasePage
{
EC_OrderBasicBLL _eC_OrderBasicBLL = null;
OA_StaffBLL bll_OA_StaffBLL = null;
LF_OrderFileBLL _lF_OrderFileBLL = null;
///
/// 初始化构造
///
public OrderList()
{
_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["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/OrderList.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.selOrderTypes.DataSource = _sys_DictionaryBLL.GetDataByType("EC_订单类型");
this.selOrderTypes.DataBind();
this.selOrderTypes.Items.Insert(0, new ListItem("全部", ""));
this.selPayStates.DataSource = _sys_DictionaryBLL.GetDataByType("EC_订单支付状态");
this.selPayStates.DataBind();
this.selPayStates.Items.Insert(0, new ListItem("全部", ""));
this.selOrderStates.DataSource = _sys_DictionaryBLL.GetDataByType("EC_订单状态").Where(p => p.MeanValue.Value != -5 && p.MeanValue.Value != -4);
this.selOrderStates.DataBind();
this.selOrderStates.Items.Insert(0, new ListItem("全部", ""));
this.selCustormerLevels.DataSource = _sys_DictionaryBLL.GetDataByType("客户重要程度");
this.selCustormerLevels.DataBind();
this.selCustormerLevels.Items.Insert(0, new ListItem("全部", ""));
this.selPayType.DataSource = _sys_DictionaryBLL.GetDataByType("EC_支付方式");
this.selPayType.DataTextField = "Name";
this.selPayType.DataValueField = "MeanValue";
this.selPayType.DataBind();
this.selPayType.Items.Insert(0, new ListItem("全部", ""));
this.selCustormerManager.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, false, true);
this.selCustormerManager.DataTextField = "Name";
this.selCustormerManager.DataValueField = "Keyid";
this.selCustormerManager.DataBind();
this.selCustormerManager.Items.Insert(0, new ListItem("全部", ""));
//this.selCustormerManager.Items.Insert(1, new ListItem(CurrentUser.ShortName, CurrentUser.ShortName));
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.selBusinessManager.Items.Insert(1, new ListItem(CurrentUser.ShortName, CurrentUser.ShortName));
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();
SetParamValue(searchParam, 1, CurrentUser.MemberId);
SetParamValue(searchParam, 2, this.txtOrderId.Value.Trim());
SetParamValue(searchParam, 3, this.txtCustormerName.Value.Trim());
SetParamValue(searchParam, 4, this.txtBeginData.Value.Trim());
SetParamValue(searchParam, 5, this.txtEndDate.Value.Trim());
SetParamValue(searchParam, 6, this.selPrintTypes.Value);
SetParamValue(searchParam, 7, this.selOrderTypes.Value);
SetParamValue(searchParam, 8, this.selOrderStates.Value);
SetParamValue(searchParam, 9, this.selPayStates.Value);
SetParamValue(searchParam, 10, this.txtCreaterName.Value.Trim());
SetParamValue(searchParam, 11, this.selCustormerLevels.Value);
SetParamValue(searchParam, 12, this.selCustormerManager.Value);
SetParamValue(searchParam, 13, this.selBusinessManager.Value);
SetParamValue(searchParam, 14, this.selPayType.SelectedValue);
SetParamValue(searchParam, 15, this.selReturnvisit.SelectedValue);
SetParamValue(searchParam, 16, this.selAppraise.SelectedValue);
SetParamValue(searchParam, 18, (CurrentUser.StaffId > 0 ? 1 : 0));
SetParamValue(searchParam, 19, CurrentUser.TrueMemberId);
SetParamValue(searchParam, 20, CurrentUser.StaffId);
SetParamValue(searchParam, 21, CurrentUser.TrueName);
SetParamValue(searchParam, 28, this.txtSearchyjname.Value);
if (!IsPostBack && !IsCallback)
{
if (Session["OrderList"] != null)
{
//先还原表单
searchParam = Session["OrderList"] as Dictionary;
if (searchParam.Keys.Count(x => x == 4)<=0)
{
this.txtBeginData.Value = "";
}
if (searchParam.Keys.Count(x => x == 5) <= 0)
{
this.txtEndDate.Value = "";
}
foreach (int index in searchParam.Keys)
{
if (index == 2)
this.txtOrderId.Value = searchParam[index].ToString();
if (index == 3)
this.txtCustormerName.Value = searchParam[index].ToString();
if (index == 4)
this.txtBeginData.Value = searchParam[index].ToString();
if (index == 5)
this.txtEndDate.Value = searchParam[index].ToString();
if (index == 6)
this.selPrintTypes.Value = searchParam[index].ToString();
if (index == 7)
this.selOrderTypes.Value = searchParam[index].ToString();
if (index == 8)
this.selOrderStates.Value = searchParam[index].ToString();
if (index == 9)
this.selPayStates.Value = searchParam[index].ToString();
if (index == 10)
this.txtCreaterName.Value = searchParam[index].ToString();
if (index == 11)
this.selCustormerLevels.Value = searchParam[index].ToString();
if (index == 12)
this.selCustormerManager.Value = searchParam[index].ToString();
if (index == 13)
this.selBusinessManager.Value = searchParam[index].ToString();
if (index == 14)
this.selPayType.SelectedValue = searchParam[index].ToString();
if (index == 15)
this.selReturnvisit.SelectedValue = searchParam[index].ToString();
if (index == 16)
this.selAppraise.SelectedValue = searchParam[index].ToString();
if (index == 28)
this.txtSearchyjname.Value = searchParam[index].ToString();
}
SetParamValue(searchParam, 1, CurrentUser.MemberId);
SetParamValue(searchParam, 18, (CurrentUser.StaffId > 0 ? 1 : 0));
SetParamValue(searchParam, 19, CurrentUser.TrueMemberId);
SetParamValue(searchParam, 20, CurrentUser.StaffId);
SetParamValue(searchParam, 21, CurrentUser.TrueName);
SetParamValue(searchParam, 28, this.txtSearchyjname.Value);
}
}
else
{
Session["OrderList"] = searchParam;
}
SearchParam = searchParam;
UCPager1.AspNetPager.CurrentPageIndex = 1;//重置页数
//再次查询
AspNetPager_PageChanged(UCPager1.AspNetPager, new EventArgs());
}
///
/// 设置查询参数方法
///
/// 设置目标
/// 键
/// 值
private static void SetParamValue(Dictionary target, int key, object value)
{
if (string.IsNullOrEmpty(string.Format("{0}", value)))
return;
else
{
}
if (target.ContainsKey(key))
{
target[key] = value;
}
else
{
target.Add(key, value);
}
}
///
/// 分页事件
///
///
///
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.SelectModelPage_Seller(pagination, SearchParam);
rptData.DataSource = result;
rptData.DataBind();
UCPager1.AspNetPager.RecordCount = pagination.RecordCount;
}
///
/// 查询参数
///
private Dictionary SearchParam
{
get
{
return ViewState["SearchParam"] as Dictionary;
}
set
{
ViewState["SearchParam"] = value;
}
}
///
/// 是否可以操作
///
///
///
///
///
public bool IsCanOpearte(object keyidObj, object orderStateObj, object outIdObj, object opTypeObj)
{
bool isCan = false;
int keyid = (int)keyidObj;
int orderState = (int)orderStateObj;
string opType = (string)opTypeObj;
int outId = (int)outIdObj;
if (orderState == -2)
{
return false;
}
if (opType == "回访" || opType == "评价" || opType == "投诉")
{
if (orderState == 1)
{
isCan = false;
}
else
{
isCan = true;
}
}
else
{
if (outId > 0)
{
return false;
}
if (orderState == 0)
{
isCan = false;
}
else if (orderState == -1)
{
if (opType != "送货")
{
isCan = false;
}
else
{
isCan = true;
}
}
else
{
if (opType == "受理")
{
if (orderState == 1)
{
isCan = true;
}
}
else
{
if (orderState == 1)
{
isCan = false;
}
else
{
if (opType == "撤单")
{
if (orderState == 4 || orderState == 5)
{
isCan = false;
}
else
{
isCan = true;
}
}
else
{
isCan = true;
}
}
}
}
}
return isCan;
}
///
/// 是否已经操作
///
///
///
///
///
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
}
}