public Tblbetlin Update_Nr_Faknr(Tblbetlin m_rec_betlin, dbData3060DataContext p_dbData3060) { Tblbetlin m_rec_betlin_save = m_rec_betlin; try { var xFaknr = m_rec_betlin.Faknr; var xDebitorkonto = m_rec_betlin.Debitorkonto; var xNr = m_rec_betlin.Nr; // find Tblfak var qry1 = from f in p_dbData3060.Tblfak where f.Faknr == xFaknr select f; var count1 = qry1.Count(); if (count1 > 0) { var recfak1 = qry1.First(); m_rec_betlin.Nr = recfak1.Nr; } else { var qry2 = from f in p_dbData3060.Tblfak where f.Indbetalerident == xDebitorkonto select f; var count2 = qry2.Count(); if (count2 > 0) { var recfak2 = qry2.First(); m_rec_betlin.Nr = recfak2.Nr; m_rec_betlin.Faknr = recfak2.Faknr; } } } catch { return(m_rec_betlin_save); } return(m_rec_betlin); }
public void read042(string sektion, string transkode, string rec, dbData3060DataContext p_dbData3060) { int fortegn; decimal belobmun; int belob; // -- pbssektionnr // -- pbstranskode // - transkode 0236, gennemført automatisk betaling // - transkode 0237, afvist automatisk betaling // - transkode 0238, afmeldt automatisk betaling // - transkode 0239, tilbageført betaling m_rec_betlin = new Tblbetlin { Pbssektionnr = sektion, Pbstranskode = transkode }; // -- debitorkonto if ((sektion == "0211")) { m_rec_betlin.Debitorkonto = rec.Substring(25, 15); if (m_rec_betlin.Debitorkonto.StartsWith("03200161")) { m_rec_betlin.Nr = int.Parse(rec.Substring(33, 7)); //***MHA*** } else { m_rec_betlin.Nr = null; } } else if ((sektion == "0215")) { m_rec_betlin.Debitorkonto = rec.Substring(29, 15); if (m_rec_betlin.Debitorkonto.StartsWith("03200161")) { m_rec_betlin.Nr = int.Parse(rec.Substring(37, 7)); } else { m_rec_betlin.Nr = null; } } else { m_rec_betlin.Nr = null; m_rec_betlin.Debitorkonto = null; } // -- aftalenr if ((sektion == "0211")) { m_rec_betlin.Aftalenr = int.Parse(rec.Substring(40, 9)); } else { m_rec_betlin.Aftalenr = null; } // -- pbskortart if ((sektion == "0215")) { m_rec_betlin.Pbskortart = rec.Substring(44, 2); } else { m_rec_betlin.Pbskortart = null; } // -- pbsgebyrbelob if ((sektion == "0215")) { fortegn = int.Parse(rec.Substring(46, 1)); belob = int.Parse(rec.Substring(47, 5)); belobmun = (belob / 100); if ((fortegn == 0)) { m_rec_betlin.Pbsgebyrbelob = 0; } else if ((fortegn == 1)) { m_rec_betlin.Pbsgebyrbelob = belobmun; } else { m_rec_betlin.Pbsgebyrbelob = 0; } } else { m_rec_betlin.Pbsgebyrbelob = 0; } // -- betalingsdato if ((sektion == "0211")) { if ((rec.Substring(49, 6) != "000000")) { m_rec_betlin.Betalingsdato = DateTime.Parse("20" + (rec.Substring(53, 2) + ("-" + (rec.Substring(51, 2) + ("-" + rec.Substring(49, 2)))))); } else { m_rec_betlin.Betalingsdato = null; } } else if ((sektion == "0215")) { if ((rec.Substring(52, 6) != "000000")) { m_rec_betlin.Betalingsdato = DateTime.Parse("20" + (rec.Substring(56, 2) + ("-" + (rec.Substring(54, 2) + ("-" + rec.Substring(52, 2)))))); } else { m_rec_betlin.Betalingsdato = null; } } else { m_rec_betlin.Betalingsdato = null; } // -- belob if ((sektion == "0211")) { fortegn = int.Parse(rec.Substring(55, 1)); belob = int.Parse(rec.Substring(56, 13)); belobmun = (belob / 100); if ((fortegn == 0)) { m_rec_betlin.Belob = 0; } else if ((fortegn == 1)) { m_rec_betlin.Belob = belobmun; } else if ((fortegn == 2)) { m_rec_betlin.Belob = (belobmun * -1); } else { m_rec_betlin.Belob = null; } } else if ((sektion == "0215")) { fortegn = int.Parse(rec.Substring(58, 1)); belob = int.Parse(rec.Substring(59, 13)); belobmun = (belob / 100); if ((fortegn == 0)) { m_rec_betlin.Belob = 0; } else if ((fortegn == 1)) { m_rec_betlin.Belob = belobmun; } else { m_rec_betlin.Belob = null; } } else { m_rec_betlin.Belob = null; } // -- faknr if ((sektion == "0211")) { m_rec_betlin.Faknr = int.Parse("0" + rec.Substring(69, 9).Trim()); //***MHA*** } else if ((sektion == "0215")) { m_rec_betlin.Faknr = int.Parse("0" + rec.Substring(72, 9).Trim()); } else { m_rec_betlin.Faknr = null; } // -- pbsarkivnr if ((sektion == "0215")) { m_rec_betlin.Pbsarkivnr = rec.Substring(81, 22); } else { m_rec_betlin.Pbsarkivnr = null; } // -- indbetalingsdato if ((rec.Substring(103, 6) != "000000")) { m_rec_betlin.Indbetalingsdato = DateTime.Parse("20" + (rec.Substring(107, 2) + ("-" + (rec.Substring(105, 2) + ("-" + rec.Substring(103, 2)))))); } else { m_rec_betlin.Indbetalingsdato = null; } // -- bogforingsdato if ((rec.Substring(109, 6) != "000000")) { m_rec_betlin.Bogforingsdato = DateTime.Parse("20" + (rec.Substring(113, 2) + ("-" + (rec.Substring(111, 2) + ("-" + rec.Substring(109, 2)))))); } else { m_rec_betlin.Bogforingsdato = null; } // -- indbetalingsbelob if ((sektion == "0211")) { fortegn = int.Parse(rec.Substring(55, 1)); belob = int.Parse(rec.Substring(115, 13)); belobmun = (belob / 100); if ((fortegn == 0)) { m_rec_betlin.Indbetalingsbelob = 0; } else if ((fortegn == 1)) { m_rec_betlin.Indbetalingsbelob = belobmun; } else if ((fortegn == 2)) { m_rec_betlin.Indbetalingsbelob = (belobmun * -1); } else { m_rec_betlin.Indbetalingsbelob = null; } } else if ((sektion == "0215")) { fortegn = int.Parse(rec.Substring(58, 1)); belob = int.Parse(rec.Substring(115, 13)); belobmun = (belob / 100); if ((fortegn == 0)) { m_rec_betlin.Indbetalingsbelob = 0; } else if ((fortegn == 1)) { m_rec_betlin.Indbetalingsbelob = belobmun; } else { m_rec_betlin.Indbetalingsbelob = null; } } else { m_rec_betlin.Indbetalingsbelob = null; } // Find or Create tblber record try { m_rec_bet = (from c in m_rec_frapbs.Tblbet where c.Pbssektionnr == sektion && c.Transkode == transkode && c.Bogforingsdato == m_rec_betlin.Bogforingsdato select c).First(); } catch (System.InvalidOperationException) { m_rec_bet = new Tblbet { Pbssektionnr = sektion, Transkode = transkode, Bogforingsdato = m_rec_betlin.Bogforingsdato }; m_rec_frapbs.Tblbet.Add(m_rec_bet); } // Add tblbetlin Tblbetlin w_rec_betlin = Update_Nr_Faknr(m_rec_betlin, p_dbData3060); m_rec_bet.Tblbetlin.Add(w_rec_betlin); try { p_dbData3060.SaveChanges(); } catch (Exception e) { Console.WriteLine(string.Format("clsPbs602 read042 p_dbData3060.SaveChanges() failed with message: {0}", e.Message)); } }