Föy Fatura Bakiye Kontrol Webservis c# 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.Runtime.InteropServices;
using Newtonsoft.Json.Linq;
using System.Data.OleDb;

namespace FoyBakiye
{
public partial class Form1 : Form
{
foyfatura.FoyOnlineApiGateWS fatura = new foyfatura.FoyOnlineApiGateWS();

string dosyaYolu, bankax, tutarx, istektarihi, aciklamax, apikey, tarihx, saatx, status,totalX;

[DllImport(“kernel32.dll”)]

static extern uint GetPrivateProfileString(
string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
string sunucu = “”, database = “”, username = “”, password = “”;

OleDbConnection con,con1;
OleDbDataAdapter da,da1;
OleDbCommand cmd,cmd1;
DataSet ds,ds1;

public Form1()
{
InitializeComponent();
}

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(“VPN”, “HOST”, “”, sb, sb.Capacity, dosyaYolu);
sunucu = 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);
apikey = sb.ToString();
api.Text = apikey;

con = new OleDbConnection(“Provider=Microsoft.ACE.Oledb.12.0;Data Source=bakiye.mdb”);
}

private void kullanici_TextChanged(object sender, EventArgs e)
{

}

private void label8_Click(object sender, EventArgs e)
{

}

private void label9_Click(object sender, EventArgs e)
{

}

private void Hesapno_TextChanged(object sender, EventArgs e)
{

}

private void subekodu_TextChanged(object sender, EventArgs e)
{

}

private void label6_Click(object sender, EventArgs e)
{

}

private void label5_Click(object sender, EventArgs e)
{

}

private void label4_Click(object sender, EventArgs e)
{

}

private void label3_Click(object sender, EventArgs e)
{

}

private void bayi_TextChanged(object sender, EventArgs e)
{

}

private void garantor_TextChanged(object sender, EventArgs e)
{

}

private void parola_TextChanged(object sender, EventArgs e)
{

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

con.Open();
String sql2 = “DELETE FROM bakiye”;
OleDbCommand kmt2 = new OleDbCommand(sql2, con);
kmt2.ExecuteNonQuery();
con.Close();

try
{
float toplam=0;

da = new OleDbDataAdapter(“Select * from bakiye”, con);
ds = new DataSet();
con.Open();
da.Fill(ds, “bakiye”);
dataGridView1.DataSource = ds.Tables[“bakiye”];
con.Close();

tarihx = dateTimePicker1.Text.Substring(6, 4) + “-” + dateTimePicker1.Text.Substring(3, 2) + “-” + dateTimePicker1.Text.Substring(0, 2);

string bakiye = fatura.GetAddedBalanceList(kullanici.Text, parola.Text, apikey, tarihx);

bakiye = bakiye.Substring(bakiye.IndexOf(“[“), bakiye.IndexOf(“]”) – bakiye.IndexOf(“[“) + 1);

var objects = JArray.Parse(bakiye);

foreach (JObject root in objects)
{

bankax = root[“Bank”].ToString();
tutarx = root[“Amount”].ToString();
istektarihi = root[“Date”].ToString();

istektarihi = String.Format(“{0:dd.MM.yyyy}”, Convert.ToDateTime(istektarihi));

aciklamax = root[“Description”].ToString();

aciklamax = aciklamax.Replace(“‘”, “”);
saatx = root[“Time”].ToString();
status = root[“Status”].ToString();
totalX = root[“TotalBalance”].ToString();

if (status == “-1”) { status = “2”; }

//listBox1.Items.Add(bankax+””+tutarx+” – “+istektarihi+”- “+saatx+” – “+aciklamax);

// dataGridView1.Rows.Add(new object[] { bankax, tutarx, istektarihi,saatx, aciklamax });

con.Open();
String sql1 = “INSERT INTO bakiye (BANKA,TUTAR,TARIH,SAAT,ACIKLAMA,DURUM,TOTAL) VALUES (‘” + bankax + “‘,'” + tutarx + “‘,'” + istektarihi + “‘,'” + saatx + “‘,'” + aciklamax + “‘,'” + status + “‘,'” + totalX + “‘) “;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();
con.Close();

toplam = toplam + float.Parse(tutarx);

}

con.Close();
da = new OleDbDataAdapter(“Select * from bakiye”, con);
ds = new DataSet();
con.Open();
da.Fill(ds, “bakiye”);
dataGridView1.DataSource = ds.Tables[“bakiye”];
con.Close();

comboBox1.Items.Clear();

String sql = “Select BANKA from bakiye GROUP BY BANKA “;

OleDbCommand komut = new OleDbCommand(sql, con);
con.Open();

OleDbDataReader oku = komut.ExecuteReader();
while (oku.Read())
{
comboBox1.Items.Add(oku[“BANKA”].ToString());
}
con.Close();

sql = “Select sum(TUTAR) as TOPLAM,count(TUTAR) as ADET from bakiye “;

komut = new OleDbCommand(sql, con);
con.Open();

oku = komut.ExecuteReader();
while (oku.Read())
{
txtoplam.Text = oku[“TOPLAM”].ToString();
txsayi.Text = oku[“ADET”].ToString();

}
con.Close();

}
catch { }

}

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

}

private void button2_Click_1(object sender, EventArgs e)
{

ExportToExcel();

}

private void ExportToExcel()
{
// Creating a Excel object.
Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook workbook = excel.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

try
{

worksheet = workbook.ActiveSheet;

worksheet.Name = “ExportedFromDatGrid”;

int cellRowIndex = 1;
int cellColumnIndex = 1;

//Loop through each row and read value from each column.
for (int i = -1; i < dataGridView1.Rows.Count – 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
// Excel index starts from 1,1. As first Row would have the Column headers, adding a condition check.
if (cellRowIndex == 1)
{
worksheet.Cells[cellRowIndex, cellColumnIndex] = dataGridView1.Columns[j].HeaderText;
}
else
{
worksheet.Cells[cellRowIndex, cellColumnIndex] = dataGridView1.Rows[i].Cells[j].Value.ToString();
}
cellColumnIndex++;
}
cellColumnIndex = 1;
cellRowIndex++;
}

//Getting the location and file name of the excel to save from user.
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.Filter = “Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*”;
saveDialog.FilterIndex = 2;

if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
workbook.SaveAs(saveDialog.FileName);
MessageBox.Show(“Export Successful”);
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
excel.Quit();
workbook = null;
excel = null;
}

}

private void button3_Click(object sender, EventArgs e)
{

}

private void button3_Click_1(object sender, EventArgs e)
{
DialogResult cevap;

cevap = MessageBox.Show(“Tüm Kayıtlar Silinecek”, “Uyarı”, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (cevap == DialogResult.Yes)
{
try
{
con.Open();
String sql1 = “DELETE FROM bakiye”;
OleDbCommand kmt1 = new OleDbCommand(sql1, con);
kmt1.ExecuteNonQuery();
con.Close();

da = new OleDbDataAdapter(“Select * from bakiye”, con);
ds = new DataSet();
con.Open();
da.Fill(ds, “bakiye”);
dataGridView1.DataSource = ds.Tables[“bakiye”];
con.Close();
}
catch (System.Exception ex)
{
// MessageBox.Show(ex.Message);
}
}

}

private void button4_Click(object sender, EventArgs e)
{
String sql = “Select * from bakiye where (1=1)”;
if (comboBox1.Text != “”) { sql = sql + ” AND BANKA like ‘%” + comboBox1.Text + “%’ “; }
if (textBox2.Text != “”) { sql = sql + ” AND ACIKLAMA like ‘%” + textBox2.Text + “%’ “; }
if (checkBox1.Checked == true) { sql = sql + ” and TARIH between ‘”+dateTimePicker2.Text+”‘ and ‘”+dateTimePicker3.Text+”‘ “; }
if (checkBox2.Checked == true) { sql = sql + ” and SAAT between ‘” + dateTimePicker4.Text + “‘ and ‘” + dateTimePicker5.Text + “‘ “; }
if (cxdurum.Text == “Aktif Bakiye”) { sql = sql + ” AND DURUM=1 “; }
if (cxdurum.Text == “İptal Bakiye”) { sql = sql + ” AND DURUM=2 “; }
if (cxdurum.Text == “Bekleyen Bakiye”) { sql = sql + ” AND DURUM=0 “; }
if (cxdiger.Checked == true) { sql = sql + ” AND BANKA <> ‘DİĞER’ “; }
if (cxparafix.Checked == true) { sql = sql + ” AND BANKA <> ‘PARAFIX’ “; }

da = new OleDbDataAdapter(sql, con);
ds = new DataSet();
con.Open();
da.Fill(ds, “bakiye”);
dataGridView1.DataSource = ds.Tables[“bakiye”];
con.Close();

String sorgu = “Select sum(TUTAR) AS TOPLAM , count(TUTAR) as ADET from bakiye WHERE (1=1) “;

if (comboBox1.Text != “”) { sorgu = sorgu + ” AND BANKA like ‘%” + comboBox1.Text + “%’ “; }
if (textBox2.Text != “”) { sorgu = sorgu + ” AND ACIKLAMA like ‘%” + textBox2.Text + “%’ “; }
if (checkBox1.Checked == true) { sorgu = sorgu + ” and TARIH between ‘” + dateTimePicker2.Text + “‘ and ‘” + dateTimePicker3.Text + “‘ “; }
if (checkBox2.Checked == true) { sorgu = sorgu + ” and SAAT between ‘” + dateTimePicker4.Text + “‘ and ‘” + dateTimePicker5.Text + “‘ “; }
if (cxdurum.Text == “Aktif Bakiye”) { sorgu = sorgu + ” AND DURUM=1 “; }
if (cxdurum.Text == “İptal Bakiye”) { sorgu = sorgu + ” AND DURUM=2 “; }
if (cxdurum.Text == “Bekleyen Bakiye”) { sorgu = sorgu + ” AND DURUM=0 “; }
if (cxdiger.Checked == true) { sorgu = sorgu + ” AND BANKA <> ‘DİĞER’ “; }
if (cxparafix.Checked == true) { sorgu = sorgu + ” AND BANKA <> ‘PARAFIX’ “; }

OleDbCommand komut = new OleDbCommand(sorgu, con);
con.Open();

txtoplam.Text = “0”;
txsayi.Text = “0”;

OleDbDataReader oku = komut.ExecuteReader();
while (oku.Read())
{
txtoplam.Text = oku[“TOPLAM”].ToString();
txsayi.Text = oku[“ADET”].ToString();
}
con.Close();

}

private void button5_Click(object sender, EventArgs e)
{
checkBox1.Checked = false;
checkBox2.Checked = false;
comboBox1.Text = “”;
textBox2.Text = “”;
button4.PerformClick();

}

private void label2_Click(object sender, EventArgs e)
{

}

private void txtoplam_TextChanged(object sender, EventArgs e)
{

}

}
}

Bir cevap yazın

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