using System; using System.Linq; using System.Web.Mvc; using DSWeb.Areas.Account.DAL.Chfee_Invoice; using DSWeb.Areas.Account.DAL.Chfee_Invoiceapplication; using DSWeb.Areas.Account.Models.Chfee_Invoiceapplication; using DSWeb.Areas.Account.Models.Chfee_Invoice; using DSWeb.Areas.Account.Models.Chfee_do_detail; using DSWeb.Areas.Account.Models.BillChfeeDetail; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.Comm.Cookie; using DSWeb.Areas.CommMng.DAL; using System.Collections.Generic; using HcUtility.Comm; using HcUtility.Core; using DSWeb.EntityDA; using DSWeb.Areas.Account.Models.Chfee_Exrate; using System.IO; using Microsoft.Practices.EnterpriseLibrary.Data; using System.Text; using System.Data; namespace DSWeb.Areas.Account.Controllers { [JsonRequestBehavior] public class Chfee_invoiceController : Controller { // // GET: public ActionResult Index() { return View(); } // // GET: / public ActionResult Edit() { return View(); } public ActionResult BLEdit() { return View(); } public ActionResult AppEdit() { return View(); } public ActionResult BookEdit() { return View(); } public ActionResult BookIndex() { return View(); } // // GET: public ContentResult GetDataList(int start, int limit, string sort, string condition) { if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "") { var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; } var dataList = ChinvoiceDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]), sort); 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 GetDataListStr(int start, int limit, string sort, string condition, int billtype) { var dataListStr = ChinvoiceDAL.GetDataListStr(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"]), sort); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr }); return new ContentResult() { Content = json }; } public ContentResult GetData(string handle, string condition,bool isapp) { ChInvoice head = null; if (handle == "edit" || handle == "copyadd") { var list = ChinvoiceDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"])); if (list.Count > 0) head = list[0]; } if (head == null) { head = new ChInvoice(); } if (handle == "add") { head.OPERATOR = Convert.ToString(Session["USERID"]); head.OPERATORNAME = Convert.ToString(Session["SHOWNAME"]); if (isapp) { head.INVOICETYPE = 2; head.INVOICETYPEREF = "申请发票"; } else { head.INVOICETYPE = 1; head.INVOICETYPEREF = "自由发票"; } } var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = head }); return new ContentResult() { Content = json }; } public ContentResult GetDetailList(string condition) { var dataList = ChinvoiceDAL.GetDetailList(condition); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetBillList(string condition, string sort) { var dataList = ChinvoiceDAL.GetBodyList(condition,sort); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetBillSum(string condition) { var dataList = ChinvoiceDAL.GetBodySumList(condition); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetFeeDataList(int start, int limit, string sort, string condition) { var dataList = ChinvoiceDAL.GetFeeDataList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort); 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 GetBillDataList(int start, int limit, string sort, string condition) { var dataList = ChinvoiceDAL.GetAddBillList(start, limit,condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort); int count = ChinvoiceapplicationDAL.getAddBillTotalCount(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", totalCount = count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetFeeDetailList(string sort, string condition) { var dataList = ChinvoiceDAL.GetFeeDetailList(condition,sort); var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetAddSum(string condition) { var dataList = ChinvoiceDAL.GetAddSum(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult Save(string opstatus, string data, string body) { var headData = JsonConvert.Deserialize(data); var bodyList = JsonConvert.Deserialize>(body); if (opstatus == "add") { headData.GID = Guid.NewGuid().ToString(); headData.BILLNO = PubSysDAL.GetBillNo("0308"); headData.COMPANYID = Convert.ToString(Session["COMPANYID"]); headData.OPERATOR = Convert.ToString(Session["USERID"]); headData.OPERATETIME = DateTime.Now; headData.DbOperationType = DbOperationType.DbotIns; } else if (opstatus == "edit") { headData.DbOperationType = DbOperationType.DbotUpd; headData.ModelUIStatus = "E"; } else { headData.DbOperationType = DbOperationType.DbotDel; } if (headData.INVOICECUSTNAME == "") { T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet dsHSCODE = T_ALL_DA.GetAllSQL("SELECT Gid,CODENAME as CustCode,SHORTNAME as CustName,CODENAME+'-'+SHORTNAME as CodeAndName,BillRises1,INVADDRTEL,[DESCRIPTION],RmbBillRises,(select top 1 BANKNAME+' '+ACCOUNT FROM info_client_bank WHERE CURRENCY='RMB' AND LINKID=info_client.GID) Rmbbank,Rmbaccount,usdBillRises,usdbank,usdaccount,TaxNo,Addr,Tel from info_client WHERE SHORTNAME='" + headData.CUSTOMERNAME + "'"); if (dsHSCODE != null) { if (dsHSCODE.Tables[0].Rows.Count > 0) { if (dsHSCODE.Tables[0].Rows[0]["BillRises1"].ToString() != "") headData.INVOICECUSTNAME = dsHSCODE.Tables[0].Rows[0]["BillRises1"].ToString(); else headData.INVOICECUSTNAME = dsHSCODE.Tables[0].Rows[0]["DESCRIPTION"].ToString(); if (headData.CUSTRATENO == "") headData.CUSTRATENO = dsHSCODE.Tables[0].Rows[0]["TaxNo"].ToString(); if (headData.CUSTADDRTEL == "") { if (dsHSCODE.Tables[0].Rows[0]["INVADDRTEL"].ToString() != "") headData.CUSTADDRTEL = dsHSCODE.Tables[0].Rows[0]["INVADDRTEL"].ToString(); else headData.CUSTADDRTEL = dsHSCODE.Tables[0].Rows[0]["Addr"].ToString() + " " + dsHSCODE.Tables[0].Rows[0]["Tel"].ToString(); } if (headData.CUSTBANK == "") { headData.CUSTBANK = dsHSCODE.Tables[0].Rows[0]["Rmbbank"].ToString(); } } } } var isPost = true; var errorstr = ""; if (headData.INVOICENO != "") { var ct = ChinvoiceDAL.GetRdCount("GID<>'" + headData.GID + "' AND INVOICENO='" + headData.INVOICENO + "' and COMPANYID='" + Convert.ToString(Session["COMPANYID"]) + "'"); if (ct != 0) { isPost = false; errorstr = "发票号"; } } if (isPost) { if (headData.INVOICEMAKETIME == "") headData.INVOICEMAKETIME = null; if (headData.ETD == "") headData.ETD = null; var BILLNO = headData.BILLNO; var modb = new ModelObjectDB(); DBResult result = ChinvoiceDAL.SaveInvDetail(headData.GID, bodyList); if (result.Success == true) { result = modb.Save(headData); ChinvoiceDAL.UpdateInvNoUse(headData.INVOICENO, Convert.ToString(Session["USERID"]),headData.BILLNO); if (headData.EXCHANGERATE != 0) { ChinvoiceDAL.updateFeeTax(headData.BILLNO, headData.EXCHANGERATE); } }; var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = ChinvoiceDAL.GetData(" BILLNO='" + BILLNO + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"])) }; 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 AddDetail(string bill, string data, string curr,bool islist,string GID,string invoiceno) { var bodyList = JsonConvert.Deserialize>(data); var headdata = ChinvoiceDAL.GetData(" BILLNO='" + bill + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"])); var modb = new ModelObjectDB(); DBResult result = ChinvoiceDAL.AddDetail(bill, bodyList, curr, Convert.ToString(Session["COMPANYID"]), islist, GID,headdata); if (result.Success) { ChinvoiceDAL.p_update_Amount(bill, GID); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult AddBill(string bill, string feesql, string storeCurrExrate, bool islist, string GID, bool custgroup = false) { var headData = JsonConvert.Deserialize(bill); var exrateList = JsonConvert.Deserialize>(storeCurrExrate); if ((exrateList == null) || (exrateList.Count == 0)) { exrateList = ChinvoiceDAL.GetCurrExrateData(headData.CUSTOMERNAME, headData.CURRENCY, feesql, custgroup); if (exrateList.Count == 0) { var modb = new ModelObjectDB(); DBResult result = ChinvoiceDAL.AddBill(headData, feesql, exrateList, Convert.ToString(Session["COMPANYID"]), islist, GID, custgroup); if (result.Success) { ChinvoiceDAL.p_update_Amount(headData.BILLNO, GID); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var jsonRespose = new JsonResponse { Success = true, Message = "查询成功", Data = exrateList.ToList() }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } else { var modb = new ModelObjectDB(); DBResult result = ChinvoiceDAL.AddBill(headData, feesql, exrateList, Convert.ToString(Session["COMPANYID"]), islist, GID); if (result.Success) { ChinvoiceDAL.p_update_Amount(headData.BILLNO, GID); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } public ContentResult DelBill(string data, string billno,string GID) { var bodyList = JsonConvert.Deserialize>(data); DBResult result = ChinvoiceDAL.DelFeeDo(bodyList,GID); if (result.Success) { ChinvoiceDAL.p_update_Amount(billno, GID); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } // public ContentResult Delete(string data) { var headData = JsonConvert.Deserialize(data); DBResult result; if (headData.INVOICETYPE == 2) { var dataList = ChinvoiceapplicationDAL.GetDataList("INVBILLNO='"+headData.BILLNO+"'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request),Convert.ToString(Session["COMPANYID"])); result = ChinvoiceDAL.DelAppList(dataList,headData.BILLNO); } else { var dataList = ChinvoiceDAL.GetBodyList("BILLNO='" + headData.BILLNO + "'"); result = ChinvoiceDAL.DelFeeDo(dataList, headData.GID); } if (result.Success == true) { var modb = new ModelObjectDB(); modb.Delete(headData); ChinvoiceDAL.UpdateInvNoCancelUse(headData.INVOICENO); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var blUpSQL = " insert into sys_log(GID,NAME,LOGTYPE,LOGTIME,LOGCONTENT,CREATEUSER) values(NEWID(),'" + headData.BILLNO + "','删除发票','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + headData.INVOICENO + '(' + headData.CUSTOMERNAME + ')' + "','" + Convert.ToString(Session["USERID"]) + "')"; bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult DeleteUp(string data) { var headData = JsonConvert.Deserialize(data); DBResult result; if (headData.INVOICETYPE == 2) { var dataList = ChinvoiceapplicationDAL.GetDataList("INVBILLNO='" + headData.BILLNO + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"])); result = ChinvoiceDAL.DelAppList(dataList, headData.BILLNO); } else { var dataList = ChinvoiceDAL.GetBodyList("BILLNO='" + headData.BILLNO + "'"); result = ChinvoiceDAL.DelFeeDo(dataList,headData.GID); } if (result.Success == true) { ChinvoiceDAL.UpdateDelete(headData.BILLNO, Convert.ToString(Session["USERID"])); ChinvoiceDAL.UpdateInvNoDelete(headData.INVOICENO, Convert.ToString(Session["USERID"])); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult CancelDeleteUp(string data) { var headData = JsonConvert.Deserialize(data); DBResult result; result = ChinvoiceDAL.UpdateDelete(headData.BILLNO, Convert.ToString(Session["USERID"]),false); if (result.Success == true) { ChinvoiceDAL.UpdateInvNoDelete(headData.INVOICENO, Convert.ToString(Session["USERID"]),false); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult GetInvoiceNo(string condition) { var dataList = ChinvoiceDAL.GetInvoiceNo(Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"])); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } #region 发票申请添加 public ContentResult AddAppDetail(string bill, string data, string invoiceno, string GID) { var bodyList = JsonConvert.Deserialize>(data); var StrGid=""; if (bodyList != null) { foreach (var enumValue in bodyList) { if (StrGid=="") StrGid="'"+enumValue.GID+"'"; else StrGid=StrGid+",'"+enumValue.GID+"'"; } } if (StrGid != "") { StrGid = "(" + StrGid + ")"; var dataList = ChinvoiceapplicationDAL.GetDataInvList(" BILLSTATUS=0 and GID IN " + StrGid, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"])); if (dataList != null && dataList.Count != 0) { var modb = new ModelObjectDB(); DBResult result = ChinvoiceDAL.AddAppDetail(bill, dataList, invoiceno, Convert.ToString(Session["COMPANYID"]), GID); if (result.Success) { ChinvoiceDAL.p_update_Amount(bill, GID); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var jsonRespose = new JsonResponse { Success = false, Message = "发票申请已生成发票,请刷新!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } else { var jsonRespose = new JsonResponse { Success =false, Message ="无需要添加的发票申请!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } public ContentResult DelAppBill(string data, string billno, string GID) { var bodyList = JsonConvert.Deserialize>(data); DBResult result = ChinvoiceDAL.DelAppList(bodyList,billno); if (result.Success) { ChinvoiceDAL.p_update_Amount(billno, GID); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult DelInvDetail(string billno, string body,string GID) { var bodyList = JsonConvert.Deserialize>(body); DBResult result = ChinvoiceDAL.DelInvDetail(bodyList); if (result.Success) { ChinvoiceDAL.p_update_Amount(billno, GID); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion //public ContentResult UpdateCustInvHead(string data) //{ // var headdata = JsonConvert.Deserialize(data); // var result = new DBResult(); // Database db = DatabaseFactory.CreateDatabase(); // using (var conn = db.CreateConnection()) // { // conn.Open(); // var tran = conn.BeginTransaction(); // try // { // var strSql = new StringBuilder(); // strSql.Append("update info_client set CODENAME=CODENAME "); // if (headdata.INVOICECUSTNAME!="") // strSql.Append(",BillRises1='"+headdata.INVOICECUSTNAME+"'"); // if (headdata.CUSTRATENO != "") // strSql.Append(",TaxNo='" + headdata.CUSTRATENO + "'"); // if (headdata.CUSTADDRTEL != "") // strSql.Append(",BillRises1='" + headdata.CUSTADDRTEL + "'"); // strSql.Append(" where BSNO=@BSNO "); // tran.Commit(); // } // catch (Exception) // { // tran.Rollback(); // result.Success = false; // result.Message = "修改出现错误,请重试或联系系统管理员"; // return result; // } // } // result.Success = true; // result.Message = "修改成功" + result.Message; // var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; //} #region 锁定和撤销锁定 public ContentResult Lock(string bill) { DBResult result = ChinvoiceDAL.Lock(bill); var json = JsonConvert.Serialize(result); return new ContentResult() { Content = json }; } public ContentResult UnLock(string bill) { DBResult result = ChinvoiceDAL.UnLock(bill, Convert.ToString(Session["USERID"])); var json = JsonConvert.Serialize(result); return new ContentResult() { Content = json }; } public ContentResult LockList(string bills) { DBResult result = ChinvoiceDAL.LockList(bills); var json = JsonConvert.Serialize(result); return new ContentResult() { Content = json }; } public ContentResult UnLockList(string bills) { DBResult result = ChinvoiceDAL.UnLockList(bills, Convert.ToString(Session["USERID"])); var json = JsonConvert.Serialize(result); return new ContentResult() { Content = json }; } #endregion public ContentResult ExpInv(string bills) { var bodyList = JsonConvert.Deserialize>(bills); var path = Server.MapPath("../../EDIFiles/ExportInv"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // var result = new DBResult(); var filename = ""; filename = ChinvoiceDAL.CreateInvList(bodyList, path); if (filename != "") { //result.Data = "../../EDIFiles/ExportInv/" + filename; result.Data =filename; filename = Path.GetFileName(filename); result.Success = true; result.Message = filename; } else { result.Success = false; result.Message = "无当前匹配的导出文件!"; } // var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult ExpInvForm(string bill) { var bodyList = ChinvoiceDAL.GetDataList("BILLNO='"+bill+"'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), Convert.ToString(Session["COMPANYID"])); var path = Server.MapPath("../../EDIFiles/ExportInv"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // var result = new DBResult(); var filename = ""; filename = ChinvoiceDAL.CreateInvList(bodyList, path); if (filename != "") { result.Data = filename; filename = Path.GetFileName(filename); result.Success = true; result.Message = filename; } else { result.Success = false; result.Message = "无当前匹配的导出文件!"; } // var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult UpdatePrint(string billno) { DBResult result = ChinvoiceDAL.UpdatePrint(billno); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #region 发票模板 public ContentResult GetRemarksTemplate() { DBResult result = ChinvoiceDAL.GetRemarksTemplate(Convert.ToString(Session["COMPANYID"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message,Data=result.Data }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult SaveRemarksTemplate(string Template) { DBResult result = ChinvoiceDAL.SaveRemarksTemplate(Template, Convert.ToString(Session["COMPANYID"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult GetRemarksData(string billno) { var dataList = ChinvoiceDAL.GetBsList("c.BILLNO='" + billno + "'"); DBResult result = ChinvoiceDAL.GetRemarksData(dataList,Convert.ToString(Session["COMPANYID"]),billno); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = result.Data }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion #region 发票票册 public ContentResult GetBookDataList(int start, int limit, string sort, string condition) { var dataList = ChinvoiceDAL.GetBookDataList(condition, Convert.ToString(Session["COMPANYID"]), sort); 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 GetBookData(string handle, string condition) { ChInvoiceBook head = null; if (handle == "edit") { var list = ChinvoiceDAL.GetBookDataList(condition, Convert.ToString(Session["COMPANYID"])); if (list.Count > 0) head = list[0]; } if (head == null) { head = new ChInvoiceBook(); } if (handle == "add") { head.CREATEUSER = Convert.ToString(Session["USERID"]); head.CREATEUSERREF = Convert.ToString(Session["SHOWNAME"]); head.COMPANYID = Convert.ToString(Session["COMPANYID"]); } var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = head }); return new ContentResult() { Content = json }; } public ContentResult SaveBook(string opstatus, string data) { var headData = JsonConvert.Deserialize(data); if (opstatus == "add") { headData.GID = Guid.NewGuid().ToString(); headData.COMPANYID = Convert.ToString(Session["COMPANYID"]); headData.CREATEUSER = Convert.ToString(Session["USERID"]); headData.CREATETIME = DateTime.Now.ToString(); headData.DbOperationType = DbOperationType.DbotIns; } else if (opstatus == "edit") { headData.DbOperationType = DbOperationType.DbotUpd; headData.ModelUIStatus = "E"; } else { headData.DbOperationType = DbOperationType.DbotDel; } if (headData.TYPE == "") headData.TYPE ="0"; var BILLNO = headData.GID; var modb = new ModelObjectDB(); DBResult result = modb.Save(headData); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = ChinvoiceDAL.GetBookData(" GID='" + BILLNO + "'", Convert.ToString(Session["COMPANYID"])) }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult DeleteBook(string data) { var headData = JsonConvert.Deserialize(data); var isfee = ChinvoiceDAL.GetMakeOutCount(headData.GID); if (isfee) { var jsonRespose = new JsonResponse { Success = false, Message = "此票册已有开出发票,不允许删除!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { DBResult result; var modb = new ModelObjectDB(); result = modb.Delete(headData); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } public ContentResult CreateBookitems(string data) { var headData = JsonConvert.Deserialize(data); DBResult result = ChinvoiceDAL.CreateBookitems(headData, Convert.ToString(Session["USERID"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult LockBookitems(string data) { var headData = JsonConvert.Deserialize>(data); DBResult result = ChinvoiceDAL.LockBookitems(headData); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult CancelLockBookitems(string data) { var headData = JsonConvert.Deserialize>(data); DBResult result = ChinvoiceDAL.CancelLockBookitems(headData); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult GetBookitemsDataList(string condition, string sort) { var dataList = ChinvoiceDAL.GetBookitemsDataList(condition, sort); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult DeleteUpBook(string data) { var headData = JsonConvert.Deserialize(data); DBResult result; result = ChinvoiceDAL.DeleteUpBook(headData.GID, Convert.ToString(Session["USERID"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion #region 参照部分 #endregion } }