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.Infrastructure.Common;
using CY.BLL.Integrity;
using CY.BLL;
using System.Threading.Tasks;
using System.Transactions;
namespace CY.WebForm.Pages.business
{
//吴辉
//卖家评价
public partial class kaipiaoConfirm : BasePage
{
EC_OrderBasicBLL bll_EC_OrderBasicBLL = null;
EC_OrderBLL _eC_OrderBLL = null;
OA_KaipiaoshenqingBLL _oA_KaipiaoshenqingBLL = null;
OA_CorporateClientsBLL _oA_CorporateClientsBLL = null;
OA_StaffBLL bll_OA_StaffBLL = null;
OA_WorkPlanBll oA_WorkReminderBll = null;
//初始化
public kaipiaoConfirm()
{
bll_EC_OrderBasicBLL = new EC_OrderBasicBLL();
_eC_OrderBLL = new EC_OrderBLL();
_oA_CorporateClientsBLL = new OA_CorporateClientsBLL();
_oA_KaipiaoshenqingBLL = new OA_KaipiaoshenqingBLL();
bll_OA_StaffBLL = new OA_StaffBLL();
oA_WorkReminderBll = new OA_WorkPlanBll();
}
//页面加载
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitData();
}
}
//绑定数据
public void InitData()
{
string orderIdStr = Request["id"];
if (!string.IsNullOrEmpty(orderIdStr))
{
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));
decimal total = 0;
string name = "";
this.txtOrderIds.Value = orderIdStr;
// string[] idsArray = orderIdStr.Split(',');
//if (idsArray != null && idsArray.Length > 0)
//{
var models = _eC_OrderBLL.GetOrderByIds(orderIdStr).ToList();
if(models!=null&& models.Count > 0)
{
var model = bll_EC_OrderBasicBLL.SelectModelById(models[0].Keyid.Value);
name = models[0].BuyerName;
OA_CorporateClients oA_CorporateClients = _oA_CorporateClientsBLL.GetModel(models[0].BuyerId);
if (oA_CorporateClients != null)
{
this.selBusinessManager.Value = oA_CorporateClients.BusinessManagerId.HasValue ? oA_CorporateClients.BusinessManagerId.Value.ToString() : "";
}
}
total = models.Sum(x=>x.SumPrice)??0;
txtZengjianmoney.Value = "0";
//foreach (var item in idsArray)
//{
// var model = _eC_OrderBLL.GetOrderById(int.Parse(item));
// if (model != null)
// {
// total += model.SumPrice??0;
// if(string.IsNullOrEmpty(name))
// {
// name = model.BuyerName;
// }
// }
//}
//}
kpmoney.InnerText = total.ToString("0.00");
khname.InnerText = name;
Dingdanshu.InnerText = orderIdStr.Split(',').Length +"个";
}
else
{
JavaScript.CloseDIVOpener(this);
}
}
//提交事件
protected void btn_Submit_form(object sender, EventArgs e)
{
AcceptAll3();
}
///
/// 批量开票申请
///
public void AcceptAll3()
{
string ids = this.txtOrderIds.Value;
string[] idsArray = ids.Split(',');
if (idsArray != null && idsArray.Length > 0)
{
EC_OrderBasic eC_OrderBasic = bll_EC_OrderBasicBLL.SelectModelById(idsArray[0].ToInt32().Value);
OA_CorporateClients oA_CorporateClients = _oA_CorporateClientsBLL.SelectModelByFirmIdandMemberId(CurrentUser.MemberId, eC_OrderBasic.BuyerId);
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadCommitted,
Timeout = TransactionManager.MaximumTimeout
}
)
)
{
try
{
string ssss = DateTime.Now.ToString("yyyyMMdd");
string SellerOrderId = ssss + 1.ToString("000");
string maxSellerOrderId = _oA_KaipiaoshenqingBLL.GetModelByformid(CurrentUser.MemberId).Where(x => x.SellerOrderId.Contains(ssss)).Max(x => x.SellerOrderId);
if (!string.IsNullOrWhiteSpace(maxSellerOrderId))
{
string aaaaaaaaaaaa = maxSellerOrderId.Substring(maxSellerOrderId.Length - 3, 3);
SellerOrderId = ssss + (aaaaaaaaaaaa.ToInt32().Value + 1).ToString("000");
}
OA_Kaipiaoshenqing oA_DeliverPlan = new OA_Kaipiaoshenqing();
oA_DeliverPlan.Keyid = Guid.NewGuid();
oA_DeliverPlan.FirmId = CurrentUser.MemberId;
oA_DeliverPlan.BuyerId = eC_OrderBasic.BuyerId;
oA_DeliverPlan.Kaipiaoshenqing = 1;
oA_DeliverPlan.Kehuqianshou = 1;
oA_DeliverPlan.SellerOrderId = SellerOrderId;
oA_DeliverPlan.remark = this.txtContent.Value;//.Replace("\r\n", "
");
oA_DeliverPlan.KehuqianshouTime = null;
oA_DeliverPlan.KehuqianshouCreater = null;
oA_DeliverPlan.KaipiaoquerenTime = null;
oA_DeliverPlan.KaipiaoquerenCreater = null;
oA_DeliverPlan.BusinessManagerId = this.selBusinessManager.Value.ToInt32();
oA_DeliverPlan.Zengjianmoney = this.txtZengjianmoney.Value.ToDecimal2();
oA_DeliverPlan.kpmoney = this.kpmoney.InnerText.ToDecimal2();
oA_DeliverPlan.ApprovalStatus = 1;
oA_DeliverPlan.Dingdanshu = ids.Trim(',').Split(',').Length;
if (oA_DeliverPlan.Zengjianmoney < 0)
{
oA_DeliverPlan.ApprovalStatus = 0;
//需要添加审批信息
DateTime nowTime = DateTime.Now;
OA_WorkPlan m_OA_WorkPlan = new OA_WorkPlan();
m_OA_WorkPlan.ApprovalContent = "";
m_OA_WorkPlan.ApprovalStaffId = Guid.Empty;
m_OA_WorkPlan.ApprovalStaffName = "";
m_OA_WorkPlan.ApprovalStatus = 0;
m_OA_WorkPlan.ApprovalTime = nowTime;
m_OA_WorkPlan.EvaluationContent = "";
m_OA_WorkPlan.EvaluationStaff = "";
m_OA_WorkPlan.EvaluationStaffId = Guid.Empty;
m_OA_WorkPlan.EvaluationStatus = 0;
m_OA_WorkPlan.EvaluationTime = nowTime;
m_OA_WorkPlan.RewardContent = "";
m_OA_WorkPlan.RewardMoney = 0;
m_OA_WorkPlan.RewardResult = "";
m_OA_WorkPlan.RewardType = 0;
m_OA_WorkPlan.PlanStartTime = nowTime;
m_OA_WorkPlan.PlanStatus = 1;
m_OA_WorkPlan.SentStaffId = CurrentUser.TrueMemberId;
m_OA_WorkPlan.MemberId = CurrentUser.MemberId;
OA_Staff m_OA_Staff = bll_OA_StaffBLL.GetModelByMemberId(CurrentUser.TrueMemberId);
if (m_OA_Staff != null)
m_OA_WorkPlan.DepartId = m_OA_Staff.DepartmentId;
else
m_OA_WorkPlan.DepartId = 0;
m_OA_WorkPlan.PlanPeople = CurrentUser.TrueName;
m_OA_WorkPlan.ReciveStaffId = CurrentUser.TrueMemberId;
m_OA_WorkPlan.Operator = CurrentUser.ShortName;
m_OA_WorkPlan.PlanComplany = oA_DeliverPlan.Keyid.ToString();
m_OA_WorkPlan.PlanContent = this.khname.InnerText+" 减少金额开票申请";
m_OA_WorkPlan.PlanDataType = 13;
m_OA_WorkPlan.PlanMoney = oA_DeliverPlan.Zengjianmoney;
m_OA_WorkPlan.PlanRemark = oA_DeliverPlan.remark;
m_OA_WorkPlan.PlanRunTime = DateTime.Now;
m_OA_WorkPlan.PlanTitle = this.khname.InnerText + " 减少金额开票申请";
m_OA_WorkPlan.PlanType = 3;
m_OA_WorkPlan.LastUpdateTime = nowTime;
oA_WorkReminderBll.InsertModel(m_OA_WorkPlan);
}
oA_DeliverPlan.Shenqingleixing = "订单开票";
oA_DeliverPlan.Creater = CurrentUser.TrueMemberId;
oA_DeliverPlan.CreateTime = DateTime.Now;
oA_DeliverPlan.Updater = CurrentUser.TrueMemberId;
oA_DeliverPlan.LastUpdateTime = DateTime.Now;
_oA_KaipiaoshenqingBLL.InsertModel(oA_DeliverPlan);
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;
model.KaipiaoshenqingId = oA_DeliverPlan.Keyid;
result = _eC_OrderBLL.OldUpdateKaipiaoshenqings(model, ids);
if (!result)
{
return;
}
//}
scope.Complete();
}
catch (Exception ex)
{
// 回滚事务
}
finally
{
// 释放资源
scope.Dispose();
}
}
//JavaScript.MessageBox("提交成功", this);
//操作成功
JavaScript.MessageBoxsssss("提交成功", this, true, true);
}
}
}
}