/**
* 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.Transactions;
namespace CY.WebForm.Pages.business
{
public partial class Waixiefukuanweikaipiao : BasePage
{
EC_OrderBasicBLL _eC_OrderBasicBLL = null;
OA_StaffBLL bll_OA_StaffBLL = null;
LF_OrderFileBLL _lF_OrderFileBLL = null;
EC_OrderBLL _eC_OrderBLL = null;
OA_FukuanshenqingBLL oA_FukuanshenqingBLL = null;
///
/// 初始化构造
///
public Waixiefukuanweikaipiao()
{
_eC_OrderBasicBLL = new EC_OrderBasicBLL();
bll_OA_StaffBLL = new OA_StaffBLL();
_lF_OrderFileBLL = new LF_OrderFileBLL();
_eC_OrderBLL = new EC_OrderBLL();
oA_FukuanshenqingBLL = new OA_FukuanshenqingBLL();
}
///
/// 加载事件
///
///
///
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/OrderListBatchOperation.aspx");
return;
}
switch (Request["Target"])
{
case "deleteOrderAll2":
AcceptAll2();
break;
case "deleteOrderAll3":
AcceptAll3();
break;
case "AcceptOrder":
Accept();
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 = "只有送货上门且送货地址相同的订单才能打印送货单";
foreach (string orderIdStr in orderIdArry)
{
int orderId = orderIdStr.ToInt32().Value;
EC_AcceptWayByOrder model = _AcceptWayByOrderBLL.GetModelByTargetId(orderId);
if (model == null)
continue;
if (IsFirst)
{
firstAccepterAddress = model.AccepterAddress.Trim();
}
if (model.AcceptTypeId.Value != 106)
{
jsonStr = "IsCan:'false',Msg:'" + msg + "'";
break;
}
if (model.AccepterAddress.Trim() != firstAccepterAddress)
{
jsonStr = "IsCan:'false',Msg:'" + 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");
}
///
/// 批量受理订单
///
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 ToBatchRemove()
{
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 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.txtSQBeginDate.Value = DateTime.Now.AddDays(-14).ToString("yyyy-MM-dd");
this.txtSQEndDate.Value = DateTime.Now.ToString("yyyy-MM-dd");
//初次数据加载
btn_Search_Click(btn_Search, new EventArgs());
}
}
#region 查询
///
/// 搜索按钮点击事件
///
///
///
private void btn_Search_Click(object sender, EventArgs e)
{
/* if (this.txtCustormerName.Value.Trim() == "")
{
Response.Write("客户名称不能为空,请输入客户名称再查询……");
return;
}*/
//Dictionary searchParam = new Dictionary();
//SetParamValue(searchParam, 1, CurrentUser.MemberId);
//SetParamValue(searchParam, 2, "");
//SetParamValue(searchParam, 3, this.txtCustormerName.Value.Trim());
//SetParamValue(searchParam, 4, "");
//SetParamValue(searchParam, 5, "");
//SetParamValue(searchParam, 6, "");
//SetParamValue(searchParam, 7, "");
//SetParamValue(searchParam, 8, "");
//SetParamValue(searchParam, 9, this.selPayStates.Value);
//SetParamValue(searchParam, 10, "");
//SetParamValue(searchParam, 11, "");
//SetParamValue(searchParam, 12, "");
//SetParamValue(searchParam, 13, this.selBusinessManager.Value);
//SetParamValue(searchParam, 14, "");
//SetParamValue(searchParam, 15, "");
//SetParamValue(searchParam, 16, "");
//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, 22, this.txtSQBeginDate.Value);
//SetParamValue(searchParam, 23, this.txtSQEndDate.Value);
//SetParamValue(searchParam, 24, this.selKaipiaoshenqing.Value);
//SetParamValue(searchParam, 25, this.selKehuqianshou.Value);
//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 = oA_FukuanshenqingBLL.SelectModelPageweikaipiao(pagination, CurrentUser.MemberId, this.txtSQBeginDate.Value, this.txtSQEndDate.Value, this.txtCreatorName.Value, this.txtCustormerName.Value,"");
rptData.DataSource = result;
rptData.DataBind();
heji.InnerText = String.Format("{0:F2}", result.Sum(x => x.Fukuanmoney));
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);
}
///
/// 批量去除订单
///
public void AcceptAll2()
{
Response.Clear();
string ids = string.Empty;
if (Request["ids"] != null)
{
ids = Request["ids"].ToString();
}
string[] idsArray = ids.Split(',');
using (TransactionScope scope = new TransactionScope())
{
if (idsArray != null && idsArray.Length > 0)
{
for (int i = 0; i < idsArray.Length; i++)
{
bool result = true;
EC_OrderExtend model = new EC_OrderExtend();
model.Keyid = idsArray[i].ToInt32();
model.QuchudingdanCreater = CurrentUser.TrueMemberId;
model.QuchudingdanTime = DateTime.Now;
model.Quchudingdan = 1;
result = _eC_OrderBLL.OldUpdateQuchudingdan(model);
if (!result)
{
//Page_Load_Default();
Response.Write("-2");
return;
}
}
}
scope.Complete();
}
// Page_Load_Default();
Response.Write("1");
}
///
/// 批量开票申请
///
public void AcceptAll3()
{
Response.Clear();
string ids = string.Empty;
if (Request["ids"] != null)
{
ids = Request["ids"].ToString();
}
string[] idsArray = ids.Split(',');
using (TransactionScope scope = new TransactionScope())
{
if (idsArray != null && idsArray.Length > 0)
{
DateTime kaipiaoshenqing = DateTime.Now;
for (int i = 0; i < idsArray.Length; i++)
{
bool result = true;
EC_OrderExtend model = new EC_OrderExtend();
model.Keyid = idsArray[i].ToInt32();
model.KaipiaoshenqingCreater = CurrentUser.TrueMemberId;
model.KaipiaoshenqingTime = kaipiaoshenqing;
model.Kaipiaoshenqing = 1;
result = _eC_OrderBLL.OldUpdateKaipiaoshenqing(model);
if (!result)
{
//Page_Load_Default();
Response.Write("-2");
return;
}
}
}
scope.Complete();
}
// Page_Load_Default();
Response.Write("1");
}
#endregion
}
}