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;
using CY.BLL.OA;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
namespace CY.WebForm.Pages.Property
{
//吴辉
//卖家评价
public partial class ShebeiWeixiuAdd : BasePage
{
EC_OrderBasicBLL bll_EC_OrderBasicBLL = null;
OA_FukuanshenqingBLL _oA_FukuanshenqingBLL = null;
OA_SubjectSetBLL _OA_SubjectSetBLL = null;
OA_StaffBLL bll_OA_StaffBLL = null;
OA_WorkPlanBll oA_WorkReminderBll = null;
OA_ShebeiManageBLL oA_ShebeiManageBLL = null;
OA_ShebeiWeixiuBLL oA_ShebeiWeixiuBLL = null;
string url = "https://yocaisim.51zhengcai.com/api/CYOSSetting/GetShowID";// "http://192.168.0.36:5000/api/CYOSSetting/GetShowID";
//初始化
public ShebeiWeixiuAdd()
{
bll_EC_OrderBasicBLL = new EC_OrderBasicBLL();
_oA_FukuanshenqingBLL = new OA_FukuanshenqingBLL();
bll_OA_StaffBLL = new OA_StaffBLL();
oA_WorkReminderBll = new OA_WorkPlanBll();
oA_ShebeiManageBLL = new OA_ShebeiManageBLL();
oA_ShebeiWeixiuBLL = new OA_ShebeiWeixiuBLL();
_OA_SubjectSetBLL = new OA_SubjectSetBLL();
}
//页面加载
protected void Page_Load(object sender, EventArgs e)
{
try
{
switch (Request["Target"])
{
case "change":
Response.Write(reLoadAccountName(Request["TypeName"].ToString2()));
break;
case "GetSuplier":
LoadCommunication();
break;
default:
if (!IsPostBack)
{
InitData();
}
return;
}
}
catch (Exception ex)
{
PAGEHandleException(ex);
Response.Clear();
//Response.Write("-1");
Response.Write(ex.Message);
}
Response.End();
}
//绑定数据
public void InitData()
{
//供应商
this.selShebei.DataSource = oA_ShebeiManageBLL.SelectAllModel(null).Where(x=>x.Status == 2);
this.selShebei.DataBind();
//this.selShebei.Items.Insert(0, new ListItem("全部", ""));
this.selZerenren.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, null, null);
this.selZerenren.DataTextField = "Name";
this.selZerenren.DataValueField = "Keyid";
this.selZerenren.DataBind();
this.selZerenren.Items.Insert(0, new ListItem("全部", ""));
this.selZerenren.Value = "";
this.txtWeixiuTime.Value = DateTime.Now.ToString("yyyy-MM-dd");
}
protected string reLoadAccountName(string selAcoountType)
{
var query = new Infrastructure.Query.Query();
if (!string.IsNullOrEmpty(selAcoountType))
{
return JsonHelper.GetJsonStringByObject(oA_ShebeiManageBLL.SelectAllModel(query).Where(x => x.Status != 1 && x.Zerenren == selAcoountType.ToInt32()));
}
else
{
return JsonHelper.GetJsonStringByObject(oA_ShebeiManageBLL.SelectAllModel(query).Where(x => x.Status != 1));
}
}
///
/// 加载供应商
///
private void LoadCommunication()
{
//Response.Clear();
//string id = Request["id"];
//if (string.IsNullOrEmpty(id))
//{
// Response.Write("-2");
// return;
//}
//var oA_Suppliers = _OA_SuppliersBLL.getSingleSupplier(id);
//Response.Write(null == oA_Suppliers ? "" : JsonHelper.GetJsonStringByObject(oA_Suppliers));
}
//提交事件
protected void btn_Submit_form(object sender, EventArgs e)
{
AcceptAll3();
}
///
/// 批量开票申请
///
public void AcceptAll3()
{
if (string.IsNullOrEmpty(this.selShebei.Value))
{
JavaScript.MessageBox("请选择维修设备!", this);
return;
}
if (this.selShifoufukuan.Value == "1" && string.IsNullOrEmpty(this.txtWeixiuPrice.Value))
{
JavaScript.MessageBox("请输入申请金额!", this);
return;
}
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadCommitted,
Timeout = TransactionManager.MaximumTimeout
}
)
)
{
try
{
bool result = false;
DateTime nowTime = DateTime.Now;
var oA_ShebeiWeixiu = new OA_ShebeiWeixiu();
oA_ShebeiWeixiu.MemberId = CurrentUser.MemberId;
oA_ShebeiWeixiu.ShebeiId = this.selShebei.Value.ToInt32();
oA_ShebeiWeixiu.WeixiuTime = this.txtWeixiuTime.Value.ToDateTime2();
var shebeiManage = oA_ShebeiManageBLL.GetModelByKeyid(oA_ShebeiWeixiu.ShebeiId);
var ShebeiZerenrenName = "";
if (shebeiManage != null)
{
oA_ShebeiWeixiu.CateId = shebeiManage.CateId;
oA_ShebeiWeixiu.Anzhuangdidian = shebeiManage.Anzhuangdidian;
oA_ShebeiWeixiu.Name = shebeiManage.Name;
ShebeiZerenrenName = shebeiManage.ZerenrenName;
}
oA_ShebeiWeixiu.Remark = this.txtPlanRemark.Value;
oA_ShebeiWeixiu.WeixiuPrice = this.txtWeixiuPrice.Value.ToDecimal2();
oA_ShebeiWeixiu.Zerenren = 0;
oA_ShebeiWeixiu.ZerenrenName = "";
oA_ShebeiWeixiu.DanzePrice = 0;
oA_ShebeiWeixiu.Shifoufufei = 2;
oA_ShebeiWeixiu.CreateTime = nowTime;
oA_ShebeiWeixiu.Creator = CurrentUser.ShortName;
oA_ShebeiWeixiu.LastUpdateTime = nowTime;
oA_ShebeiWeixiu.Operator = CurrentUser.ShortName;
//需要添加审批信息
OA_WorkPlan m_OA_WorkPlan = new OA_WorkPlan();
if (this.selShifoufukuan.Value == "1" )
{
oA_ShebeiWeixiu.Fukuanfangshi = this.selFukuanfangshi.Value;
if(oA_ShebeiWeixiu.Fukuanfangshi == "1")
{
OA_Fukuanshenqing oA_Fukuanshenqing = new OA_Fukuanshenqing();
oA_Fukuanshenqing.FirmId = CurrentUser.MemberId;
oA_Fukuanshenqing.SupplierId = "0";
oA_Fukuanshenqing.Fukuanshenqingstatus = 0;
oA_Fukuanshenqing.ApprovalStatus = 0;
oA_Fukuanshenqing.Molingmoney = 0;
oA_Fukuanshenqing.Fukuanmoney = this.txtWeixiuPrice.Value.ToDecimal2();
oA_Fukuanshenqing.Bank = "";
oA_Fukuanshenqing.Huming = "";
oA_Fukuanshenqing.AccountID = "";
oA_Fukuanshenqing.Yishoumoney = 0;
oA_Fukuanshenqing.Youwufapiao = 0;
oA_Fukuanshenqing.Fukuanyongtu = "设备维修费";
oA_Fukuanshenqing.FukuanStatus = 1;
oA_Fukuanshenqing.remark = "";
oA_Fukuanshenqing.DindanId = "";
oA_Fukuanshenqing.Creater = CurrentUser.ShortName;
oA_Fukuanshenqing.CreateTime = nowTime;
oA_Fukuanshenqing.Updater = CurrentUser.ShortName;
oA_Fukuanshenqing.LastUpdateTime = nowTime;
//var oA_Suppliers = _OA_SuppliersBLL.getSingleSupplier(this.selSuppliers.Value);
//var _SupplierName = "";
//if (oA_Suppliers != null)
//{
// _SupplierName = oA_Suppliers.Name;
//}
var _SupplierName = oA_ShebeiWeixiu.Name + "(" + ShebeiZerenrenName + ")" + "维修";
oA_Fukuanshenqing.SupplierName = _SupplierName;
var id = _oA_FukuanshenqingBLL.InsertModel(oA_Fukuanshenqing);
oA_ShebeiWeixiu.FukuanshenqingId = id;
m_OA_WorkPlan.PlanComplany = id.ToString();
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.PlanTitle = oA_ShebeiWeixiu.Name + "(" + ShebeiZerenrenName + ")" + "维修申请";
m_OA_WorkPlan.PlanDataType = 18;
m_OA_WorkPlan.PlanMoney = this.txtWeixiuPrice.Value.ToDecimal2();
m_OA_WorkPlan.RewardMoney = 0;
m_OA_WorkPlan.PlanRemark = "";
m_OA_WorkPlan.PlanRunTime = DateTime.Now;
m_OA_WorkPlan.PlanContent = this.txtPlanRemark.Value + ".维修日期:" + this.txtWeixiuTime.Value;
m_OA_WorkPlan.PlanType = 3;
m_OA_WorkPlan.LastUpdateTime = nowTime;
}
else
{
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.EvaluationStaff = "";
m_OA_WorkPlan.EvaluationStaffId = Guid.Empty;
m_OA_WorkPlan.EvaluationStatus = 2;
m_OA_WorkPlan.EvaluationTime = nowTime;
m_OA_WorkPlan.RewardMoney = 0;
m_OA_WorkPlan.RewardType = 1;
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;
if (string.IsNullOrEmpty(m_OA_WorkPlan.EvaluationContent))
{
try
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
string content = reader.ReadToEnd();
JavaScriptSerializer serializer = new JavaScriptSerializer();
var person = serializer.Deserialize(content);
if (person != null && person.code == 1)
{
m_OA_WorkPlan.EvaluationContent = person.data;
}
else
{
JavaScript.MessageBox("生成报销单号失败", this);
return;
}
}
}
}
catch (Exception ex)
{
JavaScript.MessageBox("生成报销单号失败", this);
return;
}
}
var oA_SubjectSet =_OA_SubjectSetBLL.getAllSubject(CurrentUser.MemberId, "贷").Where(x=>x.SubjectName == "维修配件").FirstOrDefault();
if (oA_SubjectSet != null)
{
m_OA_WorkPlan.RewardResult = oA_SubjectSet.Keyid.ToString();
m_OA_WorkPlan.RewardContent = oA_SubjectSet.SubjectName;
}
else
{
m_OA_WorkPlan.RewardResult = "0";
m_OA_WorkPlan.RewardContent = "其他";
}
oA_ShebeiWeixiu.FukuanshenqingId = 0;
m_OA_WorkPlan.PlanComplany = "";
m_OA_WorkPlan.Operator = CurrentUser.ShortName;
m_OA_WorkPlan.HoubufapiaoStatus = 3;
m_OA_WorkPlan.PlanContent = oA_ShebeiWeixiu.Name + "(" + ShebeiZerenrenName + ")" + "维修申请." + this.txtPlanRemark.Value + ".维修日期:" + this.txtWeixiuTime.Value; ;
m_OA_WorkPlan.PlanDataType = 17;
m_OA_WorkPlan.PlanMoney = this.txtWeixiuPrice.Value.Trim().ToDecimal2() ?? 0;
m_OA_WorkPlan.PlanRemark = "";
m_OA_WorkPlan.PlanRunTime = DateTime.Now;
m_OA_WorkPlan.PlanTitle = oA_ShebeiWeixiu.Name + "(" + ShebeiZerenrenName + ")" + "维修申请";
m_OA_WorkPlan.PlanType = 3;
m_OA_WorkPlan.LastUpdateTime = nowTime;
}
}
else
{
m_OA_WorkPlan.PlanComplany = "";
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.PlanTitle = oA_ShebeiWeixiu.Name + "(" + ShebeiZerenrenName + ")" + "维修申请";
m_OA_WorkPlan.PlanDataType = 18;
m_OA_WorkPlan.PlanMoney = this.txtWeixiuPrice.Value.ToDecimal2();
m_OA_WorkPlan.RewardMoney = 0;
m_OA_WorkPlan.PlanRemark = "";
m_OA_WorkPlan.PlanRunTime = DateTime.Now;
m_OA_WorkPlan.PlanContent = this.txtPlanRemark.Value + ".维修日期:" + this.txtWeixiuTime.Value;
m_OA_WorkPlan.PlanType = 3;
m_OA_WorkPlan.LastUpdateTime = nowTime;
}
var workid = oA_WorkReminderBll.InserModelAndGetId(m_OA_WorkPlan);
m_OA_WorkPlan.Keyid = workid;
if (workid > 0)
{
oA_ShebeiWeixiu.WeixiuShebeiId = workid;
if (this.selShifoufukuan.Value == "1")
{
oA_ShebeiWeixiu.FukuanShebeiId = workid;
}
var ssss = oA_ShebeiWeixiuBLL.InsertModel(oA_ShebeiWeixiu);
}
result = true;
if (!result)
{
return;
}
//}
scope.Complete();
}
catch (Exception ex)
{
// 回滚事务
}
finally
{
// 释放资源
scope.Dispose();
}
}
//JavaScript.MessageBox("提交成功", this);
//操作成功
JavaScript.MessageBox("提交成功", this, true, true);
}
}
}