/// <summary> /// 取得電子發票原始檔明細 /// </summary> /// <param name="invNo"></param> /// <returns></returns> private EinvoiceDetalisSendModel GetEinvoiceProtoDetalisByNo(string invNo) { invNo = string.Concat(invNo[0], invNo[1]).ToUpper() + invNo.Substring(2, invNo.Length - 2); EinvoiceDetalisSendModel send = new EinvoiceDetalisSendModel(); try { C0401H einvoice = this.module.GetEinvoiceDetalisByNo(invNo); if (einvoice == null) { throw new Exception("[系統]查無相關電子發票原始檔明細明細"); } int getMonth = Convert.ToInt16(einvoice.MInvoiceDate.Substring(4, 2)); var chkMonth = (getMonth % 2) == 1; string invTerm = string.Format("{0}{1}", einvoice.MInvoiceDate.Substring(0, 4), chkMonth ? (getMonth + 1).ToString().PadLeft(2, '0') : (getMonth).ToString().PadLeft(2, '0')); string y = einvoice.MInvoiceDate.Substring(0, 4); string m = einvoice.MInvoiceDate.Substring(4, 2); string d = einvoice.MInvoiceDate.Substring(6, 2); string date = string.Format("{0}/{1}/{2}", y, m, d); send.invTerm = invTerm; send.invDate = date; send.randomNumber = einvoice.MRandomNumber; } catch (Exception ex) { throw ex; } return(send); }
public EinvoiceDetalisResultModel GetEinvoiceDetalisByNo(string invNo) { invNo = string.Concat(invNo[0], invNo[1]).ToUpper() + invNo.Substring(2, invNo.Length - 2); EinvoiceDetalisSendModel send = new EinvoiceDetalisSendModel(); #region 取發票原始檔明細 測試時請註解 正式請取消註解 send = GetEinvoiceProtoDetalisByNo(invNo); #endregion 取發票原始檔明細 測試時請註解 正式請取消註解 send.version = 0.3; send.type = "Barcode"; send.invNum = invNo; send.action = "qryInvDetail"; send.generation = "V2"; #region 測試時請取消註解並給時寄發票的資訊 正式請註解 //send.invTerm = "10610"; //send.invDate = "2017/09/26"; //send.randomNumber = "6157"; #endregion 測試時請取消註解並給時寄發票的資訊 正式請註解 string resultStr = string.Empty; WebRequest webRequest = null; string sendData = this.Repository.ConvertObjectToQueryString(send); byte[] bytes = Encoding.UTF8.GetBytes(sendData); //Request try { webRequest = this.Repository.CreateWebRequest(ConnectionStringModel.EinvoiceSearchApiConnectionStr); webRequest.ContentLength = bytes.Length; this.Repository.SendWebRequest(webRequest, bytes); } catch (Exception ex) { throw ex; } //Get Response try { resultStr = this.Repository.GetResponse(webRequest); } catch (Exception ex) { throw ex; } EinvoiceDetalisResultModel result = JsonConvert.DeserializeObject <EinvoiceDetalisResultModel>(resultStr); return(result); }