/// <summary> /// 해당 사업자의 미서명된 세금계산서를 정의된 갯수 만큼 서명 합니다. /// 100건 이상인 경우에는 100건에 한번씩 데이터베이스에 저장 합니다. /// </summary> /// <param name="p_invoicerCert"></param> /// <param name="p_invoicerId"></param> /// <param name="p_noInvoicee"></param> //public int DoSignInvoice(X509CertMgr p_invoicerCert, string p_invoicerId, int p_noInvoicee) //{ // string _where = ""; // var _dbps = new PgDatParameters(); // return CheckSignature(p_invoicerCert, p_invoicerId, p_noInvoicee, _where, _dbps); //} /// <summary> /// /// </summary> /// <param name="p_invoicerCert"></param> /// <param name="p_invoicerId"></param> /// <param name="p_issueIds">comma delimeter</param> public int DoSignInvoice(X509CertMgr p_invoicerCert, string p_invoicerId, string[] p_issueIds) { ISigner.WriteDebug(p_invoicerId); int _result = 0; string _issueCols = ""; foreach (string _issueId in p_issueIds) { if (String.IsNullOrEmpty(_issueCols) == false) { _issueCols += ", "; } _issueCols += String.Format("'{0}'", _issueId); } if (String.IsNullOrEmpty(_issueCols) == false) { string _where = String.Format(" AND a.issueId IN ({0})", _issueCols); var _dbps = new PgDatParameters(); _result = CheckSignature(p_invoicerCert, p_invoicerId, p_issueIds.Length, _where, _dbps); } return(_result); }
private int CheckSignature(X509CertMgr p_invoicerCert, string p_invoicerId, int p_noInvoicee, string p_where, PgDatParameters p_dbps) { int _noIssuing = 0; lock (SyncEngine) _noIssuing = CheckReEnter(p_invoicerId, p_where, p_dbps); if (_noIssuing > 0) { SignatureArgs _args = new SignatureArgs() { invoicerCert = p_invoicerCert, invoicerId = p_invoicerId, noInvoicee = p_noInvoicee, noIssuing = _noIssuing, where = p_where, dbps = p_dbps }; // Do not use using statement ThreadPoolWait _doneEvent = new ThreadPoolWait(); _doneEvent.QueueUserWorkItem(DoSignature, _args); if (Environment.UserInteractive == true) { _doneEvent.WaitOne(); } } return(_noIssuing); }
/// <summary> /// /// </summary> /// <param name="p_certapp"></param> /// <param name="p_certifier"></param> /// <param name="p_invoicerId"></param> /// <param name="p_issueIds"></param> /// <returns></returns> public int SignatureWithIDs(Guid p_certapp, string[] p_certifier, string p_invoicerId, string[] p_issueIds) { int _result = 0; try { if (ISigner.CheckValidApplication(p_certapp) == true) { if (p_issueIds.Length > 100) { throw new SignerException(String.Format("Issue-ids can not exceed 100-records. invoiceId->'{0}', length->{1})", p_invoicerId, p_issueIds.Length)); } X509CertMgr _invoicerCert = UCertHelper.GetCustomerCertMgr(p_invoicerId, p_certifier[0], p_certifier[1], p_certifier[2]); _result = ESigner.DoSignInvoice(_invoicerCert, p_invoicerId, p_issueIds); } } catch (SignerException ex) { ELogger.SNG.WriteLog(ex); } catch (Exception ex) { ELogger.SNG.WriteLog(ex); } return(_result); }
//------------------------------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------------------------------- /// <summary> /// /// </summary> /// <param name="p_certapp"></param> /// <param name="p_certifier"></param> /// <param name="p_invoicerId"></param> /// <param name="p_fromDay"></param> /// <param name="p_tillDay"></param> /// <returns></returns> public int SignatureWithDateRange(Guid p_certapp, string[] p_certifier, string p_invoicerId, DateTime p_fromDay, DateTime p_tillDay) { int _result = 0; try { if (ISigner.CheckValidApplication(p_certapp) == true) { UTextHelper.SNG.GetSigningRange(ref p_fromDay, ref p_tillDay); var _sqlstr = "SELECT invoicerId, COUNT(invoicerId) as norec " + " FROM TB_eTAX_INVOICE " + " WHERE isSuccess != @isSuccess " // for resignning, do check 'isSuccess' here + " AND ( " + " (RIGHT(typeCode, 2) IN ('01', '02', '04') AND invoicerId=@invoicerId) " + " OR " + " (RIGHT(typeCode, 2) IN ('03', '05') AND brokerId=@invoicerId) " + " ) " + " AND issueDate>=@fromDate AND issueDate<=@tillDate " + " GROUP BY invoicerId"; var _dbps = new PgDatParameters(); { _dbps.Add("@isSuccess", NpgsqlDbType.Varchar, "T"); _dbps.Add("@invoicerId", NpgsqlDbType.Varchar, p_invoicerId); _dbps.Add("@fromDate", NpgsqlDbType.TimestampTz, p_fromDay); _dbps.Add("@tillDate", NpgsqlDbType.TimestampTz, p_tillDay); } var _ds = LSQLHelper.SelectDataSet(UAppHelper.ConnectionString, _sqlstr, _dbps); if (LSQLHelper.IsNullOrEmpty(_ds) == false) { X509CertMgr _invoicerCert = UCertHelper.GetCustomerCertMgr(p_invoicerId, p_certifier[0], p_certifier[1], p_certifier[2]); var _rows = _ds.Tables[0].Rows; for (int i = 0; i < _rows.Count; i++) { string _invoicerId = Convert.ToString(_rows[i]["invoicerId"]); int _noInvoice = Convert.ToInt32(_rows[i]["norec"]); _result += ESigner.DoSignInvoice(_invoicerCert, _invoicerId, _noInvoice, p_fromDay, p_tillDay); } } } } catch (SignerException ex) { ELogger.SNG.WriteLog(ex); } catch (Exception ex) { ELogger.SNG.WriteLog(ex); } return(_result); }
private void SignerCallback(Object p_invoicer) { var _signingDay = DateTime.Now; try { DataRow _invoicerRow = (DataRow)p_invoicer; string _invoicerId = Convert.ToString(_invoicerRow["invoicerId"]); int _noInvoicee = Convert.ToInt32(_invoicerRow["norec"]); DateTime _fromDay = Convert.ToDateTime(_invoicerRow["fromDay"]); DateTime _tillDay = Convert.ToDateTime(_invoicerRow["tillDay"]); DataSet _customer_set = ESigner.GetCustomerSet(_invoicerId); DataRow _customerRow = _customer_set.Tables[0].Rows[0]; decimal _fromSigningDay = Convert.ToDecimal(_customerRow["signFromDay"]); decimal _tillSigningDay = Convert.ToDecimal(_customerRow["signTillDay"]); string _signingType = Convert.ToString(_customerRow["signingType"]); if (_signingType == "01" || _signingType == "03") { if (_signingType == "01") { decimal _today = _signingDay.Day; if (_today < _fromSigningDay || _today > _tillSigningDay) { throw new SignerException( String.Format( "out of range sign-period: invoicerId->'{0}', fromDay->{1}, tillDay->{2}, toDay->{3}", _invoicerId, _fromSigningDay, _tillSigningDay, _today ) ); } } X509CertMgr _invoicerCert = UCertHelper.GetCustomerCertMgr(_invoicerId); ESigner.DoSignInvoice(_invoicerCert, _invoicerId, _noInvoicee, _fromDay, _tillDay); } else { ISigner.WriteDebug(String.Format("invoicer '{0}' is skipped {1} record(s) because sign-type is {2}.", _invoicerId, _noInvoicee, _signingType)); } } catch (SignerException ex) { ELogger.SNG.WriteLog(ex); } catch (Exception ex) { ELogger.SNG.WriteLog(ex); } }
/// <summary> /// /// </summary> /// <param name="p_invoicerCert"></param> /// <param name="p_invoicerId"></param> /// <param name="p_noInvoicee"></param> /// <param name="p_fromDay"></param> /// <param name="p_tillDay"></param> /// <returns></returns> public int DoSignInvoice(X509CertMgr p_invoicerCert, string p_invoicerId, int p_noInvoicee, DateTime p_fromDay, DateTime p_tillDay) { ISigner.WriteDebug(p_invoicerId); var _where = " AND a.issueDate>=@fromDate AND a.issueDate<=@tillDate "; var _dbps = new PgDatParameters(); { _dbps.Add("@fromDate", NpgsqlDbType.TimestampTZ, p_fromDay); _dbps.Add("@tillDate", NpgsqlDbType.TimestampTZ, p_tillDay); } return(CheckSignature(p_invoicerCert, p_invoicerId, p_noInvoicee, _where, _dbps)); }
private X509CertMgr GetCertManager(string p_condition, string p_publicStr, string p_privateStr, string p_passwordStr) { byte[] _privateKey = Encryptor.SNG.ChiperBase64ToPlainBytes(p_privateStr); byte[] _publicKey = Encryptor.SNG.ChiperBase64ToPlainBytes(p_publicStr); string _passwordTxt = Encoding.UTF8.GetString(Encryptor.SNG.ChiperBase64ToPlainBytes(p_passwordStr)); X509CertMgr _result = new X509CertMgr(_publicKey, _privateKey, _passwordTxt); { DateTime _expiration = Convert.ToDateTime(_result.X509Cert2.GetExpirationDateString()); if (_expiration.Subtract(DateTime.Now).Days < USvcHelper.AvailablePeriod) { throw new ProxyException(String.Format("certifier expired: '{0}', '{1}'", _expiration, p_condition)); } } return(_result); }
//------------------------------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------------------------------- /// <summary> /// /// </summary> /// <param name="p_doneEvent"></param> /// <param name="p_invoicerCert">매출자의 공인인증서</param> /// <param name="p_issuingTbl"></param> /// <param name="p_invoiceTbl"></param> public Updater(X509CertMgr p_invoicerCert, DataTable p_issuingTbl, DataTable p_invoiceTbl) { m_invoicerCert = p_invoicerCert; m_issuingTbl = p_issuingTbl; m_invoiceTbl = p_invoiceTbl; }