Föy Fatura Fatura Ödeme C# Webservis Kodu

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using Newtonsoft.Json.Linq;
using System.Runtime.InteropServices;

namespace FoyFatura
{
public partial class Form1 : Form
{
string tutar, sonodeme, dosyaYolu, apikeyy,referans_no;
float fatura_tutari = 0;

[DllImport(“kernel32.dll”)]
static extern uint GetPrivateProfileString(
string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);

OleDbConnection con;
OleDbDataAdapter da;
OleDbCommand cmd;
DataSet ds;

foyfatura.FoyOnlineApiGateWS fatura = new foyfatura.FoyOnlineApiGateWS();

void griddoldur()
{

con = new OleDbConnection(“Provider=Microsoft.ACE.Oledb.12.0;Data Source=foyfatura.mdb”);
da = new OleDbDataAdapter(“Select * from foyfatura where FATURA_ID is null”, con);
ds = new DataSet();
con.Open();
da.Fill(ds, “fatura”);
dataGridView1.DataSource = ds.Tables[“fatura”];
//con.Close();
}

void fatura_sorgula() {

griddoldur();

String sql = “Select * from foyfatura where FATURA_ID is null and DURUM=’bos’ “;

OleDbCommand komut = new OleDbCommand(sql, con);

int Count = Convert.ToInt32(komut.ExecuteScalar());

if (Count != 0)
{

OleDbDataReader oku = komut.ExecuteReader();
while (oku.Read())
{
txsorgu_id.Text = oku[“ID”].ToString();
txkurumno.Text = oku[“KURUM”].ToString();
txaboneno1.Text = oku[“TESISAT_NO1”].ToString();
txaboneno2.Text = oku[“TESISAT_NO2”].ToString();
tutar = oku[“TUTAR”].ToString();
sonodeme = oku[“SON_ODEME_TARIHI”].ToString();
string kurum = oku[“KURUM”].ToString();

string unique = Guid.NewGuid().ToString();
referans_no = unique.Substring(0, 15);

string sorgu = fatura.InvoiceQuery(kullanici.Text, parola.Text, apikeyy, txkurumno.Text, txaboneno1.Text, txaboneno2.Text,referans_no);
JObject baslik = JObject.Parse(sorgu);

string sonuc=baslik[“ResultCode”].ToString();
string mesaj = baslik[“ResultMessage”].ToString();

richTextBox1.Text = sorgu.ToString();

if (sonuc==”1″)
{
sorgu = sorgu.Substring(sorgu.IndexOf(“[“), sorgu.IndexOf(“]”) – sorgu.IndexOf(“[“) + 1);

var objects = JArray.Parse(sorgu);

foreach (JObject root in objects)
{
string FaturaId = root[“InvoiceId”].ToString();
string SonOdemeTarihi = root[“LastDate”].ToString();
string FaturaTutari = root[“Amount”].ToString();

float vt_tutar = float.Parse(tutar);
fatura_tutari = float.Parse(root[“Amount”].ToString());

richTextBox1.Text += FaturaId + Environment.NewLine + SonOdemeTarihi + Environment.NewLine + FaturaTutari + Environment.NewLine;

//SON ÖDEME VE TUTAR KONTROLÜ YAP

if (((fatura_tutari – vt_tutar <= 1) && (fatura_tutari – vt_tutar>= 0)) || kurum.Equals(“1”) )
{
if (sonodeme.Trim() == SonOdemeTarihi.Trim() || kurum.Equals(“1”))
{

String sql1 = “UPDATE foyfatura SET FATURA_ID='” + FaturaId + “‘, DURUM=’bos’ WHERE ID=” + txsorgu_id.Text + ” AND SON_ODEME_TARIHI='” + SonOdemeTarihi + “‘ “;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();

}
else {

String sql1 = “UPDATE foyfatura SET DURUM=’Sorgu Başarısız’ WHERE ID=” + txsorgu_id.Text + ” and FATURA_ID IS NULL”;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();

}

}
else
{

String sql1 = “UPDATE foyfatura SET DURUM=’Yüksek Tutar Farkı’ WHERE ID=” + txsorgu_id.Text + ” and FATURA_ID IS NULL “;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();

}

}
}
else
{
String sql1 = “UPDATE foyfatura SET DURUM='” + mesaj + “‘ WHERE ID=” + txsorgu_id.Text + ” and FATURA_ID IS NULL “;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();

}

System.Threading.Thread.Sleep(2000);

}

}

}

void fatura_ode() {

griddoldur();

String sql = “Select * from foyfatura where FATURA_ID is not null and DURUM=’bos’ “;

OleDbCommand komut = new OleDbCommand(sql, con);

int Count = Convert.ToInt32(komut.ExecuteScalar());

if (Count != 0)
{

OleDbDataReader oku = komut.ExecuteReader();
while (oku.Read())
{
string fatura_id = oku[“FATURA_ID”].ToString();
float vttutar = float.Parse(oku[“TUTAR”].ToString().Trim());
string kurum = oku[“KURUM”].ToString();

string iski_tutar = oku[“TUTAR”].ToString().Trim();

string sorgu1 = fatura.GetBalanceInformation(kullanici.Text, parola.Text,apikeyy);
string gelen_bakiye=”0″;
JObject o = JObject.Parse(sorgu1);
gelen_bakiye = o[“Balance”].ToString();

float bakiye = float.Parse(gelen_bakiye);
string sorgu = “”;

if (bakiye > vttutar+1)
{

if (kurum.Equals(“1”))
{
sorgu = fatura.InvoicePayment(kullanici.Text, parola.Text,apikeyy, fatura_id, iski_tutar);
}
else
{
sorgu = fatura.InvoicePayment(kullanici.Text, parola.Text, apikeyy,fatura_id, “”);
}

JObject baslik = JObject.Parse(sorgu);
string ResultMessage = baslik[“ResultMessage”].ToString();
string ResultCode = baslik[“ResultCode”].ToString();

if (ResultCode == “1”)
{

sorgu = sorgu.Substring(sorgu.IndexOf(“[“), sorgu.IndexOf(“]”) – sorgu.IndexOf(“[“) + 1);
richTextBox1.Text = sorgu.ToString();

var objects = JArray.Parse(sorgu);

foreach (JObject root in objects)
{
string PaymentId = root[“PaymentId”].ToString();

String sql1 = “UPDATE foyfatura SET DURUM='” + PaymentId + “‘ where FATURA_ID='” + fatura_id + “‘ “;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();
}

}
else
{
String sql1 = “UPDATE foyfatura SET DURUM='” + ResultMessage + “‘ where FATURA_ID='” + fatura_id + “‘ “;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();

}

}
else
{

String sql1 = “UPDATE foyfatura SET DURUM=’Yetersiz Bakiye’ WHERE ID=” + txsorgu_id.Text + ” “;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();

}

System.Threading.Thread.Sleep(2000);

}

}

}

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
griddoldur();

string kurumlar = fatura.GetSootList(kullanici.Text, parola.Text,apikeyy);
kurumlar = kurumlar.Substring(kurumlar.IndexOf(“[“), kurumlar.IndexOf(“]”) – kurumlar.IndexOf(“[“) + 1);

richTextBox1.Text = kurumlar.ToString();

if (kurumlar.ToString().Length > 100)
{

var objects = JArray.Parse(kurumlar);

foreach (JObject root in objects)
{
string KurumNo = root[“SootCode”].ToString();
string KurumAd = root[“SootName”].ToString();

richTextBox1.Text += KurumNo + Environment.NewLine + KurumAd + Environment.NewLine;

}
}
else
{
}

System.Threading.Thread.Sleep(2000);
}

private void btnsorgula_Click(object sender, EventArgs e)
{

fatura_sorgula();

}

private void button2_Click(object sender, EventArgs e)
{

if (timer1.Enabled == true)
{

timer1.Enabled = false;
button2.Text = “Sorguya Başla”;

}

else
{

timer1.Enabled = true;
button2.Text = “Sorguyu Durdur”;

}
}

private void button3_Click(object sender, EventArgs e)
{

if (timer2.Enabled == true)
{

timer2.Enabled = false;
button3.Text = “Ödemeye Başla”;

}

else
{

timer2.Enabled = true;
button3.Text = “Ödemeyi Durdur”;

}
}

private void btnfaturaborcutahsil_Click(object sender, EventArgs e)
{
fatura_ode();

}

private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
fatura_sorgula();
timer1.Enabled = true;
}

private void timer2_Tick(object sender, EventArgs e)
{
timer2.Enabled = false;
fatura_ode();
timer2.Enabled = true;
}

private void timer3_Tick(object sender, EventArgs e)
{

}

private void btnbakiye_Click(object sender, EventArgs e)
{
string gelen_bakiye = “0”;

string sorgu1 = fatura.GetBalanceInformation(kullanici.Text, parola.Text, apikeyy);

JObject o = JObject.Parse(sorgu1);

gelen_bakiye = o[“Balance”].ToString();

richTextBox1.Text = gelen_bakiye;

}

private void button4_Click(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{

dosyaYolu = Application.StartupPath + “\\Settings.ini”;

StringBuilder sb = new StringBuilder(500);

GetPrivateProfileString(“VPN”, “IP”, “”, sb, sb.Capacity, dosyaYolu);
textBox1.Text = sb.ToString();

GetPrivateProfileString(“USER”, “kullanici”, “”, sb, sb.Capacity, dosyaYolu);
kullanici.Text = sb.ToString();
GetPrivateProfileString(“USER”, “parola”, “”, sb, sb.Capacity, dosyaYolu);
parola.Text = sb.ToString();
GetPrivateProfileString(“USER”, “apikey”, “”, sb, sb.Capacity, dosyaYolu);
apikeyy = sb.ToString();

}
}
}

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir