C# Get Field From Database
MySqlConnection buatKon = new MySqlConnection(kon);
buatKon.Open();
DataTable dt = new DataTable();
MySqlDataAdapter sda = new MySqlDataAdapter("select * from `parkir` where Nomor_Polisi like '%" + nopol + "%' order by `id` desc", buatKon);
sda.Fill(dt);
DataSet ds = new DataSet();
sda.Fill(ds);
int row= ds.Tables[0].Rows.Count;
if (row>0){
status="Out";
cs= dt.Rows[0]["Status"].ToString();
if (cs.Equals("In")) {//jika didatabase terdaftarnya IN=artinya dia mau keluar
status = "Out";
jk = dt.Rows[0]["Image"].ToString();
rfid= dt.Rows[0]["rfid"].ToString();
String Jam_Masuk = dt.Rows[0]["Jam_Masuk"].ToString();
String jam = DateTime.Now.ToString("HH:mm:ss");// tt
string[] ar= Jam_Masuk.Split(':');
String tg= DateTime.Now.ToString("dd");
String bl = DateTime.Now.ToString("MM");
String th = DateTime.Now.ToString("yyyy");
String ja = DateTime.Now.ToString("HH");
String me = DateTime.Now.ToString("mm");
String de = DateTime.Now.ToString("ss");
DateTime awal = new DateTime(Int32.Parse(th), Int32.Parse(bl), Int32.Parse(tg), Int32.Parse(ar[0]), Int32.Parse(ar[1]), Int32.Parse(ar[2]));
DateTime akhir = new DateTime(Int32.Parse(th), Int32.Parse(bl), Int32.Parse(tg), Int32.Parse(ja), Int32.Parse(me), Int32.Parse(de));
TimeSpan span = akhir.Subtract(awal);
double d1 = span.TotalSeconds;
Console.WriteLine("awal : " + awal.ToString("dd/MM/yyyy HH:mm:ss"));
Console.WriteLine("akhir : " + akhir.ToString("dd/MM/yyyy HH:mm:ss"));
Console.WriteLine("selisih hari: " + span.TotalDays);
Console.WriteLine("selisih jam: " + span.TotalHours);
Console.WriteLine("selisih menit: " + span.TotalMinutes);
Console.WriteLine("selisih detik : " + span.TotalSeconds);
String dur = span.TotalDays + "," + span.TotalHours + " jam " + span.TotalMinutes + " menit " + span.TotalSeconds + " detik";
double lama = span.TotalHours+ 1;
txtmasuk.Text = Jam_Masuk;
txtkeluar.Text = jam;
double biaya = lama * 2000;
txttarif.Text = biaya.ToString();
txtketerangan.Text = status+" Durasi :"+lama +" jam, "+dur;
txtjenis.Text = jk;
txtRFID.Text = rfid;
String path = System.IO.Directory.GetCurrentDirectory();
try
{
imgCapture.SizeMode = PictureBoxSizeMode.StretchImage;
imgCapture.Load(path + "//" + jk);
Application.DoEvents();
imgCapture.WaitOnLoad = true;
System.Threading.Thread.Sleep(100);
}
catch (Exception ex)
{ }
}
else if (cs.Equals("Out")) {
//jika datanya sudah ada tapi mau masuk lagi
imgCapture.Image = imgVideo.Image;
status = "In";
jk = dt.Rows[0]["Image"].ToString();
rfid= dt.Rows[0]["rfid"].ToString();
String jam = DateTime.Now.ToString("HH:mm:ss");// tt
txtmasuk.Text = jam;
txtkeluar.Text = "23:59:59";
txttarif.Text = "0";
txtketerangan.Text = status;
txtRFID.Text = rfid;
String nf = "IMG" + DateTime.UtcNow.ToString("yyyyMMddTHHmmssfffffffZ") + ".jpg";
txtjenis.Text = nf;
}
//update
}
else{
//jika datanya belumada dan mau masuk (Orang baru)
imgCapture.Image = imgVideo.Image;
String jam = DateTime.Now.ToString("HH:mm:ss");// tt
txtmasuk.Text = jam;
txtkeluar.Text = "23:59:59";
txttarif.Text = "0";
status="In";
txtRFID.Focus();
txtketerangan.Text = status;
String nf = "IMG" + DateTime.UtcNow.ToString("yyyyMMddTHHmmssfffffffZ") + ".jpg";
txtjenis.Text = nf;
//insert
}
buatKon.Close();
}//>5
buatKon.Open();
DataTable dt = new DataTable();
MySqlDataAdapter sda = new MySqlDataAdapter("select * from `parkir` where Nomor_Polisi like '%" + nopol + "%' order by `id` desc", buatKon);
sda.Fill(dt);
DataSet ds = new DataSet();
sda.Fill(ds);
int row= ds.Tables[0].Rows.Count;
if (row>0){
status="Out";
cs= dt.Rows[0]["Status"].ToString();
if (cs.Equals("In")) {//jika didatabase terdaftarnya IN=artinya dia mau keluar
status = "Out";
jk = dt.Rows[0]["Image"].ToString();
rfid= dt.Rows[0]["rfid"].ToString();
String Jam_Masuk = dt.Rows[0]["Jam_Masuk"].ToString();
String jam = DateTime.Now.ToString("HH:mm:ss");// tt
string[] ar= Jam_Masuk.Split(':');
String tg= DateTime.Now.ToString("dd");
String bl = DateTime.Now.ToString("MM");
String th = DateTime.Now.ToString("yyyy");
String ja = DateTime.Now.ToString("HH");
String me = DateTime.Now.ToString("mm");
String de = DateTime.Now.ToString("ss");
DateTime awal = new DateTime(Int32.Parse(th), Int32.Parse(bl), Int32.Parse(tg), Int32.Parse(ar[0]), Int32.Parse(ar[1]), Int32.Parse(ar[2]));
DateTime akhir = new DateTime(Int32.Parse(th), Int32.Parse(bl), Int32.Parse(tg), Int32.Parse(ja), Int32.Parse(me), Int32.Parse(de));
TimeSpan span = akhir.Subtract(awal);
double d1 = span.TotalSeconds;
Console.WriteLine("awal : " + awal.ToString("dd/MM/yyyy HH:mm:ss"));
Console.WriteLine("akhir : " + akhir.ToString("dd/MM/yyyy HH:mm:ss"));
Console.WriteLine("selisih hari: " + span.TotalDays);
Console.WriteLine("selisih jam: " + span.TotalHours);
Console.WriteLine("selisih menit: " + span.TotalMinutes);
Console.WriteLine("selisih detik : " + span.TotalSeconds);
String dur = span.TotalDays + "," + span.TotalHours + " jam " + span.TotalMinutes + " menit " + span.TotalSeconds + " detik";
double lama = span.TotalHours+ 1;
txtmasuk.Text = Jam_Masuk;
txtkeluar.Text = jam;
double biaya = lama * 2000;
txttarif.Text = biaya.ToString();
txtketerangan.Text = status+" Durasi :"+lama +" jam, "+dur;
txtjenis.Text = jk;
txtRFID.Text = rfid;
String path = System.IO.Directory.GetCurrentDirectory();
try
{
imgCapture.SizeMode = PictureBoxSizeMode.StretchImage;
imgCapture.Load(path + "//" + jk);
Application.DoEvents();
imgCapture.WaitOnLoad = true;
System.Threading.Thread.Sleep(100);
}
catch (Exception ex)
{ }
}
else if (cs.Equals("Out")) {
//jika datanya sudah ada tapi mau masuk lagi
imgCapture.Image = imgVideo.Image;
status = "In";
jk = dt.Rows[0]["Image"].ToString();
rfid= dt.Rows[0]["rfid"].ToString();
String jam = DateTime.Now.ToString("HH:mm:ss");// tt
txtmasuk.Text = jam;
txtkeluar.Text = "23:59:59";
txttarif.Text = "0";
txtketerangan.Text = status;
txtRFID.Text = rfid;
String nf = "IMG" + DateTime.UtcNow.ToString("yyyyMMddTHHmmssfffffffZ") + ".jpg";
txtjenis.Text = nf;
}
//update
}
else{
//jika datanya belumada dan mau masuk (Orang baru)
imgCapture.Image = imgVideo.Image;
String jam = DateTime.Now.ToString("HH:mm:ss");// tt
txtmasuk.Text = jam;
txtkeluar.Text = "23:59:59";
txttarif.Text = "0";
status="In";
txtRFID.Focus();
txtketerangan.Text = status;
String nf = "IMG" + DateTime.UtcNow.ToString("yyyyMMddTHHmmssfffffffZ") + ".jpg";
txtjenis.Text = nf;
//insert
}
buatKon.Close();
}//>5
Posting Komentar untuk "C# Get Field From Database"