You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1756 lines
72 KiB
C#

10 months ago
using System;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.CRM_QUOTATIONDAL;
using DSWeb.MvcShipping.Models.CRM_QUOTATION;
using DSWeb.MvcShipping.Models.MsOpAireBill;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using HcUtility.Comm;
using HcUtility.Core;
using System.Collections.Generic;
using System.IO;
using System.Data;
using System.Data.OleDb;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.RptMng.Comm;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsOpApply;
using DSWeb.MvcShipping.DAL.MsOpApplyDAL;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.TruckMng.Helper.Repository;
using System.Net;
using System.Net.Mail;
using Microsoft.Office.Interop.Excel;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL;
using DSWeb.MvcShipping.Models.MsOpSeae;
using DSWeb.MvcShipping.DAL.MsCompanysDAL;
using DSWeb.MvcShipping.Models.MsChFee;
using DSWeb.EntityDA;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using DSWeb.DataAccess;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class CRM_QUOTATION_CUSTController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition,string load)
{
var dataList = CRM_QUOTATIONDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort, load);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition,string BLTYPE)
{
CRM_QUOTATIONmb head = null;
if (handle == "edit")
{
head = CRM_QUOTATIONDAL.GetData(condition);
}
if (head == null)
{
head = new CRM_QUOTATIONmb();
head.BLSTATUS = "0";
head.PORTLOAD = "CNTAO";
head.VALIDDATE = DateTime.Now.ToString();
head.ASKDATE = DateTime.Now.ToString();
/*
head.OP = Convert.ToString(Session["SHOWNAME"]);
head.INPUTBY= Convert.ToString(Session["SHOWNAME"]);
head.CUSTSERVICE = Convert.ToString(Session["SHOWNAME"]);
head.PFREIGHT = "0";
head.PVALUEFEE = "0";
head.PCARRIEROT = "0";
head.POTFREIGHT = "0";
head.PTOTAL = "0";
head.CFREIGHT = "0";
head.CVALUEFEE = "0";
head.CCARRIEROT = "0";
head.COTFREIGHT = "0";
head.CTOTAL = "0";*/
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetCARRIERList ( string condition)
{
var dataList = CRM_QUOTATIONDAL.GetCARRIERList(condition);
var list = dataList;
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult Save ( string opstatus, string data, string DetailBody, string DetailDelBody, string CARRIERBody )
{
var aaa = "";
//var dataall = data.Replace("}", ",") + (data2.Replace("{", "")).Replace("}", ",") + data3.Replace("{", "");
//var dataall = data.Replace("}", ",") + data2.Replace("{", "");
var headData = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data);
var DetailbodyList = JsonConvert.Deserialize<List<CRM_QUOTATION_DETAILmb>>(DetailBody);
var DetaildelbodyList = JsonConvert.Deserialize<List<CRM_QUOTATION_DETAILmb>>(DetailDelBody);
var CARRIERbodyList = JsonConvert.Deserialize<List<CRM_QUOTATION_CARRIERmb>>(CARRIERBody);
if (opstatus == "add")
{
headData.GID = PubSysDAL.GetBillNo("0403");
}
var isPost = true;
var errorstr = "";
var isuse = false;
var iscreatecustno = false;
if (headData.CORPID == ""||headData.CORPID ==null)
{
headData.CORPID = Convert.ToString(Session["COMPANYID"]);
}
/*
if (headData.MBLNO != "" && headData.MBLNO != null && headData.BLTYPE == "国内主单" )
{
var ct = CRM_QUOTATIONDAL.GetRdCount(" MBLNO='" + headData.MBLNO + "' and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "' and BLTYPE='国内主单'");
if (ct != 0)
{
isPost = false;
errorstr = "主单号";
}
}
*/
if (opstatus == "add")
{
//headData.INPUTBY = Convert.ToString(Session["SHOWNAME"]);
headData.CREATETIME = DateTime.Now.ToString();
//headData.BSSTATUS = false;
//headData.FEESTATUS = false;
headData.DbOperationType = DbOperationType.DbotIns;
headData.ModelUIStatus = "I";
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
//if (headData.MASTERNO == null || headData.MASTERNO =="") { headData.MASTERNO = headData.BSNO; }
if (headData.ETA == "") headData.ETA = null;
if (headData.ETD == "") headData.ETD = null;
//if (headData.STLDATE == "") headData.STLDATE = null;
//if (headData.INSPECTIONDATE == "") headData.INSPECTIONDATE = null;
//if (headData.CUSTOMDATE == "") headData.CUSTOMDATE = null;
////headData.PORTLOAD = MsBaseInfoDAL.DelPortCn(headData.PORTLOAD);
////headData.PORTDISCHARGE = MsBaseInfoDAL.DelPortCn(headData.PORTDISCHARGE);
//var BSNO = headData.BSNO;
/*
if (headData.BLTYPE == "国内主单" && headData.MASTERNO!="" && opstatus!="add")
{
//如果是编辑 需要根据MASTERNO清除库存主单使用记录
CRM_QUOTATIONDAL.ExecSql(" update op_airn_RECEIPT set RSTATUS='入库',OP='" + Convert.ToString(Session["SHOWNAME"]) + "',OPDATE=getdate() where GID=(select Masterno from OP_AIRN where BSNO='" + headData.BSNO + "') ");
}*/
if (isPost)
{
headData.MODIFIEDUSER = Convert.ToString(Session["SHOWNAME"]);
headData.MODIFIEDTIME = DateTime.Now.ToString();
var UPD="update CRM_QUOTATION set PORTLOAD='"+headData.PORTLOAD+"',PORTDISCHARGE='"+headData.PORTDISCHARGE+"'"
+ " ,ETD='" + headData.ETD + "',ETA='" + headData.ETA + "'"
+ " ,TT='" + headData.TT + "',GOODSNAME='" + headData.GOODSNAME + "'"
+ " ,_20GP=" + headData._20GP + ",_40GP=" + headData._40GP + ""
+ " ,_40HC=" + headData._40HC + ",_45=" + headData._45 + ""
+ " ,CTN='" + headData.CTN + "',CTN2='" + headData.CTN2 + "'"
+ " ,CTNNUM=" + headData.CTNNUM + ",CTNNUM2=" + headData.CTNNUM2 + ""
+ " ,REMARK='" + headData.REMARK + "'"
+" where GID in(select CARRIERCQGID from CRM_QUOTATION_LINK where CUSTCQGID='"+headData.GID+"')";
var modb = new ModelObjectRepository();
DBResult result = modb.Save(headData,
ModelObjectConvert<CRM_QUOTATION_DETAILmb>.ToModelObjectList(DetailbodyList),
ModelObjectConvert<CRM_QUOTATION_DETAILmb>.ToModelObjectList(DetaildelbodyList),
ModelObjectConvert<CRM_QUOTATION_CARRIERmb>.ToModelObjectList(CARRIERbodyList),
null);
/*
else
{
//MsSysBillNoSetDAL.DeleteBsNo(headData.CUSTNO);
} */
if (result.Success == true) {
CRM_QUOTATIONDAL.ExecSql(UPD);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = CRM_QUOTATIONDAL.GetData("CQ.GID='" + headData.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
/*
if (iscreatecustno == true)
MsSysBillNoSetDAL.DeleteBsNo(headData.CUSTNO);
* */
var jsonRespose = new JsonResponse { Success = false, Message =errorstr+"重复,不允许保存!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult SaveChild ( string opstatus, string data, string parentgid, string DetailBody, string DetailDelBody )
{
var headData = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data);
if (opstatus == "add" && headData.GID == "")
{
headData.GID = PubSysDAL.GetBillNo("0403");
}
CRM_QUOTATIONDAL.ExecSql(" delete from CRM_QUOTATION_LINK where CUSTCQGID='" + parentgid + "' and CARRIERCQGID='" + headData.GID + "'");
CRM_QUOTATIONDAL.ExecSql(" insert into CRM_QUOTATION_LINK (GID,CUSTCQGID,CARRIERCQGID) values(newid(), '" + parentgid + "','" + headData.GID + "') ");
return Save(opstatus, data, DetailBody, DetailDelBody,null);
}
public ContentResult SetUse ( string DetailBody)
{
var DetailbodyList = JsonConvert.Deserialize<List<CRM_QUOTATION_DETAILmb>>(DetailBody);
var GIDList = "";
foreach (var _d in DetailbodyList) {
if (GIDList == "")
{
GIDList = "'"+_d.GID+"'";
}
else {
GIDList = GIDList+",'" + _d.GID + "'";
}
}
var SQL = "Update crm_quotation_detail set ISUSE=1-isnull(ISUSE,0) where GID in(" + GIDList + ")";
var _r = CRM_QUOTATIONDAL.ExecSql(SQL);
var jsonRespose = new JsonResponse();
if (_r > 0) {
jsonRespose = new JsonResponse
{
Success = true,
Message = "设置完成",
Data = null
};
}else
jsonRespose = new JsonResponse
{
Success = false,
Message = "设置0条数据",
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AddChild ( string opstatus, string data )
{
var aaa = "";
var headData = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data);
if (opstatus == "add")
{
headData.GID = PubSysDAL.GetBillNo("0403");
}
var isPost = true;
var errorstr = "";
var isuse = false;
var iscreatecustno = false;
if (headData.CORPID == "" || headData.CORPID == null)
{
headData.CORPID = Convert.ToString(Session["COMPANYID"]);
}
if (opstatus == "add")
{
//headData.INPUTBY = Convert.ToString(Session["SHOWNAME"]);
headData.CREATETIME = DateTime.Now.ToString();
//headData.BSSTATUS = false;
//headData.FEESTATUS = false;
headData.DbOperationType = DbOperationType.DbotIns;
headData.ModelUIStatus = "I";
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
if (headData.ETA == "") headData.ETA = null;
if (headData.ETD == "") headData.ETD = null;
if (isPost)
{
headData.MODIFIEDUSER = Convert.ToString(Session["SHOWNAME"]);
headData.MODIFIEDTIME = DateTime.Now.ToString();
if (headData.BLSTATUS == "0")
{
headData.BLSTATUS = "1";
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(headData);
if (result.Success == true) {
var Child = new CRM_QUOTATIONmb();
Child.GID = PubSysDAL.GetBillNo("0403");
Child.CREATETIME = DateTime.Now.ToString();
Child.CREATEUSER = Convert.ToString(Session["SHOWNAME"]);
Child.DbOperationType = DbOperationType.DbotIns;
Child.ModelUIStatus = "I";
Child.BLTYPE = "供应商报价";
Child.PORTLOAD = headData.PORTLOAD;
Child.PORTDISCHARGE = headData.PORTDISCHARGE;
Child.ETD = headData.ETD;
Child.ETA = headData.ETA;
Child.QUOTATIONDATE = headData.QUOTATIONDATE;
Child.CARRIER = headData.CARRIER;
Child.ENTREPORT = headData.ENTREPORT;
Child.TT = headData.TT;
Child.GOODSNAME = headData.GOODSNAME;
Child._20GP = headData._20GP;
Child._40GP = headData._40GP;
Child._40HC = headData._40HC;
Child._45 = headData._45;
Child.CTN = headData.CTN;
Child.CTN2 = headData.CTN2;
Child.CTNNUM = headData.CTNNUM;
Child.CTNNUM2 = headData.CTNNUM2;
Child.CREATEUSER = Convert.ToString(Session["SHOWNAME"]);
Child.MODIFIEDUSER = Convert.ToString(Session["SHOWNAME"]);
Child.CREATETIME = DateTime.Now.ToString();
Child.MODIFIEDTIME = DateTime.Now.ToString();
Child.ASKDATE = DateTime.Now.ToString();
var modb2 = new ModelObjectRepository();
result = modb2.Save(Child);
if (result.Success == true) {
CRM_QUOTATIONDAL.ExecSql(" delete from CRM_QUOTATION_LINK where CUSTCQGID='" + headData.GID + "' and CARRIERCQGID='" + Child.GID + "'");
CRM_QUOTATIONDAL.ExecSql(" insert into CRM_QUOTATION_LINK (GID,CUSTCQGID,CARRIERCQGID) values(newid(), '" + headData.GID + "','" + Child.GID + "') ");
CRM_QUOTATIONDAL.ExecSql(" insert into CRM_QUOTATION_CARRIER (GID,LINKGID,CARRIER,FREEDAYS) select newid(),'" + Child.GID + "',CARRIER,0 from CRM_QUOTATION_CARRIER where LINKGID='" + headData.GID + "' ");
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = CRM_QUOTATIONDAL.GetData("CQ.GID='" + headData.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var jsonRespose = new JsonResponse { Success = false, Message = errorstr + "重复,不允许保存!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult SaveChild2(string ChildBody)
{
var ChildBodyList = JsonConvert.Deserialize<List<CRM_QUOTATIONmb>>(ChildBody);
if (ChildBodyList != null)
{
foreach (var _h in ChildBodyList)
{
_h.MODIFIEDTIME = DateTime.Now.ToString();
_h.MODIFIEDUSER = Session["SHOWNAME"].ToString();
}
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(
ModelObjectConvert<CRM_QUOTATIONmb>.ToModelObjectList(ChildBodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Delete(string data)
{
var head = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data);
var isfee = CRM_QUOTATIONDAL.GetFeeCount(head.GID);
if (isfee)
{
var jsonRespose = new JsonResponse { Success = false, Message ="此报价单内存在报价,请先删除她的所有报价才能删除此报价单!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
var BSNO = head.GID;
var modb = new ModelObjectDB();
DBResult result = new DBResult();
result = modb.Delete(head);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult Delete2 ( string data )
{
var head = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data);
var BSNO = head.GID;
var modb = new ModelObjectDB();
DBResult result = new DBResult();
result = modb.Delete(head, " delete from crm_QUOTATION_DETAIL where LINKGID='" + BSNO + "'");
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AddDetail ( string BJ_GID, string XJ_GID,string CARRIER )
{
//向客户报价的单号;向供应商询价的单号;船公司名
var jsonRespose = new JsonResponse
{
Success = false,
Message = "",
Data = null
};
var _carrierList = BasicDataRefDAL.GeneralSelect("select CARRIER GVALUE, GID from CRM_QUOTATION_CARRIER where LINKGID='" + BJ_GID + "' and LINKGID2='" + XJ_GID + "' and CARRIER='" + CARRIER + "'");
if (_carrierList.Count() > 0)
{
jsonRespose.Success = true;
jsonRespose.Message = "已有船公司信息";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdupdate = db.GetSqlStringCommand("insert into CRM_QUOTATION_CARRIER (GID,LINKGID,LINKGID2,CARRIER,FREEDAYS,REMARK,VALIDDATE,VALIDDATE_END) select top 1 newid(),'"
+ BJ_GID + "','" + XJ_GID + "',CARRIER,FREEDAYS,REMARK,VALIDDATE,VALIDDATE_END from CRM_QUOTATION_CARRIER where LINKGID='" + XJ_GID + "' and CARRIER='" + CARRIER + "'");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
//db.AddInParameter(cmdupdate, "@GID", DbType.String, billno);
db.ExecuteNonQuery(cmdupdate, tran);
jsonRespose.Success = true;
jsonRespose.Message = "添加成功";
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
jsonRespose.Success = false;
jsonRespose.Message = e.Message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
//return result;
}
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
//var billList = bill.Split(',');
}
public ContentResult DelDetail ( String bill )
{
var result = new DBResult();
var billList = bill.Split(',');
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var billno in billList)
{
var cmdupdate = db.GetSqlStringCommand("delete from CRM_QUOTATION_DETAIL where GID=@GID ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, billno);
db.ExecuteNonQuery(cmdupdate, tran);
}
result = new DBResult();
result.Success = true;
result.Message = "删除成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除错误,请重试或联系系统管理员";
//return result;
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DelCARRIER ( String bill )
{
var result = new DBResult();
var billList = bill.Split(',');
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var billno in billList)
{
var strSql = new StringBuilder();
strSql.Append(" delete from CRM_QUOTATION_DETAIL where LINKGID=(select LINKGID from CRM_QUOTATION_CARRIER where GID=@GID1) ");
strSql.Append(" and CARRIER=(select CARRIER from CRM_QUOTATION_CARRIER where GID=@GID4) ");
strSql.Append(" and (select count(*) from CRM_QUOTATION_CARRIER where carrier= (select CARRIER from CRM_QUOTATION_CARRIER where GID=@GID2) and LINKGID=(select LINKGID from CRM_QUOTATION_CARRIER where GID=@GID5) )<=1 ");
strSql.Append(" delete from CRM_QUOTATION_CARRIER where GID=@GID3 ");
var cmdupdate = db.GetSqlStringCommand(strSql.ToString());
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID1", DbType.String, billno);
db.AddInParameter(cmdupdate, "@GID2", DbType.String, billno);
db.AddInParameter(cmdupdate, "@GID3", DbType.String, billno);
db.AddInParameter(cmdupdate, "@GID4", DbType.String, billno);
db.AddInParameter(cmdupdate, "@GID5", DbType.String, billno);
db.ExecuteNonQuery(cmdupdate, tran);
}
result = new DBResult();
result.Success = true;
result.Message = "删除成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除错误,请重试或联系系统管理员";
//return result;
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult MakeOpseae ( string data )
{
var aaa = "";
var headData = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data);
var OpSeae = new MsOpSeae();
if (headData.CORPID == "" || headData.CORPID == null)
{
headData.CORPID = Convert.ToString(Session["COMPANYID"]);
}
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
if (headData.ETA == "") headData.ETA = null;
if (headData.ETD == "") headData.ETD = null;
headData.REMARK = headData.REMARK +" "+ DateTime.Now.ToShortDateString()+"生成海运进口业务;";
var modb = new ModelObjectRepository();
DBResult result = modb.Save(headData);
if (result.Success == true)
{
OpSeae.CREATETIME = DateTime.Now.ToString();
OpSeae.OP = Session["SHOWNAME"].ToString();
OpSeae.BSNO = "topseae" + Guid.NewGuid().ToString();
OpSeae.MASTERNO = OpSeae.BSNO;
var company = MsCompanysDAL.GetNoPicData("GID='" + Convert.ToString(Session["COMPANYID"]) + "'");
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='海运出口'", Convert.ToString(Session["COMPANYID"]), company.DBNAME);
var custno = MsSysBillNoSetDAL.GetBillNo(billnoset, headData.ETD.ToString().Trim(), DateTime.Now.ToString(), company.DBNAME);
OpSeae.CUSTNO = custno;
if (OpSeae.CUSTNO == "") {
OpSeae.CUSTNO = headData.GID;
}
var portload = BasicDataRefDAL.GetLoadportbyEDI(headData.PORTLOAD);
OpSeae.PORTLOAD = MsBaseInfoDAL.DelPortCn(portload[0].CodeAndName);
OpSeae.PORTLOADID = headData.PORTLOAD;
OpSeae.CUSTOMERNAME = headData.SHORTNAME;
var portdischarge = BasicDataRefDAL.GetCodeDisportbyEDICODE(headData.PORTDISCHARGE);
OpSeae.PORTDISCHARGE = MsBaseInfoDAL.DelPortCn(portdischarge[0].CodeAndName);
OpSeae.PORTDISCHARGEID = headData.PORTDISCHARGE;
OpSeae.CARRIER = headData.CARRIER;
OpSeae.ETD = headData.ETD;
OpSeae.REMARK = "通过报价单自动生成("+headData.GID+")";
OpSeae.DbOperationType = DbOperationType.DbotIns;
OpSeae.ModelUIStatus = "I";
var DetailList = CRM_QUOTATIONDAL.GetDetailList(" LINKGID='"+headData.GID+"'");
var FeeList = new List<MsChFee>();
foreach (var _d in DetailList) {
var _F = new MsChFee();
_F.GId = Guid.NewGuid().ToString();
_F.BsNo = "";
_F.TaxUnitPrice = Convert.ToDecimal(_d.UNITPRICE);
_F.UnitPrice = Convert.ToDecimal(_d.UNITPRICE);
_F.Unit = _d.UNIT;
_F.Quantity = 0;
_F.CustomerName = _d.SHORTNAME;
_F.FeeType = 1;
_F.FeeStatus = 1;
_F.FeeName = _d.FEENAME;
FeeList.Add(_F);
}
foreach (var _d in DetailList)
{
var _F = new MsChFee();
_F.GId = Guid.NewGuid().ToString();
_F.BsNo = "";
_F.TaxUnitPrice = Convert.ToDecimal(_d.UNITPRICE);
_F.UnitPrice = Convert.ToDecimal(_d.UNITPRICE);
_F.Unit = _d.UNIT;
_F.Quantity = 0;
//_F.CustomerName = _d.SHORTNAME;
_F.FeeType = 2;
_F.FeeStatus = 1;
_F.FeeName = _d.FEENAME;
FeeList.Add(_F);
}
var modb2 = new ModelObjectRepository();
result = modb2.Save(OpSeae
, ModelObjectConvert<MsChFee>.ToModelObjectList(FeeList)
, null
);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = CRM_QUOTATIONDAL.GetData("CQ.GID='" + headData.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = CRM_QUOTATIONDAL.GetData("CQ.GID='" + headData.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult AddDetailCarrier ( string DetailGID, string LINKGID, string NEWLINKGID, string CARRIER )
{
CRM_QUOTATIONDAL.ExecSql(" delete from CRM_QUOTATION_CARRIER where linkgid='" + NEWLINKGID + "' and carrier='" + CARRIER + "' ");
var sql2=new StringBuilder();
sql2.Append(" insert into CRM_QUOTATION_CARRIER (GID,linkgid,carrier,freedays,remark) ");
sql2.Append(" select top 1 newid(), '" + NEWLINKGID + "','" + CARRIER + "',freedays,remark from CRM_QUOTATION_CARRIER where linkgid ='" + LINKGID + "' and CARRIER='" + CARRIER + "' ");
var jsonRespose = new JsonResponse
{
Success = true,
Message = "",
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 明细信息
public ContentResult GetDetailList ( string condition )
{
var dataList = CRM_QUOTATIONDAL.GetDetailList(condition);
//var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
#endregion
#region 邮件和EXCEL模板处理
public ContentResult SendMailXJ ( string data,string data2,string URLID )
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
var head = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data);//向供应商询价
var head2 = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data2);//客户询价、向客户报价
//head2 = CRM_QUOTATIONDAL.GetData("GID='"+head2.GID+"'");
if (head.CONTACTNAME == "")
{
var json = JsonConvert.Serialize(new { Success = false, Message = "发送失败 没有设定联系人" });
return new ContentResult() { Content = json };
}
//首先获取自己和对方的邮箱
var SenderName = Session["SHOWNAME"].ToString();
var SenderEmail = "";
var SenderCompany = Session["COMPANYNAME"].ToString();
var ReceiverName = head.CONTACTNAME;
var ReceiverEmail = "";
var ReceiverCompany = head.SHORTNAME;
var strSql = new StringBuilder();
strSql.Append(" select (select EMAIL1 from user_baseinfo where USERID='" + Session["USERID"].ToString() + "') SenderEmail, ");
strSql.Append(" (select email from info_client_contact where linkid='" + head.CLIENTGID + "' and SHOWNAME='" + head.CONTACTNAME + "' ) ReceiverEmail");
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
try
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SenderEmail = Convert.ToString(reader["SenderEmail"]);
ReceiverEmail = Convert.ToString(reader["ReceiverEmail"]);
}
reader.Close();
}
}
catch (Exception)
{
}
finally
{
}
if (ReceiverEmail == "" || SenderEmail == "")
{
var json = JsonConvert.Serialize(new { Success = false, Message = "发送失败 没有设定自己(个人设置-修改个人信息)或对方联系人(往来单位-联系人信息)的邮箱地址" });
return new ContentResult() { Content = json };
}
//getemail
msg.To.Add(ReceiverEmail);
msg.From = new MailAddress(SenderEmail, Session["SHOWNAME"].ToString(), System.Text.Encoding.UTF8);
/* 上面3个参数分别是发件人地址可以随便写发件人姓名编码*/
var Subject = "";
var Body = new StringBuilder();
Subject = " 询价:From " + SenderCompany;
if (head.ETD != "")
Subject = Subject + " 船期" + head2.ETD.Substring(0, 10);
if (head.PORTLOAD != "")
Subject = Subject + " 装货港" + head2.PORTLOAD_REF;
if (head.PORTDISCHARGE != "")
Subject = Subject + " 卸货港" + head2.PORTDISCHARGE_REF;
var URL = "http://123.57.17.72:8729/index.aspx?" + URLID;
Body.Append("<html> <Body>询价公司:" + SenderCompany);
Body.Append("<br />联系人:" + SenderName );
Body.Append("<br />邮箱:" + SenderEmail );
if (head.PORTLOAD != "")
Body.Append("<br />装货港:" + head.PORTLOAD_REF);
if (head.PORTDISCHARGE != "")
Body.Append("<br />卸货港:" + head.PORTDISCHARGE_REF);
if (head.ETD != "")
Body.Append("<br />船期:" + head2.ETD.Substring(0,10));
if (head.REMARK != "")
Body.Append("<br />其他说明:" + head2.REMARK);
Body.Append("<br />");
Body.Append("<br />");
Body.Append("<a href=" + URL + ">打开报价页面,填写报价并提交</a>");
/*
Body.Append("<html> <Body>订舱公司:" + SenderCompany);
Body.Append("<br />订舱人:" + SenderName + "&nbsp;&nbsp;&nbsp;电话:" + SenderMobile + "&nbsp;&nbsp;&nbsp;邮箱:" + SenderEmail);
if (Opseae.CNTR != "")
Body.Append("<br />箱型箱量:" + Opseae.CNTR);
if (Opseae.ETD != "")
Body.Append("<br />船期:" + Opseae.ETD);
if (Opseae.CNTR != "")
Body.Append("<br />目的地:" + Opseae.DESTINATION);
if (Opseae.BOOKINGDESCRIPTION != "")
Body.Append("<br />订舱说明:" + Opseae.BOOKINGDESCRIPTION);
*/
msg.Subject = Subject;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = Body.ToString();//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
/* 使
var sfile = getXJ2(head, head2);
msg.Attachments.Add(new Attachment(sfile));
msg.Attachments[0].Name = Session["COMPANYNAME"].ToString() + "_" + Session["SHOWNAME"].ToString() + "_询价.xls";
* */
var content = "";
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(content, null, "text/html");
/*
LinkedResource lrImage = new LinkedResource(@"D:\DSWebservice\a.jpg", "image/gif");
lrImage.ContentId = "Email001";
htmlBody.LinkedResources.Add(lrImage);
msg.AlternateViews.Add(htmlBody);*/
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("admin@dongshengsoft.com", "ds!@#)(*");
//在71info.com注册的邮箱和密码
client.Host = "smtpcom.263xmail.com";
object userState = msg;
var Result = "";
try
{
//client.SendAsync(msg, userState);
//简单一点儿可以
client.Send(msg);
CRM_QUOTATIONDAL.ExecSql("update CRM_QUOTATION set ASKDATE='" + DateTime.Now.ToString() + "' , BLSTATUS=1 where GID='"+head.GID+"'");
/*
if (System.IO.File.Exists(Path.GetFullPath(sfile)))
{
System.IO.File.Delete(Path.GetFullPath(sfile));
}
*/
var json = JsonConvert.Serialize(new { Success = true, Message = "发送成功" });
return new ContentResult() { Content = json };
}
catch (System.Net.Mail.SmtpException ex)
{
Result = ex.Message;
var json = JsonConvert.Serialize(new { Success = false, Message = "发送失败 " + Result });
return new ContentResult() { Content = json };
}
}
public string getXJ ( CRM_QUOTATIONmb head, CRM_QUOTATIONmb head2 )
{
//var head = MsOpSeaeDAL.GetData("BSNO='" + mbill + "'");
var bodyList = CRM_QUOTATIONDAL.GetDetailList(" LINKGID ='"+head2.GID+"' ");
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
//Microsoft.Office.Interop.Excel.Application application = new Microsoft.Office.Interop.Excel.ApplicationClass()
var path = Server.MapPath("../../CRM_QUOTATION_EXCEL/output");
var path2 = Server.MapPath("../../CRM_QUOTATION_EXCEL/model/");
var result = new DBResult();
if (excel == null)
{
return "";
}
else
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string expfilename = path + "\\" + head.GID + ".xls";
string excelFilePath = path2 + "XJ.xls";
Workbook workbook = excel.Workbooks.Open(excelFilePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Worksheet mySheet = workbook.Sheets[1] as Worksheet;
var _i=2;
if (bodyList.Count == 0)
{
mySheet.Cells[_i, 1] = head.SHORTNAME;
mySheet.Cells[_i, 2] = head.CARRIER;
mySheet.Cells[_i, 3] = head.ETD.Substring(0,10);
mySheet.Cells[_i, 4] = head.TT;
_i++;
}
else
{
foreach (var _c in bodyList)
{
mySheet.Cells[_i, 1] = head.SHORTNAME;
mySheet.Cells[_i, 2] = head.CARRIER;
mySheet.Cells[_i, 3] = head.ETD.Substring(0, 10);
mySheet.Cells[_i, 4] = head.TT;
mySheet.Cells[_i, 5] = _c.CTN;
mySheet.Cells[_i, 10] = _c.REMARK;
_i++;
}
}
if (System.IO.File.Exists(Path.GetFullPath(expfilename)))
{
System.IO.File.Delete(Path.GetFullPath(expfilename));
}
mySheet.SaveAs(expfilename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
workbook.Close(true, Type.Missing, Type.Missing);
workbook = null;
excel.Quit();
excel = null;
var filename = Path.GetFileName(expfilename);
//return "../../CRM_QUOTATION_EXCEL/output/" + filename;
return expfilename.Replace("\\", "/");
}
}
public ContentResult SendMailBJ(string data )
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
var head2 = JsonConvert.Deserialize<CRM_QUOTATIONmb>(data);//向供应商报价
var head = CRM_QUOTATIONDAL.GetData("cq.GID='" + head2.GID + "'");
var BodyList = CRM_QUOTATIONDAL.GetDetailList("LINKGID='"+head2.GID+"'");
//查询一下报价单涉及几个船公司
/*var strSql1 = new StringBuilder();
strSql1.Append(" select distinct carrier as GVALUE ");
strSql1.Append(" ,(isnull(('目的港免箱期'+(select top 1 convert(varchar(10),freedays) from CRM_QUOTATION_CARRIER ");
strSql1.Append(" where CARRIER=crm_quotation_detail.CARRIER and LINKGID in (select linkgid2 from crm_quotation_detail where LINKGID=crm_quotation_detail.LINKGID))+'天 '),'') ");
strSql1.Append(" +isnull((' 备注'+(select top 1 remark from CRM_QUOTATION_CARRIER ");
strSql1.Append(" where CARRIER=crm_quotation_detail.CARRIER and LINKGID in (select linkgid2 from crm_quotation_detail where LINKGID=crm_quotation_detail.LINKGID))+''),'') ");
strSql1.Append(" +isnull(( ' 有效期'+(select dbo.trimdate(VALIDDATE)+'至'+dbo.trimdate(VALIDDATE_END) from CRM_QUOTATION where GID =crm_quotation_detail.linkgid2)),'') ");
strSql1.Append(" ) GID");
strSql1.Append(" from crm_quotation_detail where linkGID='" + head2.GID + "'");*/
var CarrierList = CRM_QUOTATIONDAL.GetCARRIERList(" linkGID='" + head2.GID + "'");
//var _i = 0;
//var AmountRMB = 0M;
//var AmountUSD = 0M;
if (head.CONTACTNAME == "")
{
var json = JsonConvert.Serialize(new { Success = false, Message = "发送失败 没有设定联系人" });
return new ContentResult() { Content = json };
}
//首先获取自己和对方的邮箱
var SenderName = Session["SHOWNAME"].ToString();
var SenderEmail = "";
var SenderCompany = Session["COMPANYNAME"].ToString();
var ReceiverName = head.CONTACTNAME;
var ReceiverEmail = "";
var ReceiverCompany = head.SHORTNAME;
var strSql = new StringBuilder();
strSql.Append(" select (select EMAIL1 from user_baseinfo where USERID='" + Session["USERID"].ToString() + "') SenderEmail, ");
strSql.Append(" (select email from info_client_contact where linkid='" + head.CLIENTGID + "' and SHOWNAME='" + head.CONTACTNAME + "' ) ReceiverEmail");
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
try
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
SenderEmail = Convert.ToString(reader["SenderEmail"]);
ReceiverEmail = Convert.ToString(reader["ReceiverEmail"]);
}
reader.Close();
}
}
catch (Exception)
{
}
finally
{
}
if (ReceiverEmail == "" || SenderEmail == "")
{
var json = JsonConvert.Serialize(new { Success = false, Message = "发送失败 没有设定自己(个人设置-修改个人信息)或对方联系人(往来单位-联系人信息)的邮箱地址" });
return new ContentResult() { Content = json };
}
//getemail
msg.To.Add(ReceiverEmail);
msg.From = new MailAddress(SenderEmail, Session["SHOWNAME"].ToString(), System.Text.Encoding.UTF8);
/* 上面3个参数分别是发件人地址可以随便写发件人姓名编码*/
var Subject = "";
var Body = new StringBuilder();
Subject = " 报价:From " + SenderCompany;
if (head.ETD != "")
Subject = Subject + " 船期" + head.ETD.Substring(0, 10);
if (head.PORTLOAD != "")
Subject = Subject + " 装货港" + head.PORTLOAD;
if (head.PORTDISCHARGE != "")
Subject = Subject + " 卸货港" + head.PORTDISCHARGE;
//var URL = "http://123.57.17.72/index.aspx?" + URLID;
var CTN="";
if (decimal.Parse(head._20GP) != 0M){
CTN = CTN + "20GP*" + (Convert.ToInt32(decimal.Parse(head._20GP))).ToString();
}
if (decimal.Parse(head._40GP) != 0M){
if (CTN != "") { CTN = CTN + " , "; }
CTN = CTN + " 40GP*" + (Convert.ToInt32(decimal.Parse(head._40GP))).ToString();
}
if (decimal.Parse(head._40HC) != 0M){
if (CTN != "") { CTN = CTN + " , "; }
CTN = CTN + " 40HC*" + (Convert.ToInt32(decimal.Parse(head._40HC))).ToString();
}
if (decimal.Parse(head._45) != 0M){
if (CTN != "") { CTN = CTN + " , "; }
CTN = CTN + " 45GP*" + (Convert.ToInt32(decimal.Parse(head._45))).ToString();
}
if (decimal.Parse(head.CTNNUM) != 0M){
if (CTN != "") { CTN = CTN + " , "; }
CTN = CTN + " " + head.CTN + "*" + (Convert.ToInt32(decimal.Parse(head.CTNNUM))).ToString();
}
if (decimal.Parse(head.CTNNUM2) != 0M)
{
if (CTN != "") { CTN = CTN + " , "; }
CTN = CTN + " " + head.CTN2 + "*" + (Convert.ToInt32(decimal.Parse(head.CTNNUM2))).ToString();
}
Body.Append("<html> <Body>报价公司:" + SenderCompany);
foreach (var _carrier in CarrierList)
{
string[] FEELIST = new string[BodyList.Count()];
var AmountRMB = 0M;
var AmountUSD = 0M;
var _i = 0;
//var head_Cust = new CRM_QUOTATIONmb();
foreach (var _f in BodyList)
{
if (_f.CARRIER != _carrier.CARRIER)
{
continue;
}
else
{
//head_Cust = CRM_QUOTATIONDAL.GetData("cq.GID='" + _f.LINKGID2 + "'");
var _FEE = _f.FEENAME + ":";
var feename = _f.FEENAME + ":";
var Amount = 0M;
if (decimal.Parse(_f.UNITPRICE) != 0M)
{
if (_FEE != feename) { _FEE = _FEE + "+&nbsp;"; }
_FEE = _FEE + (_f.UNITPRICE.TrimEnd('0')).TrimEnd('.') + "*1";
Amount = Amount + decimal.Parse(_f.UNITPRICE);
}
else
{
if (decimal.Parse(head._20GP) != 0M)
{
if (_FEE != feename) { _FEE = _FEE + "+&nbsp;"; }
_FEE = _FEE + (_f._20GP.TrimEnd('0')).TrimEnd('.') + "*" + (Convert.ToInt32(decimal.Parse(head._20GP))).ToString();
Amount = Amount + decimal.Parse(_f._20GP) * decimal.Parse(head._20GP);
}
if (decimal.Parse(head._40GP) != 0M)
{
if (_FEE != feename) { _FEE = _FEE + "+&nbsp;"; }
_FEE = _FEE + (_f._40GP.TrimEnd('0')).TrimEnd('.') + "*" + (Convert.ToInt32(decimal.Parse(head._40GP))).ToString();
Amount = Amount + decimal.Parse(_f._40GP) * decimal.Parse(head._40GP);
}
if (decimal.Parse(head._40HC) != 0M)
{
if (_FEE != feename) { _FEE = _FEE + "+&nbsp;"; }
_FEE = _FEE + (_f._40HC.TrimEnd('0')).TrimEnd('.') + "*" + (Convert.ToInt32(decimal.Parse(head._40HC))).ToString();
Amount = Amount + decimal.Parse(_f._40HC) * decimal.Parse(head._40HC);
}
if (decimal.Parse(head._45) != 0M)
{
if (_FEE != feename) { _FEE = _FEE + "+&nbsp;"; }
_FEE = _FEE + (_f._45.TrimEnd('0')).TrimEnd('.') + "*" + (Convert.ToInt32(decimal.Parse(head._45))).ToString();
Amount = Amount + decimal.Parse(_f._45) * decimal.Parse(head._45);
}
if (decimal.Parse(head.CTNNUM) != 0M)
{
if (_FEE != feename) { _FEE = _FEE + "+&nbsp;"; }
_FEE = _FEE + (_f.CTNPRICE.TrimEnd('0')).TrimEnd('.') + "*" + (Convert.ToInt32(decimal.Parse(head.CTNNUM))).ToString();
Amount = Amount + decimal.Parse(_f.CTNPRICE) * decimal.Parse(head.CTNNUM);
}
if (decimal.Parse(head.CTNNUM2) != 0M)
{
if (_FEE != feename) { _FEE = _FEE + "+&nbsp;"; }
_FEE = _FEE + (_f.CTNPRICE2.TrimEnd('0')).TrimEnd('.') + "*" + (Convert.ToInt32(decimal.Parse(head.CTNNUM2))).ToString();
Amount = Amount + decimal.Parse(_f.CTNPRICE2) * decimal.Parse(head.CTNNUM2);
}
}
var BBFH = "¥";
if (_f.CURRENCY == "RMB")
{
AmountRMB = AmountRMB + Amount;
}
else
{
BBFH = "";
AmountUSD = AmountUSD + Amount;
}
FEELIST[_i] = _FEE + "&nbsp;=&nbsp;" + BBFH +""+ (Math.Round(Amount, 2).ToString().TrimEnd('0')).TrimEnd('.');
_i++;
}
}
var CarrierInfo = new StringBuilder();
if (_carrier.FREEDAYS!=""){
CarrierInfo.Append(" 目的港免箱期:" + _carrier.FREEDAYS + "&nbsp;&nbsp;");
}
if (_carrier.VALIDDATE!="" && _carrier.VALIDDATE_END!=""){
CarrierInfo.Append(" 有效期:从" + _carrier.VALIDDATE.Substring(0, 10) + "到" + _carrier.VALIDDATE_END.Substring(0, 10) + "&nbsp;&nbsp;");
}
if (_carrier.REMARK != "")
{
CarrierInfo.Append(" 备注:" + _carrier.REMARK);
}
Body.Append("<br/>");
Body.Append("<br/>");
Body.Append("<table border=\"1\"> ");
Body.Append("<tr>船公司:"+_carrier.CARRIER);
Body.Append("<td align=\"center\" valign=\"middle\" width=\"140\">起止地点</td>");
Body.Append("<td align=\"left\" valign=\"middle\" width=\"500\">" + head.PORTLOAD_REF + "-" + head.PORTDISCHARGE_REF + "/" + head.PORTLOAD + "-" + head.PORTDISCHARGE + "</td>");
Body.Append("</tr>");
Body.Append("<tr>");
Body.Append("<td align=\"center\" valign=\"middle\" width=\"140\">出运货量</td>");
Body.Append("<td align=\"left\" valign=\"middle\" width=\"500\">" + CTN + "</td>");
Body.Append("</tr>");
Body.Append("<tr>");
Body.Append("<td align=\"center\" valign=\"middle\" width=\"140\">其他信息</td>");
Body.Append("<td align=\"left\" valign=\"middle\" width=\"500\">" + CarrierInfo + "</td>");
Body.Append("</tr>");
Body.Append("<tr>");
Body.Append("<td align=\"center\" valign=\"middle\" width=\"140\">订舱说明</td>");
Body.Append("<td align=\"left\" valign=\"middle\" width=\"500\">" + head.REMARK + "</td>");
Body.Append("</tr>");
Body.Append("<tr>");
Body.Append("<td rowspan=\"" + _i + "\" align=\"center\" valign=\"middle\">费用明细</td>");
Body.Append("<td align=\"left\" valign=\"middle\">" + FEELIST[0] + "</td>");
Body.Append("</tr>");
if (_i > 1)
for (var _j = 1; _j <_i; _j++)
{
Body.Append("<tr>");
Body.Append("<td align=\"left\" valign=\"middle\">" + FEELIST[_j] + "</td>");
Body.Append("</tr>");
}
var HJ = "";
HJ = "" + Math.Round(AmountUSD, 2).ToString() + "&nbsp;&nbsp;&nbsp;&nbsp;";
HJ =HJ+ "¥" + Math.Round(AmountRMB, 2).ToString() + "";
Body.Append("<tr>");
Body.Append("<td align=\"center\" valign=\"middle\" width=\"140\">分类合计</td>");
Body.Append("<td align=\"center\" valign=\"middle\" width=\"500\">" + HJ + "</td>");
Body.Append("</tr>");
Body.Append("</table>");
Body.Append("<tr></tr>");
Body.Append("<tr></tr>");
Body.Append("<tr></tr>");
}
Body.Append("<br />联系人:" + SenderName);
Body.Append("<br />邮箱:" + SenderEmail);
msg.Subject = Subject;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = Body.ToString();//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
/* 使
var sfile = getXJ2(head, head2);
msg.Attachments.Add(new Attachment(sfile));
msg.Attachments[0].Name = Session["COMPANYNAME"].ToString() + "_" + Session["SHOWNAME"].ToString() + "_询价.xls";
* */
var content = "";
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(content, null, "text/html");
/*
LinkedResource lrImage = new LinkedResource(@"D:\DSWebservice\a.jpg", "image/gif");
lrImage.ContentId = "Email001";
htmlBody.LinkedResources.Add(lrImage);
msg.AlternateViews.Add(htmlBody);*/
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("admin@dongshengsoft.com", "ds!@#)(*");
//在71info.com注册的邮箱和密码
client.Host = "smtpcom.263xmail.com";
object userState = msg;
var Result = "";
try
{
//client.SendAsync(msg, userState);
//简单一点儿可以
client.Send(msg);
CRM_QUOTATIONDAL.ExecSql("update CRM_QUOTATION set ASKDATE='" + DateTime.Now.ToString() + "' where GID='" + head.GID + "'");
/*
if (System.IO.File.Exists(Path.GetFullPath(sfile)))
{
System.IO.File.Delete(Path.GetFullPath(sfile));
}
*/
var json = JsonConvert.Serialize(new { Success = true, Message = "发送成功" });
return new ContentResult() { Content = json };
}
catch (System.Net.Mail.SmtpException ex)
{
Result = ex.Message;
var json = JsonConvert.Serialize(new { Success = false, Message = "发送失败 " + Result });
return new ContentResult() { Content = json };
}
}
#endregion
#region 保存为excel文件
protected string getXJ2 ( CRM_QUOTATIONmb head, CRM_QUOTATIONmb head2 )
{
/*
T_ALL_DA T_ALL_DA = new T_ALL_DA();*/
//var strDataIndex = "WMSDATE,CUSTOMERNAME,BLNO,STORAGENAME,GOODSNAME,GOODSMODEL,hj_GOODSRKSL,hj_GOODSPFSL_OUT,hj_GOODSPFSL_MONTH,hj_GOODSSTOCK,hj_GOODSPACK,hj_GOODSPACKPFSL,hj_GOODSPACKPFSL_MONTH,hj_GOODSPACKSTOCK,CONTRACTNO,CHARGEUNIT,CUSTOMNO,GOODSGRADE,GOODSSLICE,GOODSSTANDARD,REMARK,hj_GOODSPACKACTUAL,hj_GOODSRKSLACTUAL,AREANAME";//字段名称
var strHeader = "代理\t船东\t船期\t航程\t箱型量\tALLIN海运费\t人民币杂费\t有效期\t目的港免箱使\t备注";//中文名称
/*
String strSql = "select " + strDataIndex
+ " from (";
DataSet DS = T_ALL_DA.GetAllSQL(strSql.Trim());
*/
DataSet DS2 = new DataSet();
System.Data.DataTable _tab = new System.Data.DataTable("TAB_1");
DataColumn dc = null;
/*
dc = _tab.Columns.Add("ID", Type.GetType("System.Int32"));
dc.AutoIncrement = true;//自动增加
dc.AutoIncrementSeed = 1;//起始为1
dc.AutoIncrementStep = 1;//步长为1
dc.AllowDBNull = false;//
*/
dc = _tab.Columns.Add("代理", Type.GetType("System.String"));
dc = _tab.Columns.Add("船东", Type.GetType("System.String"));
dc = _tab.Columns.Add("船期", Type.GetType("System.String"));
dc = _tab.Columns.Add("航程", Type.GetType("System.String"));
dc = _tab.Columns.Add("箱型量", Type.GetType("System.String"));
dc = _tab.Columns.Add("ALLIN海运费", Type.GetType("System.String"));
dc = _tab.Columns.Add("人民币杂费", Type.GetType("System.String"));
dc = _tab.Columns.Add("有效期", Type.GetType("System.String"));
dc = _tab.Columns.Add("目的港免箱使", Type.GetType("System.String"));
dc = _tab.Columns.Add("备注", Type.GetType("System.String"));
DS2.Tables.Add(_tab);
var bodyList = CRM_QUOTATIONDAL.GetDetailList(" LINKGID ='" + head2.GID + "' ");
/*var Row1 = DS2.Tables[0].NewRow();
Row1[0] = "代理";
Row1[1] = "船东";
Row1[2] = "船期";
Row1[3] = "航程";
Row1[4] = "箱型量";
Row1[5] = "ALLIN海运费";
Row1[6] = "人民币杂费";
Row1[7] = "有效期";
Row1[8] = "目的港免箱使";
Row1[9] = "备注";
DS2.Tables[0].Rows.Add(Row1);*/
var _i = 2;
if (bodyList.Count == 0)
{
var Row = DS2.Tables[0].NewRow();
Row[0] = head.SHORTNAME;
Row[1] = head.CARRIER;
Row[2] = head.ETD.Substring(0, 10);
Row[3] = head.TT;
_i++;
DS2.Tables[0].Rows.Add(Row);
}
else
{
foreach (var _c in bodyList)
{
var Row = DS2.Tables[0].NewRow();
/*
for (var _j = 0; _j < 10; _j++) {
System.Data.DataRow _R = new System.Data.DataRow();
Row.ItemArray.
}*/
Row[0] = head.SHORTNAME;
Row[1] = head.CARRIER;
Row[2] = head.ETD.Substring(0, 10);
Row[3] = head.TT;
Row[4] = _c.CTN + "*" + _c.CTNNUM;
_i++;
DS2.Tables[0].Rows.Add(Row);
}
}
if (DS2 != null)
{
ExcelDA ExcelDA = new EntityDA.ExcelDA();
MemoryStream ms = ExcelDA.RenderToExcel(DS2.Tables[0], strHeader.Trim());
//ExcelDA.RenderToBrowser(ms, Context, "report.xls");
var path = Server.MapPath("../../CRM_QUOTATION_EXCEL/output/");
string expfilename = path + "\\" + head.GID +"_"+ DateTime.Now.ToString("HHmmssfff")+ ".xls";
/*
if (System.IO.File.Exists(Path.GetFullPath(expfilename)))
{
System.IO.File.Delete(Path.GetFullPath(expfilename));
}*/
FileStream fs = new FileStream(expfilename, FileMode.OpenOrCreate);
BinaryWriter w = new BinaryWriter(fs);
w.Write(ms.ToArray());
fs.Close();
ms.Close();
return expfilename;
}
else {
return "";
}
}
#endregion
#region 审核 是否允许发出报价
public ContentResult StartAudit(String USERID, String bill)
{
var result = new DBResult();
var WorkFlowName = "CRMInfoFaqInfo";
var billList = bill.Split(',');
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var billno in billList)
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart(WorkFlowName, billno, USERID,billno,billno,"");
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update CRM_QUOTATION set BLSTATUS=2 where GID=@GID ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, billno);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
result.Success = false;
result.Message = "审核错误!";
}
}
result = new DBResult();
result.Success = true;
result.Message = "审核成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "审核错误,请重试或联系系统管理员";
//return result;
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult ResetAudit(String USERID, String bill)
{
var result = new DBResult();
var WorkFlowName = "CRMInfoFaqInfo";
var billList = bill.Split(',');
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var billno in billList)
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowReset(WorkFlowName, billno, USERID);
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update CRM_QUOTATION set BLSTATUS=1 where GID=@GID ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, billno);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
result.Success = false;
result.Message = "审核错误!";
}
}
result = new DBResult();
result.Success = true;
result.Message = "审核成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "审核错误,请重试或联系系统管理员";
//return result;
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Audit(String USERID, String bill)
{
var result = new DBResult();
var WorkFlowName = "CRMInfoFaqInfo";
var billList = bill.Split(',');
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var billno in billList)
{
Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo(WorkFlowName, billno, USERID,"");
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update CRM_QUOTATION set BLSTATUS=3 where GID=@GID ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, billno);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
result.Success = false;
result.Message = "审核错误!";
}
}
result = new DBResult();
result.Success = true;
result.Message = "审核成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "审核错误,请重试或联系系统管理员";
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AuditBack(String USERID, String bill)
{
var result = new DBResult();
var WorkFlowName = "CRMInfoFaqInfo";
var billList = bill.Split(',');
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var billno in billList)
{
Resultmb WorkResult = WorkFlowDAL.DeleteWorkFlowDo(WorkFlowName, billno, USERID,"");
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update CRM_QUOTATION set BLSTATUS=1 where GID=@GID ");
cmdupdate.Parameters.Clear();
//db.AddInParameter(cmdupdate, "@AUDITDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdupdate, "@GID", DbType.String, billno);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
result.Success = false;
result.Message = "审核错误!";
}
}
result = new DBResult();
result.Success = true;
result.Message = "审核成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "审核错误,请重试或联系系统管理员";
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
}
}