public override void Parsing() { JObject root = (JObject)T.SelectToken("export"); JProperty firstOrDefault = root.Properties().FirstOrDefault(p => p.Name.Contains("tenderSuspension")); if (firstOrDefault != null) { JToken c = firstOrDefault.Value; if (c.Type == JTokenType.Array) { List <JToken> comp = GetElements(root, "tenderSuspension"); if (comp.Count > 0) { c = comp[0]; } } string complaintNumber = ((string)c.SelectToken("complaintNumber") ?? "").Trim(); string purchaseNumber = ((string)c.SelectToken("tendersInfo.purchase.purchaseNumber") ?? "").Trim(); if (String.IsNullOrEmpty(purchaseNumber)) { purchaseNumber = ((string)c.SelectToken("tendersInfo.order.notificationNumber") ?? "").Trim(); } if (String.IsNullOrEmpty(purchaseNumber)) { Log.Logger("Нет purchaseNumber у Suspend", FilePath); return; } string action = ((string)c.SelectToken("action") ?? "").Trim(); using (MySqlConnection connect = ConnectToDb.GetDbConnection()) { connect.Open(); string updateComp = $"UPDATE {Program.Prefix}complaint SET tender_suspend = @tender_suspend WHERE purchaseNumber = @purchaseNumber"; MySqlCommand cmd = new MySqlCommand(updateComp, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd.Parameters.AddWithValue("@tender_suspend", action); int status = cmd.ExecuteNonQuery(); if (status > 0) { AddComplaintSuspend?.Invoke(status); } } } else { Log.Logger("Не могу найти тег suspend", FilePath); } }
public DataTable GetRegions() { string reg = "SELECT * FROM region"; DataTable dt; using (MySqlConnection connect = ConnectToDb.GetDbConnection()) { connect.Open(); MySqlDataAdapter adapter = new MySqlDataAdapter(reg, connect); DataSet ds = new DataSet(); adapter.Fill(ds); dt = ds.Tables[0]; } return(dt); }
public override void Parsing() { JObject root = (JObject)T.SelectToken("export"); List <JToken> cancel = GetElements(root, "complaintCancel"); if (cancel.Count > 0) { string complaintNumber = ((string)cancel[0].SelectToken("complaintNumber") ?? "").Trim(); string regNumber = ((string)cancel[0].SelectToken("regNumber") ?? "").Trim(); if ((String.IsNullOrEmpty(complaintNumber) || complaintNumber.Length < 3) && String.IsNullOrEmpty(regNumber)) { Log.Logger("Нет complaintNumber and regNumber у Cancel", FilePath, complaintNumber); return; } using (MySqlConnection connect = ConnectToDb.GetDbConnection()) { connect.Open(); if (!String.IsNullOrEmpty(complaintNumber) && complaintNumber.Length >= 3) { string updateComp = $"UPDATE {Program.Prefix}complaint SET cancel = 1 WHERE complaintNumber = @complaintNumber"; MySqlCommand cmd = new MySqlCommand(updateComp, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@complaintNumber", complaintNumber); int status = cmd.ExecuteNonQuery(); if (status > 0) { AddComplaintCancel?.Invoke(status); } } else if (!String.IsNullOrEmpty(regNumber)) { string updateComp = $"UPDATE {Program.Prefix}complaint SET cancel = 1 WHERE regNumber = @regNumber"; MySqlCommand cmd = new MySqlCommand(updateComp, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@regNumber", regNumber); int status = cmd.ExecuteNonQuery(); if (status > 0) { AddComplaintCancel?.Invoke(status); } } } } else { Log.Logger("Не могу найти тег cancel", FilePath); } }
public override List <String> GetListArchPrev(string pathParse) { List <String> arch = new List <string>(); List <string> archtemp = new List <string>(); /*FtpClient ftp = ClientFtp44();*/ archtemp = GetListFtp44(pathParse); string serachd = $"{Program.LocalDate:yyyyMMdd}"; foreach (var a in archtemp.Where(a => a.ToLower().IndexOf(serachd, StringComparison.Ordinal) != -1)) { string prevA = $"prev_{a}"; using (MySqlConnection connect = ConnectToDb.GetDbConnection()) { connect.Open(); string selectArch = $"SELECT id FROM {Program.Prefix}arhiv_complaint WHERE arhiv = @archive"; MySqlCommand cmd = new MySqlCommand(selectArch, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@archive", prevA); MySqlDataReader reader = cmd.ExecuteReader(); bool resRead = reader.HasRows; reader.Close(); if (!resRead) { string addArch = $"INSERT INTO {Program.Prefix}arhiv_complaint SET arhiv = @archive"; MySqlCommand cmd1 = new MySqlCommand(addArch, connect); cmd1.Prepare(); cmd1.Parameters.AddWithValue("@archive", prevA); cmd1.ExecuteNonQuery(); arch.Add(a); } } } return(arch); }
public override void Parsing() { string xml = GetXml(File.ToString()); JObject root = (JObject)T.SelectToken("export"); JProperty firstOrDefault = root.Properties().FirstOrDefault(p => p.Name.Contains("checkResultCancel")); if (firstOrDefault != null) { JToken c = firstOrDefault.Value; //Console.WriteLine(c.Type); if (c.Type == JTokenType.Array) { List <JToken> comp = GetElements(root, "checkResultCancel"); if (comp.Count > 0) { c = comp[0]; } } string checkResultNumber = ((string)c.SelectToken("commonInfo.checkResultNumber") ?? "").Trim(); //Console.WriteLine(checkResultNumber); string complaintNumber = ((string)c.SelectToken("complaint.complaintNumber") ?? "").Trim(); //Console.WriteLine(complaintNumber); string regNumber = ((string)c.SelectToken("commonInfo.regNumber") ?? "").Trim(); string purchaseNumber = ((string)c.SelectToken("complaint.checkedObject.purchase.purchaseNumber") ?? "").Trim(); string createDate = (JsonConvert.SerializeObject(c.SelectToken("commonInfo.createDate") ?? "") ?? "").Trim('"'); if (String.IsNullOrEmpty(purchaseNumber) && String.IsNullOrEmpty(complaintNumber)) { //Log.Logger("Нет purchaseNumber and complaintNumber", FilePath); return; } using (MySqlConnection connect = ConnectToDb.GetDbConnection()) { connect.Open(); int upd = 0; int idCompRes = 0; if (!String.IsNullOrEmpty(createDate)) { createDate = createDate.Substring(0, 19); string selectComp44 = $"SELECT id FROM {Program.Prefix}res_complaint WHERE purchaseNumber = @purchaseNumber AND createDate = @createDate AND complaintNumber = @complaintNumber"; MySqlCommand cmd = new MySqlCommand(selectComp44, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd.Parameters.AddWithValue("@createDate", createDate); cmd.Parameters.AddWithValue("@complaintNumber", complaintNumber); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); idCompRes = reader.GetInt32("id"); reader.Close(); upd = 1; } reader.Close(); } string decisionText = ((string)c.SelectToken("complaint.decision.decisionText") ?? "").Trim(); string complaintResult = ((string)c.SelectToken("complaint.complaintResult") ?? "").Trim(); string complaintResultInfo = ((string)c.SelectToken("complaint.complaintResultInfo") ?? "").Trim(); string printForm = ((string)c.SelectToken("printForm.url") ?? "").Trim(); if (upd == 1) { string deleteAtt = $"DELETE FROM {Program.Prefix}attach_complaint_res WHERE id_complaint_res = @id_complaint_res"; MySqlCommand cmd0 = new MySqlCommand(deleteAtt, connect); cmd0.Prepare(); cmd0.Parameters.AddWithValue("@id_complaint_res", idCompRes); cmd0.ExecuteNonQuery(); string updateC = $"UPDATE {Program.Prefix}res_complaint SET checkResultNumber = @checkResultNumber, complaintNumber = @complaintNumber, purchaseNumber = @purchaseNumber, regNumber = @regNumber, createDate = @createDate, xml = @xml, printForm = @printForm, decisionText = @decisionText, complaintResult = @complaintResult, complaintResultInfo = @complaintResultInfo, cancel = 1 WHERE id = @id"; MySqlCommand cmd1 = new MySqlCommand(updateC, connect); cmd1.Prepare(); cmd1.Parameters.AddWithValue("@checkResultNumber", checkResultNumber); cmd1.Parameters.AddWithValue("@complaintNumber", complaintNumber); cmd1.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd1.Parameters.AddWithValue("@regNumber", regNumber); cmd1.Parameters.AddWithValue("@createDate", createDate); cmd1.Parameters.AddWithValue("@printForm", printForm); cmd1.Parameters.AddWithValue("@xml", xml); cmd1.Parameters.AddWithValue("@decisionText", decisionText); cmd1.Parameters.AddWithValue("@complaintResult", complaintResult); cmd1.Parameters.AddWithValue("@complaintResultInfo", complaintResultInfo); cmd1.Parameters.AddWithValue("@id", idCompRes); int resUpdComp = cmd1.ExecuteNonQuery(); UpdateComplaintCancelRes?.Invoke(resUpdComp); } else { string InsertC = $"INSERT INTO {Program.Prefix}res_complaint SET checkResultNumber = @checkResultNumber, complaintNumber = @complaintNumber, purchaseNumber = @purchaseNumber, regNumber = @regNumber, createDate = @createDate, xml = @xml, printForm = @printForm, decisionText = @decisionText, complaintResult = @complaintResult, complaintResultInfo = @complaintResultInfo, cancel = 1"; MySqlCommand cmd1 = new MySqlCommand(InsertC, connect); cmd1.Prepare(); cmd1.Parameters.AddWithValue("@checkResultNumber", checkResultNumber); cmd1.Parameters.AddWithValue("@complaintNumber", complaintNumber); cmd1.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd1.Parameters.AddWithValue("@regNumber", regNumber); cmd1.Parameters.AddWithValue("@createDate", createDate); cmd1.Parameters.AddWithValue("@printForm", printForm); cmd1.Parameters.AddWithValue("@xml", xml); cmd1.Parameters.AddWithValue("@decisionText", decisionText); cmd1.Parameters.AddWithValue("@complaintResult", complaintResult); cmd1.Parameters.AddWithValue("@complaintResultInfo", complaintResultInfo); int resInsComp = cmd1.ExecuteNonQuery(); idCompRes = (int)cmd1.LastInsertedId; AddComplaintCancelRes?.Invoke(resInsComp); } List <JToken> attach = GetElements(c, "complaint.decision.attachments.attachment"); foreach (var att in attach) { string fileName = ((string)att.SelectToken("fileName") ?? "").Trim(); string docDescription = ((string)att.SelectToken("docDescription") ?? "").Trim(); string url = ((string)att.SelectToken("url") ?? "").Trim(); string insertAtt = $"INSERT INTO {Program.Prefix}attach_complaint_res SET id_complaint_res = @id_complaint_res, fileName = @fileName, docDescription = @docDescription, url = @url"; MySqlCommand cmd1 = new MySqlCommand(insertAtt, connect); cmd1.Prepare(); cmd1.Parameters.AddWithValue("@id_complaint_res", idCompRes); cmd1.Parameters.AddWithValue("@fileName", fileName); cmd1.Parameters.AddWithValue("@docDescription", docDescription); cmd1.Parameters.AddWithValue("@url", url); cmd1.ExecuteNonQuery(); } } } else { Log.Logger("Не могу найти тег checkResultCancel", FilePath); } }
public override void Parsing() { string xml = GetXml(File.ToString()); string idComplaint = ""; string[] fN = File.Name.Split('_'); if (fN.Length > 1) { idComplaint = fN[1]; } else { Log.Logger("Not id_complaint", FilePath); } //Console.WriteLine(id_complaint); JObject root = (JObject)T.SelectToken("export"); JProperty firstOrDefault = root.Properties().FirstOrDefault(p => p.Name.Contains("complaint")); if (firstOrDefault != null) { JToken c = firstOrDefault.Value; //Console.WriteLine(c.Type); if (c.Type == JTokenType.Array) { List <JToken> comp = GetElements(root, "complaint"); if (comp.Count > 0) { c = comp[0]; } } string complaintNumber = ((string)c.SelectToken("commonInfo.complaintNumber") ?? "").Trim(); //Console.WriteLine(complaintNumber); string regNumber = ((string)c.SelectToken("commonInfo.regNumber") ?? "").Trim(); string versionNumber = ((string)c.SelectToken("commonInfo.versionNumber") ?? "").Trim(); string purchaseNumber = ((string)c.SelectToken("object.purchase.purchaseNumber") ?? "").Trim(); string planDecisionDate = (JsonConvert.SerializeObject(c.SelectToken("commonInfo.planDecisionDate") ?? "") ?? "").Trim('"'); if (String.IsNullOrEmpty(purchaseNumber) && String.IsNullOrEmpty(complaintNumber)) { Log.Logger("Нет purchaseNumber and complaintNumber", FilePath); return; } using (MySqlConnection connect = ConnectToDb.GetDbConnection()) { connect.Open(); int GetIdOrg(string regNum, string fullName, string inn, string kpp, string table = "org_complaint") { int idO = 0; string selectOrg = $"SELECT id FROM {Program.Prefix}{table} WHERE regNum = @regNum"; MySqlCommand cmd = new MySqlCommand(selectOrg, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@regNum", regNum); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); idO = reader.GetInt32("id"); reader.Close(); } else { reader.Close(); string insertOrg = $"INSERT INTO {Program.Prefix}{table} SET regNum = @regNum, fullName = @fullName, INN = @INN, KPP = @KPP"; MySqlCommand cmd2 = new MySqlCommand(insertOrg, connect); cmd2.Prepare(); cmd2.Parameters.AddWithValue("@regNum", regNum); cmd2.Parameters.AddWithValue("@fullName", fullName); cmd2.Parameters.AddWithValue("@INN", inn); cmd2.Parameters.AddWithValue("@KPP", kpp); cmd2.ExecuteNonQuery(); idO = (int)cmd2.LastInsertedId; } return(idO); } int upd = 0; int idComp = 0; if (!String.IsNullOrEmpty(planDecisionDate) && !String.IsNullOrEmpty(versionNumber)) { planDecisionDate = planDecisionDate.Substring(0, 19); string selectComp44 = $"SELECT id FROM {Program.Prefix}complaint WHERE purchaseNumber = @purchaseNumber AND versionNumber = @versionNumber AND planDecisionDate = @planDecisionDate AND complaintNumber = @complaintNumber"; MySqlCommand cmd = new MySqlCommand(selectComp44, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd.Parameters.AddWithValue("@versionNumber", versionNumber); cmd.Parameters.AddWithValue("@planDecisionDate", planDecisionDate); cmd.Parameters.AddWithValue("@complaintNumber", complaintNumber); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); idComp = reader.GetInt32("id"); reader.Close(); upd = 1; } reader.Close(); } string decisionPlace = ((string)c.SelectToken("commonInfo.decisionPlace") ?? "").Trim(); int idRegistrationKo = 0; string regNumRegistrationKo = ((string)c.SelectToken("commonInfo.registrationKO.regNum") ?? "").Trim(); string fullNameRegistrationKo = ((string)c.SelectToken("commonInfo.registrationKO.fullName") ?? "").Trim(); string innRegistrationKo = ((string)c.SelectToken("commonInfo.registrationKO.INN") ?? "").Trim(); string kppRegistrationKo = ((string)c.SelectToken("commonInfo.registrationKO.KPP") ?? "").Trim(); if (!String.IsNullOrEmpty(regNumRegistrationKo)) { idRegistrationKo = GetIdOrg(regNumRegistrationKo, fullNameRegistrationKo, innRegistrationKo, kppRegistrationKo); } int idConsiderationKo = 0; string regNumConsiderationKo = ((string)c.SelectToken("commonInfo.considerationKO.regNum") ?? "").Trim(); string fullNameConsiderationKo = ((string)c.SelectToken("commonInfo.considerationKO.fullName") ?? "").Trim(); string innConsiderationKo = ((string)c.SelectToken("commonInfo.considerationKO.INN") ?? "").Trim(); string kppConsiderationKo = ((string)c.SelectToken("commonInfo.considerationKO.KPP") ?? "").Trim(); if (!String.IsNullOrEmpty(regNumConsiderationKo)) { idConsiderationKo = GetIdOrg(regNumConsiderationKo, fullNameConsiderationKo, innConsiderationKo, kppConsiderationKo); } string regDate = (JsonConvert.SerializeObject(c.SelectToken("commonInfo.regDate") ?? "") ?? "").Trim('"'); string noticeNumber = ((string)c.SelectToken("commonInfo.notice.number") ?? "").Trim(); string noticeAcceptDate = (JsonConvert.SerializeObject(c.SelectToken("commonInfo.notice.acceptDate") ?? "") ?? "").Trim('"'); int idCreateOrganization = 0; string regNumCreateOrganization = ((string)c.SelectToken("commonInfo.printFormInfo.createOrganization.regNum") ?? "").Trim(); string fullNameCreateOrganization = ((string)c.SelectToken("commonInfo.printFormInfo.createOrganization.fullName") ?? "") .Trim(); string innCreateOrganization = ((string)c.SelectToken("commonInfo.printFormInfo.createOrganization.INN") ?? "").Trim(); string kppCreateOrganization = ((string)c.SelectToken("commonInfo.printFormInfo.createOrganization.KPP") ?? "").Trim(); if (!String.IsNullOrEmpty(regNumCreateOrganization)) { idCreateOrganization = GetIdOrg(regNumCreateOrganization, fullNameCreateOrganization, innCreateOrganization, kppCreateOrganization); } string createDate = (JsonConvert.SerializeObject(c.SelectToken("commonInfo.printFormInfo.createDate") ?? "") ?? "").Trim('"'); int idPublishOrganization = 0; string regNumPublishOrganization = ((string)c.SelectToken("commonInfo.printFormInfo.publishOrganization.regNum") ?? "") .Trim(); string fullNamePublishOrganization = ((string)c.SelectToken("commonInfo.printFormInfo.publishOrganization.fullName") ?? "") .Trim(); string innPublishOrganization = ((string)c.SelectToken("commonInfo.printFormInfo.publishOrganization.INN") ?? "").Trim(); string kppPublishOrganization = ((string)c.SelectToken("commonInfo.printFormInfo.publishOrganization.KPP") ?? "").Trim(); if (!String.IsNullOrEmpty(regNumCreateOrganization)) { idPublishOrganization = GetIdOrg(regNumPublishOrganization, fullNamePublishOrganization, innPublishOrganization, kppPublishOrganization); } int idCustomer = 0; string regNumCustomer = ((string)c.SelectToken("indicted.customer.regNum") ?? "") .Trim(); if (String.IsNullOrEmpty(regNumCustomer)) { regNumCustomer = ((string)c.SelectToken("indicted.customerNew.regNum") ?? "") .Trim(); } string fullNameCustomer = ((string)c.SelectToken("indicted.customer.fullName") ?? "") .Trim(); if (String.IsNullOrEmpty(fullNameCustomer)) { fullNameCustomer = ((string)c.SelectToken("indicted.customerNew.fullName") ?? "") .Trim(); } string innCustomer = ((string)c.SelectToken("indicted.customer.INN") ?? "").Trim(); if (String.IsNullOrEmpty(innCustomer)) { innCustomer = ((string)c.SelectToken("indicted.customerNew.INN") ?? "").Trim(); } string kppCustomer = ((string)c.SelectToken("indicted.customer.KPP") ?? "").Trim(); if (String.IsNullOrEmpty(kppCustomer)) { kppCustomer = ((string)c.SelectToken("indicted.customerNew.KPP") ?? "").Trim(); } if (!String.IsNullOrEmpty(regNumCreateOrganization)) { idCustomer = GetIdOrg(regNumCustomer, fullNameCustomer, innCustomer, kppCustomer, "customer_complaint"); } string applicantFullName = ((string)c.SelectToken("applicantNew.legalEntity.fullName") ?? "").Trim(); if (String.IsNullOrEmpty(applicantFullName)) { applicantFullName = ((string)c.SelectToken("applicantNew.individualPerson.name") ?? "").Trim(); } if (String.IsNullOrEmpty(applicantFullName)) { applicantFullName = ((string)c.SelectToken("applicantNew.individualBusinessman.name") ?? "").Trim(); } if (String.IsNullOrEmpty(applicantFullName)) { applicantFullName = ((string)c.SelectToken("applicant.organizationName") ?? "").Trim(); } string applicantInn = ((string)c.SelectToken("applicantNew.legalEntity.INN") ?? "").Trim(); if (String.IsNullOrEmpty(applicantInn)) { applicantInn = ((string)c.SelectToken("applicantNew.individualPerson.INN") ?? "").Trim(); } if (String.IsNullOrEmpty(applicantInn)) { applicantInn = ((string)c.SelectToken("applicantNew.individualBusinessman.INN") ?? "") .Trim(); } string applicantKpp = ((string)c.SelectToken("applicantNew.legalEntity.KPP") ?? "").Trim(); if (String.IsNullOrEmpty(purchaseNumber)) { purchaseNumber = ((string)c.SelectToken("object.purchase.notificationNumber") ?? "").Trim(); } string lotNumbers = ""; List <JToken> lotnumbersList = GetElementsLots(c, "object.purchase.lots.lotNumber"); lotNumbers = String.Join(",", lotnumbersList); string lotsInfo = ((string)c.SelectToken("object.purchase.lots.info") ?? "").Trim(); string purchaseName = ((string)c.SelectToken("object.purchase.purchaseName") ?? "").Trim(); string purchasePlacingDate = (JsonConvert.SerializeObject( c.SelectToken("object.purchase.purchaseName.purchasePlacingDate") ?? "") ?? "").Trim('"'); string textComplaint = ((string)c.SelectToken("text") ?? "").Trim(); string returnInfobase = ((string)c.SelectToken("returnInfo.base") ?? "").Trim(); string returnInfo = ((string)c.SelectToken("returnInfo.decision.info") ?? "").Trim(); returnInfo = $"{returnInfobase} {returnInfo}".Trim(); string printForm = ((string)c.SelectToken("printForm.url") ?? "").Trim(); //int id_c = 0; if (upd == 1) { string deleteAtt = $"DELETE FROM {Program.Prefix}attach_complaint WHERE id_complaint = @id_complaint"; MySqlCommand cmd0 = new MySqlCommand(deleteAtt, connect); cmd0.Prepare(); cmd0.Parameters.AddWithValue("@id_complaint", idComp); cmd0.ExecuteNonQuery(); string updateC = $"UPDATE {Program.Prefix}complaint SET id_complaint = @id_complaint, complaintNumber = @complaintNumber, versionNumber = @versionNumber, xml = @xml, planDecisionDate = @planDecisionDate, id_registrationKO = @id_registrationKO, id_considerationKO = @id_considerationKO, regDate = @regDate, notice_number = @notice_number, notice_acceptDate = @notice_acceptDate, id_createOrganization = @id_createOrganization, createDate = @createDate, id_publishOrganization = @id_publishOrganization, id_customer = @id_customer, applicant_fullName = @applicant_fullName, applicant_INN = @applicant_INN, applicant_KPP = @applicant_KPP, purchaseNumber = @purchaseNumber, lotNumbers = @lotNumbers, lots_info = @lots_info, purchaseName = @purchaseName, purchasePlacingDate = @purchasePlacingDate, text_complaint = @text_complaint, printForm = @printForm, returnInfo = @returnInfo, regNumber = @regNumber WHERE id = @id_comp"; MySqlCommand cmd1 = new MySqlCommand(updateC, connect); cmd1.Prepare(); cmd1.Parameters.AddWithValue("@id_complaint", idComplaint); cmd1.Parameters.AddWithValue("@complaintNumber", complaintNumber); cmd1.Parameters.AddWithValue("@versionNumber", versionNumber); cmd1.Parameters.AddWithValue("@xml", xml); cmd1.Parameters.AddWithValue("@planDecisionDate", planDecisionDate); cmd1.Parameters.AddWithValue("@id_registrationKO", idRegistrationKo); cmd1.Parameters.AddWithValue("@id_considerationKO", idConsiderationKo); cmd1.Parameters.AddWithValue("@regDate", regDate); cmd1.Parameters.AddWithValue("@notice_number", noticeNumber); cmd1.Parameters.AddWithValue("@notice_acceptDate", noticeAcceptDate); cmd1.Parameters.AddWithValue("@id_createOrganization", idCreateOrganization); cmd1.Parameters.AddWithValue("@createDate", createDate); cmd1.Parameters.AddWithValue("@id_publishOrganization", idPublishOrganization); cmd1.Parameters.AddWithValue("@id_customer", idCustomer); cmd1.Parameters.AddWithValue("@applicant_fullName", applicantFullName); cmd1.Parameters.AddWithValue("@applicant_INN", applicantInn); cmd1.Parameters.AddWithValue("@applicant_KPP", applicantKpp); cmd1.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd1.Parameters.AddWithValue("@lotNumbers", lotNumbers); cmd1.Parameters.AddWithValue("@lots_info", lotsInfo); cmd1.Parameters.AddWithValue("@purchaseName", purchaseName); cmd1.Parameters.AddWithValue("@purchasePlacingDate", purchasePlacingDate); cmd1.Parameters.AddWithValue("@text_complaint", textComplaint); cmd1.Parameters.AddWithValue("@printForm", printForm); cmd1.Parameters.AddWithValue("@id_comp", idComp); cmd1.Parameters.AddWithValue("@returnInfo", returnInfo); cmd1.Parameters.AddWithValue("@regNumber", regNumber); int resUpdComp = cmd1.ExecuteNonQuery(); //id_c = id_comp; UpdateComplaint44?.Invoke(resUpdComp); } else { string insertC = $"INSERT INTO {Program.Prefix}complaint SET id_complaint = @id_complaint, complaintNumber = @complaintNumber, versionNumber = @versionNumber, xml = @xml, planDecisionDate = @planDecisionDate, id_registrationKO = @id_registrationKO, id_considerationKO = @id_considerationKO, regDate = @regDate, notice_number = @notice_number, notice_acceptDate = @notice_acceptDate, id_createOrganization = @id_createOrganization, createDate = @createDate, id_publishOrganization = @id_publishOrganization, id_customer = @id_customer, applicant_fullName = @applicant_fullName, applicant_INN = @applicant_INN, applicant_KPP = @applicant_KPP, purchaseNumber = @purchaseNumber, lotNumbers = @lotNumbers, lots_info = @lots_info, purchaseName = @purchaseName, purchasePlacingDate = @purchasePlacingDate, text_complaint = @text_complaint, printForm = @printForm, returnInfo = @returnInfo, regNumber = @regNumber"; MySqlCommand cmd1 = new MySqlCommand(insertC, connect); cmd1.Prepare(); cmd1.Parameters.AddWithValue("@id_complaint", idComplaint); cmd1.Parameters.AddWithValue("@complaintNumber", complaintNumber); cmd1.Parameters.AddWithValue("@versionNumber", versionNumber); cmd1.Parameters.AddWithValue("@xml", xml); cmd1.Parameters.AddWithValue("@planDecisionDate", planDecisionDate); cmd1.Parameters.AddWithValue("@id_registrationKO", idRegistrationKo); cmd1.Parameters.AddWithValue("@id_considerationKO", idConsiderationKo); cmd1.Parameters.AddWithValue("@regDate", regDate); cmd1.Parameters.AddWithValue("@notice_number", noticeNumber); cmd1.Parameters.AddWithValue("@notice_acceptDate", noticeAcceptDate); cmd1.Parameters.AddWithValue("@id_createOrganization", idCreateOrganization); cmd1.Parameters.AddWithValue("@createDate", createDate); cmd1.Parameters.AddWithValue("@id_publishOrganization", idPublishOrganization); cmd1.Parameters.AddWithValue("@id_customer", idCustomer); cmd1.Parameters.AddWithValue("@applicant_fullName", applicantFullName); cmd1.Parameters.AddWithValue("@applicant_INN", applicantInn); cmd1.Parameters.AddWithValue("@applicant_KPP", applicantKpp); cmd1.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd1.Parameters.AddWithValue("@lotNumbers", lotNumbers); cmd1.Parameters.AddWithValue("@lots_info", lotsInfo); cmd1.Parameters.AddWithValue("@purchaseName", purchaseName); cmd1.Parameters.AddWithValue("@purchasePlacingDate", purchasePlacingDate); cmd1.Parameters.AddWithValue("@text_complaint", textComplaint); cmd1.Parameters.AddWithValue("@printForm", printForm); cmd1.Parameters.AddWithValue("@returnInfo", returnInfo); cmd1.Parameters.AddWithValue("@regNumber", regNumber); int resInsertComp = cmd1.ExecuteNonQuery(); idComp = (int)cmd1.LastInsertedId; AddComplaint44?.Invoke(resInsertComp); } List <JToken> attach = GetElements(c, "attachments.attachment"); foreach (var att in attach) { string publishedContentId = ((string)att.SelectToken("publishedContentId") ?? "").Trim(); string fileName = ((string)att.SelectToken("fileName") ?? "").Trim(); string docDescription = ((string)att.SelectToken("docDescription") ?? "").Trim(); string url = ((string)att.SelectToken("url") ?? "").Trim(); string insertAtt = $"INSERT INTO {Program.Prefix}attach_complaint SET id_complaint = @id_complaint, publishedContentId = @publishedContentId, fileName = @fileName, docDescription = @docDescription, url = @url"; MySqlCommand cmd1 = new MySqlCommand(insertAtt, connect); cmd1.Prepare(); cmd1.Parameters.AddWithValue("@id_complaint", idComp); cmd1.Parameters.AddWithValue("@publishedContentId", publishedContentId); cmd1.Parameters.AddWithValue("@fileName", fileName); cmd1.Parameters.AddWithValue("@docDescription", docDescription); cmd1.Parameters.AddWithValue("@url", url); cmd1.ExecuteNonQuery(); } } } else { Log.Logger("Не могу найти тег complaint", FilePath); } }
public override void Parsing() { string xml = GetXml(File.ToString()); JObject root = (JObject)T.SelectToken("export"); JProperty firstOrDefault = root.Properties().FirstOrDefault(p => p.Name.Contains("bankGuarantee")); if (firstOrDefault != null) { JToken b = firstOrDefault.Value; string idGuarantee = ((string)b.SelectToken("id") ?? "").Trim(); string regNumber = ((string)b.SelectToken("regNumber") ?? "").Trim(); if (String.IsNullOrEmpty(regNumber)) { Log.Logger("Нет regNumber", FilePath); } string docNumber = ((string)b.SelectToken("docNumber") ?? "").Trim(); string versionNumber = ((string)b.SelectToken("versionNumber") ?? "").Trim(); string docPublishDate = (JsonConvert.SerializeObject(b.SelectToken("docPublishDate") ?? "") ?? "").Trim('"'); if (String.IsNullOrEmpty(docPublishDate)) { Log.Logger("Нет docPublishDate", FilePath); } using (MySqlConnection connect = ConnectToDb.GetDbConnection()) { connect.Open(); int upd = 0; int idGuar = 0; if (!String.IsNullOrEmpty(regNumber) && !String.IsNullOrEmpty(docPublishDate)) { string selectBankG = $"SELECT id FROM {Program.Prefix}bank_guarantee WHERE regNumber = @regNumber AND docPublishDate = @docPublishDate"; MySqlCommand cmd = new MySqlCommand(selectBankG, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@regNumber", regNumber); cmd.Parameters.AddWithValue("@docPublishDate", docPublishDate); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); idGuar = reader.GetInt32("id"); reader.Close(); upd = 1; //Log.Logger("Такой документ уже есть в базе", regNumber); //return; } reader.Close(); } int idBank = 0; string bankregNum = ((string)b.SelectToken("bank.regNum") ?? "").Trim(); if (!String.IsNullOrEmpty(bankregNum)) { string selectBank = $"SELECT id FROM {Program.Prefix}bank WHERE regNum = @regNum"; MySqlCommand cmd2 = new MySqlCommand(selectBank, connect); cmd2.Prepare(); cmd2.Parameters.AddWithValue("@regNum", bankregNum); MySqlDataReader reader = cmd2.ExecuteReader(); if (reader.HasRows) { reader.Read(); idBank = reader.GetInt32("id"); reader.Close(); } else { reader.Close(); string bankfullName = ((string)b.SelectToken("bank.fullName") ?? "").Trim(); string bankshortName = ((string)b.SelectToken("bank.shortName") ?? "").Trim(); string bankfactAddress = ((string)b.SelectToken("bank.factAddress") ?? "").Trim(); string bankInn = ((string)b.SelectToken("bank.INN") ?? "").Trim(); string bankKpp = ((string)b.SelectToken("bank.KPP") ?? "").Trim(); string banksubjectRfName = ((string)b.SelectToken("bank.subjectRF.name") ?? "").Trim(); string insertBank = $"INSERT INTO {Program.Prefix}bank SET regNum = @regNum, fullName = @fullName, shortName = @shortName, factAddress = @factAddress, INN = @INN, KPP = @KPP, subjectRFName = @subjectRFName"; MySqlCommand cmd3 = new MySqlCommand(insertBank, connect); cmd3.Prepare(); cmd3.Parameters.AddWithValue("@regNum", bankregNum); cmd3.Parameters.AddWithValue("@fullName", bankfullName); cmd3.Parameters.AddWithValue("@shortName", bankshortName); cmd3.Parameters.AddWithValue("@factAddress", bankfactAddress); cmd3.Parameters.AddWithValue("@INN", bankInn); cmd3.Parameters.AddWithValue("@KPP", bankKpp); cmd3.Parameters.AddWithValue("@subjectRFName", banksubjectRfName); cmd3.ExecuteNonQuery(); idBank = (int)cmd3.LastInsertedId; } } else { Log.Logger("Нет bank_reg_num", FilePath); } int idPlacer = 0; string placerRegNum = ((string)b.SelectToken("placingOrg.regNum") ?? "").Trim(); if (!String.IsNullOrEmpty(placerRegNum)) { string selectPlacer = $"SELECT id FROM {Program.Prefix}placer_org WHERE regNum = @regNum"; MySqlCommand cmd4 = new MySqlCommand(selectPlacer, connect); cmd4.Prepare(); cmd4.Parameters.AddWithValue("@regNum", bankregNum); MySqlDataReader reader = cmd4.ExecuteReader(); if (reader.HasRows) { reader.Read(); idPlacer = reader.GetInt32("id"); reader.Close(); } else { reader.Close(); string placerfullName = ((string)b.SelectToken("placingOrg.fullName") ?? "").Trim(); string placershortName = ((string)b.SelectToken("placingOrg.shortName") ?? "").Trim(); string placerfactAddress = ((string)b.SelectToken("placingOrg.factAddress") ?? "").Trim(); string placerInn = ((string)b.SelectToken("placingOrg.INN") ?? "").Trim(); string placerKpp = ((string)b.SelectToken("placingOrg.KPP") ?? "").Trim(); string placersubjectRfName = ((string)b.SelectToken("placingOrg.subjectRF.name") ?? "").Trim(); string insertPlacer = $"INSERT INTO {Program.Prefix}placer_org SET regNum = @regNum, fullName = @fullName, shortName = @shortName, factAddress = @factAddress, INN = @INN, KPP = @KPP, subjectRFName = @subjectRFName"; MySqlCommand cmd5 = new MySqlCommand(insertPlacer, connect); cmd5.Prepare(); cmd5.Parameters.AddWithValue("@regNum", bankregNum); cmd5.Parameters.AddWithValue("@fullName", placerfullName); cmd5.Parameters.AddWithValue("@shortName", placershortName); cmd5.Parameters.AddWithValue("@factAddress", placerfactAddress); cmd5.Parameters.AddWithValue("@INN", placerInn); cmd5.Parameters.AddWithValue("@KPP", placerKpp); cmd5.Parameters.AddWithValue("@subjectRFName", placersubjectRfName); cmd5.ExecuteNonQuery(); idPlacer = (int)cmd5.LastInsertedId; } } else { //Log.Logger("Нет placer_reg_num", file_path); } int idSupplier = 0; string innSup = ((string)b.SelectToken("supplier.inn") ?? "").Trim(); if (String.IsNullOrEmpty(innSup)) { innSup = ((string)b.SelectToken("supplierInfo.legalEntityRF.INN") ?? "").Trim(); } if (!String.IsNullOrEmpty(innSup)) { string kppSup = ((string)b.SelectToken("supplier.kpp") ?? "").Trim(); if (String.IsNullOrEmpty(kppSup)) { kppSup = ((string)b.SelectToken("supplierInfo.legalEntityRF.KPP") ?? "").Trim(); } string selectSupplier = $"SELECT id FROM {Program.Prefix}bank_supplier WHERE inn = @inn AND kpp = @kpp"; MySqlCommand cmd6 = new MySqlCommand(selectSupplier, connect); cmd6.Prepare(); cmd6.Parameters.AddWithValue("@inn", innSup); cmd6.Parameters.AddWithValue("@kpp", kppSup); MySqlDataReader reader = cmd6.ExecuteReader(); if (reader.HasRows) { reader.Read(); idSupplier = reader.GetInt32("id"); reader.Close(); } else { reader.Close(); string participantTypeSup = ((string)b.SelectToken("supplier.participantType") ?? "").Trim(); string ogrnSup = ((string)b.SelectToken("supplier.ogrn") ?? "").Trim(); string organizationNameSup = ((string)b.SelectToken("supplier.organizationName") ?? "").Trim(); string firmNameSup = ((string)b.SelectToken("supplier.firmName") ?? "").Trim(); string registrationDateSup = ((string)b.SelectToken("supplierInfo.legalEntityRF.registrationDate") ?? "").Trim(); string subjectRfNameSup = ((string)b.SelectToken("supplierInfo.legalEntityRF.subjectRF.name") ?? "").Trim(); string addressSup = ((string)b.SelectToken("supplier.factualAddress") ?? "").Trim(); string insertSupplier = $"INSERT INTO {Program.Prefix}bank_supplier SET participantType = @participantType, inn = @inn, kpp = @kpp, ogrn = @ogrn, organizationName = @organizationName, firmName = @firmName, registrationDate = @registrationDate, subjectRFName = @subjectRFName, address = @address"; MySqlCommand cmd7 = new MySqlCommand(insertSupplier, connect); cmd7.Prepare(); cmd7.Parameters.AddWithValue("@inn", innSup); cmd7.Parameters.AddWithValue("@kpp", kppSup); cmd7.Parameters.AddWithValue("@participantType", participantTypeSup); cmd7.Parameters.AddWithValue("@ogrn", ogrnSup); cmd7.Parameters.AddWithValue("@organizationName", organizationNameSup); cmd7.Parameters.AddWithValue("@firmName", firmNameSup); cmd7.Parameters.AddWithValue("@registrationDate", registrationDateSup); cmd7.Parameters.AddWithValue("@subjectRFName", subjectRfNameSup); cmd7.Parameters.AddWithValue("@address", addressSup); cmd7.ExecuteNonQuery(); idSupplier = (int)cmd7.LastInsertedId; } } else { Log.Logger("Нет inn_supplier", FilePath); } int idCustomer = 0; string customerregNum = ((string)b.SelectToken("guarantee.customer.regNum") ?? "").Trim(); if (!String.IsNullOrEmpty(customerregNum)) { string selectCustomer = $"SELECT id FROM {Program.Prefix}bank_customer WHERE regNum = @regNum"; MySqlCommand cmd8 = new MySqlCommand(selectCustomer, connect); cmd8.Prepare(); cmd8.Parameters.AddWithValue("@regNum", customerregNum); MySqlDataReader reader = cmd8.ExecuteReader(); if (reader.HasRows) { reader.Read(); idCustomer = reader.GetInt32("id"); reader.Close(); } else { reader.Close(); string customerfullName = ((string)b.SelectToken("guarantee.customer.fullName") ?? "").Trim(); string customerInn = ((string)b.SelectToken("guarantee.customer.INN") ?? "").Trim(); string customerKpp = ((string)b.SelectToken("guarantee.customer.KPP") ?? "").Trim(); string customerfactAddress = ((string)b.SelectToken("guarantee.customer.factAddress") ?? "").Trim(); string customerregistrationDate = ((string)b.SelectToken("guarantee.customer.registrationDate") ?? "").Trim(); string insertCustomer = $"INSERT INTO {Program.Prefix}bank_customer SET regNum = @regNum, fullName = @fullName, INN = @INN, KPP = @KPP, factAddress = @factAddress, registrationDate = @registrationDate"; MySqlCommand cmd9 = new MySqlCommand(insertCustomer, connect); cmd9.Prepare(); cmd9.Parameters.AddWithValue("@regNum", customerregNum); cmd9.Parameters.AddWithValue("@fullName", customerfullName); cmd9.Parameters.AddWithValue("@INN", customerInn); cmd9.Parameters.AddWithValue("@KPP", customerKpp); cmd9.Parameters.AddWithValue("@factAddress", customerfactAddress); cmd9.Parameters.AddWithValue("@registrationDate", customerregistrationDate); cmd9.ExecuteNonQuery(); idCustomer = (int)cmd9.LastInsertedId; } } else { Log.Logger("Нет customer_reg_num", FilePath); } string purchaseNumber = ((string)b.SelectToken("guarantee.contractExecutionEnsure.purchase.purchaseNumber") ?? "") .Trim(); if (String.IsNullOrEmpty(purchaseNumber)) { purchaseNumber = ((string)b.SelectToken("guarantee.purchaseRequestEnsure.purchaseNumber") ?? "") .Trim(); } string lotNumber = ((string)b.SelectToken("guarantee.contractExecutionEnsure.purchase.lotNumber") ?? "").Trim(); if (String.IsNullOrEmpty(lotNumber)) { lotNumber = ((string)b.SelectToken("guarantee.purchaseRequestEnsure.lotNumber") ?? "") .Trim(); } string guaranteeDate = (JsonConvert.SerializeObject(b.SelectToken("guarantee.guaranteeDate") ?? "") ?? "").Trim('"'); string guaranteeAmount = ((string)b.SelectToken("guarantee.guaranteeAmount") ?? "").Trim(); string currencyCode = ((string)b.SelectToken("guarantee.currency.code") ?? "").Trim(); string expireDate = (JsonConvert.SerializeObject(b.SelectToken("guarantee.expireDate") ?? "") ?? "").Trim('"'); string entryForceDate = (JsonConvert.SerializeObject(b.SelectToken("guarantee.entryForceDate") ?? "") ?? "").Trim('"'); string href = ((string)b.SelectToken("href") ?? "").Trim(); string printForm = ((string)b.SelectToken("printForm.url") ?? "").Trim(); int idG = 0; if (upd == 1) { string deleteAtt = $"DELETE FROM {Program.Prefix}bank_attach WHERE id_guar = @id_guar"; MySqlCommand cmd0 = new MySqlCommand(deleteAtt, connect); cmd0.Prepare(); cmd0.Parameters.AddWithValue("@id_guar", idGuar); cmd0.ExecuteNonQuery(); string updateG = $"UPDATE {Program.Prefix}bank_guarantee SET id_guarantee = @id_guarantee, regNumber = @regNumber, docNumber = @docNumber, versionNumber = @versionNumber, docPublishDate = @docPublishDate, purchaseNumber = @purchaseNumber, lotNumber = @lotNumber, guaranteeDate = @guaranteeDate, guaranteeAmount = @guaranteeAmount, currencyCode = @currencyCode, expireDate = @expireDate, entryForceDate = @entryForceDate, href = @href, print_form = @print_form, xml = @xml, id_bank = @id_bank, id_placer = @id_placer, id_customer = @id_customer, id_supplier = @id_supplier WHERE id = @id"; MySqlCommand cmd10 = new MySqlCommand(updateG, connect); cmd10.Prepare(); cmd10.Parameters.AddWithValue("@id_guarantee", idGuarantee); cmd10.Parameters.AddWithValue("@regNumber", regNumber); cmd10.Parameters.AddWithValue("@docNumber", docNumber); cmd10.Parameters.AddWithValue("@versionNumber", versionNumber); cmd10.Parameters.AddWithValue("@docPublishDate", docPublishDate); cmd10.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd10.Parameters.AddWithValue("@lotNumber", lotNumber); cmd10.Parameters.AddWithValue("@guaranteeDate", guaranteeDate); cmd10.Parameters.AddWithValue("@guaranteeAmount", guaranteeAmount); cmd10.Parameters.AddWithValue("@currencyCode", currencyCode); cmd10.Parameters.AddWithValue("@expireDate", expireDate); cmd10.Parameters.AddWithValue("@entryForceDate", entryForceDate); cmd10.Parameters.AddWithValue("@href", href); cmd10.Parameters.AddWithValue("@print_form", printForm); cmd10.Parameters.AddWithValue("@xml", xml); cmd10.Parameters.AddWithValue("@id_bank", idBank); cmd10.Parameters.AddWithValue("@id_placer", idPlacer); cmd10.Parameters.AddWithValue("@id_customer", idCustomer); cmd10.Parameters.AddWithValue("@id_supplier", idSupplier); cmd10.Parameters.AddWithValue("@id", idGuar); int resUpdateG = cmd10.ExecuteNonQuery(); idG = idGuar; UpdateBank44?.Invoke(resUpdateG); } else { string insertG = $"INSERT INTO {Program.Prefix}bank_guarantee SET id_guarantee = @id_guarantee, regNumber = @regNumber, docNumber = @docNumber, versionNumber = @versionNumber, docPublishDate = @docPublishDate, purchaseNumber = @purchaseNumber, lotNumber = @lotNumber, guaranteeDate = @guaranteeDate, guaranteeAmount = @guaranteeAmount, currencyCode = @currencyCode, expireDate = @expireDate, entryForceDate = @entryForceDate, href = @href, print_form = @print_form, xml = @xml, id_bank = @id_bank, id_placer = @id_placer, id_customer = @id_customer, id_supplier = @id_supplier"; MySqlCommand cmd10 = new MySqlCommand(insertG, connect); cmd10.Prepare(); cmd10.Parameters.AddWithValue("@id_guarantee", idGuarantee); cmd10.Parameters.AddWithValue("@regNumber", regNumber); cmd10.Parameters.AddWithValue("@docNumber", docNumber); cmd10.Parameters.AddWithValue("@versionNumber", versionNumber); cmd10.Parameters.AddWithValue("@docPublishDate", docPublishDate); cmd10.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd10.Parameters.AddWithValue("@lotNumber", lotNumber); cmd10.Parameters.AddWithValue("@guaranteeDate", guaranteeDate); cmd10.Parameters.AddWithValue("@guaranteeAmount", guaranteeAmount); cmd10.Parameters.AddWithValue("@currencyCode", currencyCode); cmd10.Parameters.AddWithValue("@expireDate", expireDate); cmd10.Parameters.AddWithValue("@entryForceDate", entryForceDate); cmd10.Parameters.AddWithValue("@href", href); cmd10.Parameters.AddWithValue("@print_form", printForm); cmd10.Parameters.AddWithValue("@xml", xml); cmd10.Parameters.AddWithValue("@id_bank", idBank); cmd10.Parameters.AddWithValue("@id_placer", idPlacer); cmd10.Parameters.AddWithValue("@id_customer", idCustomer); cmd10.Parameters.AddWithValue("@id_supplier", idSupplier); int resInsertG = cmd10.ExecuteNonQuery(); idG = (int)cmd10.LastInsertedId; AddBank44?.Invoke(resInsertG); } List <JToken> attach = GetElements(b, "agreementDocuments.attachment"); foreach (var att in attach) { string fileName = ((string)att.SelectToken("fileName") ?? "").Trim(); string docDescription = ((string)att.SelectToken("docDescription") ?? "").Trim(); string url = ((string)att.SelectToken("url") ?? "").Trim(); string insertAttach = $"INSERT INTO {Program.Prefix}bank_attach SET id_guar = @id_guar, fileName = @fileName, docDescription = @docDescription, url = @url"; MySqlCommand cmd11 = new MySqlCommand(insertAttach, connect); cmd11.Prepare(); cmd11.Parameters.AddWithValue("@id_guar", idG); cmd11.Parameters.AddWithValue("@fileName", fileName); cmd11.Parameters.AddWithValue("@docDescription", docDescription); cmd11.Parameters.AddWithValue("@url", url); cmd11.ExecuteNonQuery(); } } //Console.WriteLine(id); } else { Log.Logger("Не могу найти тег bankGuarantee", FilePath); } }
public override void Parsing() { string xml = GetXml(File.ToString()); JObject root = (JObject)T.SelectToken("export"); JProperty firstOrDefault = root.Properties().FirstOrDefault(p => p.Name.Contains("unfairSupplier")); if (firstOrDefault != null) { JToken r = firstOrDefault.Value; string registryNum = ((string)r.SelectToken("registryNum") ?? "").Trim(); if (String.IsNullOrEmpty(registryNum)) { Log.Logger("У unfair нет registryNum", FilePath); } string publishDate = (JsonConvert.SerializeObject(r.SelectToken("publishDate") ?? "") ?? "").Trim('"'); if (String.IsNullOrEmpty(publishDate)) { Log.Logger("Нет publishDate", FilePath); } string approveDate = (JsonConvert.SerializeObject(r.SelectToken("approveDate") ?? "") ?? "").Trim('"'); if (String.IsNullOrEmpty(approveDate)) { Log.Logger("Нет approveDate", FilePath); } string state = ((string)r.SelectToken("state") ?? "").Trim(); using (MySqlConnection connect = ConnectToDb.GetDbConnection()) { connect.Open(); if (!String.IsNullOrEmpty(registryNum) && !String.IsNullOrEmpty(publishDate)) { string selectUnf = $"SELECT id FROM {Program.Prefix}unfair WHERE registryNum = @registryNum AND publishDate = @publishDate AND state = @state"; MySqlCommand cmd = new MySqlCommand(selectUnf, connect); cmd.Prepare(); cmd.Parameters.AddWithValue("@registryNum", registryNum); cmd.Parameters.AddWithValue("@publishDate", publishDate); cmd.Parameters.AddWithValue("@state", state); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Close(); Log.Logger("Такой документ уже есть в базе", registryNum); return; } reader.Close(); /*string select_unf2 = * $"SELECT id FROM {Program.Prefix}unfair WHERE registryNum = @registryNum AND publishDate = @publishDate"; * MySqlCommand cmd2 = new MySqlCommand(select_unf2, connect); * cmd2.Prepare(); * cmd2.Parameters.AddWithValue("@registryNum", registryNum); * cmd2.Parameters.AddWithValue("@publishDate", publishDate); * MySqlDataReader reader2 = cmd2.ExecuteReader(); * if (reader2.HasRows) * { * reader2.Close(); * string update_unf = * $"UPDATE {Program.Prefix}unfair SET state = @state WHERE registryNum = @registryNum AND publishDate = @publishDate"; * MySqlCommand cmd3 = new MySqlCommand(update_unf, connect); * cmd3.Prepare(); * cmd3.Parameters.AddWithValue("@registryNum", registryNum); * cmd3.Parameters.AddWithValue("@publishDate", publishDate); * cmd3.Parameters.AddWithValue("@state", state); * cmd3.ExecuteNonQuery(); * Log.Logger("Обновили документ в базе", registryNum); * return; * } * reader2.Close();*/ } int idOrg = 0; string publishOrgregNum = ((string)r.SelectToken("publishOrg.regNum") ?? "").Trim(); string publishOrgfullName = ((string)r.SelectToken("publishOrg.fullName") ?? "").Trim(); if (!String.IsNullOrEmpty(publishOrgregNum)) { string selectPubOrg = $"SELECT id FROM {Program.Prefix}unfair_publish_org WHERE regNum = @regNum"; MySqlCommand cmd4 = new MySqlCommand(selectPubOrg, connect); cmd4.Prepare(); cmd4.Parameters.AddWithValue("@regNum", publishOrgregNum); MySqlDataReader reader3 = cmd4.ExecuteReader(); if (reader3.HasRows) { reader3.Read(); idOrg = reader3.GetInt32("id"); reader3.Close(); } else { reader3.Close(); string insertPubOrg = $"INSERT INTO {Program.Prefix}unfair_publish_org SET regNum = @regNum, fullName = @fullName"; MySqlCommand cmd5 = new MySqlCommand(insertPubOrg, connect); cmd5.Prepare(); cmd5.Parameters.AddWithValue("@regNum", publishOrgregNum); cmd5.Parameters.AddWithValue("@fullName", publishOrgfullName); cmd5.ExecuteNonQuery(); idOrg = (int)cmd5.LastInsertedId; } } else { Log.Logger("Нет organizer_reg_num", FilePath); } string createReason = ((string)r.SelectToken("createReason") ?? "").Trim(); string approveReason = ((string)r.SelectToken("approveReason") ?? "").Trim(); int idCustomer = 0; string customerregNum = ((string)r.SelectToken("customer.regNum") ?? "").Trim(); string customerfullName = ((string)r.SelectToken("customer.fullName") ?? "").Trim(); string customerInn = ((string)r.SelectToken("customer.INN") ?? "").Trim(); string customerKpp = ((string)r.SelectToken("customer.KPP") ?? "").Trim(); if (!String.IsNullOrEmpty(customerregNum)) { string selectCustomer = $"SELECT id FROM {Program.Prefix}unfair_customer WHERE regNum = @regNum"; MySqlCommand cmd6 = new MySqlCommand(selectCustomer, connect); cmd6.Prepare(); cmd6.Parameters.AddWithValue("@regNum", customerregNum); MySqlDataReader reader4 = cmd6.ExecuteReader(); if (reader4.HasRows) { reader4.Read(); idCustomer = reader4.GetInt32("id"); reader4.Close(); } else { reader4.Close(); string insertCustomer = $"INSERT INTO {Program.Prefix}unfair_customer SET regNum = @regNum, fullName = @fullName, INN = @INN, KPP = @KPP"; MySqlCommand cmd7 = new MySqlCommand(insertCustomer, connect); cmd7.Prepare(); cmd7.Parameters.AddWithValue("@regNum", customerregNum); cmd7.Parameters.AddWithValue("@fullName", customerfullName); cmd7.Parameters.AddWithValue("@INN", customerInn); cmd7.Parameters.AddWithValue("@KPP", customerKpp); cmd7.ExecuteNonQuery(); idCustomer = (int)cmd7.LastInsertedId; } } else { Log.Logger("Нет customer_reg_num", FilePath); } int idSupplier = 0; string innSupplier = ((string)r.SelectToken("unfairSupplier.inn") ?? "").Trim(); string kppSupplier = ((string)r.SelectToken("unfairSupplier.kpp") ?? "").Trim(); string fullNameSupplier = ((string)r.SelectToken("unfairSupplier.fullName") ?? "").Trim(); string placefullName = ((string)r.SelectToken("unfairSupplier.place.kladr.fullName") ?? "") .Trim(); string subjectRf = ((string)r.SelectToken("unfairSupplier.place.kladr.subjectRF") ?? "") .Trim(); string area = ((string)r.SelectToken("unfairSupplier.place.kladr.area") ?? "") .Trim(); string street = ((string)r.SelectToken("unfairSupplier.place.kladr.street") ?? "") .Trim(); string building = ((string)r.SelectToken("unfairSupplier.place.kladr.building") ?? "") .Trim(); placefullName = $"{subjectRf}, {area}, {street}, {building}, {placefullName}"; if (!String.IsNullOrEmpty(innSupplier)) { string selectSupplier = $"SELECT id FROM {Program.Prefix}unfair_suppplier WHERE inn = @inn AND kpp = @kpp"; MySqlCommand cmd8 = new MySqlCommand(selectSupplier, connect); cmd8.Prepare(); cmd8.Parameters.AddWithValue("@inn", innSupplier); cmd8.Parameters.AddWithValue("@kpp", kppSupplier); MySqlDataReader reader5 = cmd8.ExecuteReader(); if (reader5.HasRows) { reader5.Read(); idSupplier = reader5.GetInt32("id"); reader5.Close(); } else { reader5.Close(); string email = ((string)r.SelectToken("unfairSupplier.place.email") ?? "").Trim(); string foundersNames = ((string)r.SelectToken("unfairSupplier.founders.names") ?? "").Trim(); string foundersInn = ((string)r.SelectToken("unfairSupplier.founders.inn") ?? "").Trim(); string insertSupplier = $"INSERT INTO {Program.Prefix}unfair_suppplier SET inn = @inn, kpp = @kpp, fullName = @fullName, placefullName = @placefullName, email = @email, founders_names = @founders_names, founders_inn = @founders_inn"; MySqlCommand cmd9 = new MySqlCommand(insertSupplier, connect); cmd9.Prepare(); cmd9.Parameters.AddWithValue("@inn", innSupplier); cmd9.Parameters.AddWithValue("@kpp", kppSupplier); cmd9.Parameters.AddWithValue("@fullName", fullNameSupplier); cmd9.Parameters.AddWithValue("@placefullName", placefullName); cmd9.Parameters.AddWithValue("@email", email); cmd9.Parameters.AddWithValue("@founders_names", foundersNames); cmd9.Parameters.AddWithValue("@founders_inn", foundersInn); cmd9.ExecuteNonQuery(); idSupplier = (int)cmd9.LastInsertedId; } } else { Log.Logger("Нет inn_supplier", FilePath); } string purchaseNumber = ((string)r.SelectToken("purchase.purchaseNumber") ?? "").Trim(); string purchaseObjectInfo = ((string)r.SelectToken("purchase.purchaseObjectInfo") ?? "").Trim(); string lotNumber = ((string)r.SelectToken("purchase.lotNumber") ?? "").Trim(); string contractRegNum = ((string)r.SelectToken("contract.regNum") ?? "").Trim(); string contractProductInfo = ((string)r.SelectToken("contract.productInfo") ?? "").Trim(); string contractOkpdCode = ((string)r.SelectToken("contract.OKPD.code") ?? "").Trim(); string contractOkpdName = ((string)r.SelectToken("contract.OKPD.name") ?? "").Trim(); string contractCurrencyCode = ((string)r.SelectToken("contract.currency.code") ?? "").Trim(); string contractPrice = ((string)r.SelectToken("contract.price") ?? "").Trim(); string contractCancelSignDate = ((string)r.SelectToken("contract.cancel.signDate") ?? "").Trim(); string contractCancelPerformanceDate = ((string)r.SelectToken("contract.cancel.performanceDate") ?? "").Trim(); string contractCancelBaseName = ((string)r.SelectToken("contract.cancel.base.name") ?? "").Trim(); string contractCancelCancelDate = ((string)r.SelectToken("contract.cancel.cancelDate") ?? "").Trim(); string insertUnfair = $"INSERT INTO {Program.Prefix}unfair SET publishDate = @publishDate, approveDate = @approveDate, registryNum = @registryNum, state = @state, createReason = @createReason, approveReason = @approveReason, id_customer = @id_customer, id_supplier = @id_supplier, id_org = @id_org, purchaseNumber = @purchaseNumber, purchaseObjectInfo = @purchaseObjectInfo, lotNumber = @lotNumber, contract_regNum = @contract_regNum, contract_productInfo = @contract_productInfo, contract_OKPD_code = @contract_OKPD_code, contract_OKPD_name = @contract_OKPD_name, contract_currency_code = @contract_currency_code, contract_price = @contract_price, contract_cancel_signDate = @contract_cancel_signDate, contract_cancel_performanceDate = @contract_cancel_performanceDate, contract_cancel_base_name = @contract_cancel_base_name, contract_cancel_cancelDate = @contract_cancel_cancelDate, full_name_supplier = @full_name_supplier, placefullName_supplier = @placefullName_supplier"; MySqlCommand cmd10 = new MySqlCommand(insertUnfair, connect); cmd10.Prepare(); cmd10.Parameters.AddWithValue("@publishDate", publishDate); cmd10.Parameters.AddWithValue("@approveDate", approveDate); cmd10.Parameters.AddWithValue("@registryNum", registryNum); cmd10.Parameters.AddWithValue("@state", state); cmd10.Parameters.AddWithValue("@createReason", createReason); cmd10.Parameters.AddWithValue("@approveReason", approveReason); cmd10.Parameters.AddWithValue("@id_customer", idCustomer); cmd10.Parameters.AddWithValue("@id_supplier", idSupplier); cmd10.Parameters.AddWithValue("@id_org", idOrg); cmd10.Parameters.AddWithValue("@purchaseNumber", purchaseNumber); cmd10.Parameters.AddWithValue("@purchaseObjectInfo", purchaseObjectInfo); cmd10.Parameters.AddWithValue("@lotNumber", lotNumber); cmd10.Parameters.AddWithValue("@contract_regNum", contractRegNum); cmd10.Parameters.AddWithValue("@contract_productInfo", contractProductInfo); cmd10.Parameters.AddWithValue("@contract_OKPD_code", contractOkpdCode); cmd10.Parameters.AddWithValue("@contract_OKPD_name", contractOkpdName); cmd10.Parameters.AddWithValue("@contract_currency_code", contractCurrencyCode); cmd10.Parameters.AddWithValue("@contract_price", contractPrice); cmd10.Parameters.AddWithValue("@contract_cancel_signDate", contractCancelSignDate); cmd10.Parameters.AddWithValue("@contract_cancel_performanceDate", contractCancelPerformanceDate); cmd10.Parameters.AddWithValue("@contract_cancel_base_name", contractCancelBaseName); cmd10.Parameters.AddWithValue("@contract_cancel_cancelDate", contractCancelCancelDate); cmd10.Parameters.AddWithValue("@full_name_supplier", fullNameSupplier); cmd10.Parameters.AddWithValue("@placefullName_supplier", placefullName); int resInsertUnf = cmd10.ExecuteNonQuery(); AddUnfair44?.Invoke(resInsertUnf); } } else { Log.Logger("Не могу найти тег unfairSupplier", FilePath); } }