|
|
|
คือพิมพ์ไปแล้ว มันเกิด error ไม่รู้จะแก้ยังไง ช่วยแนะนำหน่อยค่ะ _/\_ |
|
|
|
|
|
|
|
เพิ่ม
Code (C#)
using System.Data.SqlClient;
ไว้บนสุดของหน้า code เลยครับ
|
|
|
|
|
Date :
2012-12-27 21:41:16 |
By :
Niratiam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พิมพ์ยุนะคะ แต่มันก้อ ขึ้น error
|
ประวัติการแก้ไข 2012-12-27 21:48:15
|
|
|
|
Date :
2012-12-27 21:45:18 |
By :
มือใหม่หัดเขียน ค่ะ^^ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วย copy หน้า code นี้มาให้ดูหน่อยครับ
|
|
|
|
|
Date :
2012-12-27 21:54:13 |
By :
Niratiam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace CAR_PARK
{
public partial class carout : Form
{
public System.Windows.Forms.Button printButton;
public Font printFont;
public StreamReader streamToPrint;
Form2 _f;
//string IDIn = "";
int auto_id = 0;
DateTime IN, OUT;
public carout(string data1, string data2, string data3, Form2 f)
{
InitializeComponent();
_f = f;
label2.Text = data1;
label5.Text = data2;
label6.Text = data3;
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
this.WindowState = FormWindowState.Maximized;
timer1.Start();
timer2.Start();
timer2.Interval = 60000;
label10.Text = DateTime.Now.ToString("yyyy/MM/dd");
string con = contocarpark.con;
SqlConnection cn = new SqlConnection(con);
cn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM DAILY_LOG_TYPEPAID WHERE ACTIVE = 1", cn);
da.Fill(ds, "combolist");
comboBox1.DataSource = ds;
comboBox1.DisplayMember = "combolist.TYPE_NAME";
comboBox1.ValueMember = "combolist.TYPE_ID";
cn.Close();
//cn.Open();
//DataSet ds2 = new DataSet();
//SqlDataAdapter da2 = new SqlDataAdapter("SELECT * FROM DAILY_LOG_ZONE", cn);
//da2.Fill(ds2, "combolist");
//comboBox2.DataSource = ds2;
//comboBox2.DisplayMember = "combolist.ZONE_NAME";
//comboBox2.ValueMember = "combolist.ZONE_ID";
// cn.Close();
Showdata();
tbCarOutId.Focus();
}
catch (Exception)
{
MessageBox.Show("เกิดข้อผิดพลาดติดต่อผู้ดูแลระบบด่วน!", "ฐานข้อมูลผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void timer2_Tick(object sender, EventArgs e)
{
timer2.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
label9.Text = DateTime.Now.ToString("HH:mm:ss");
}
private string RetrurnDate(string DateStr)
{
string DateXResult;
if (DateStr != "" | DateStr != null)
{
System.DateTime convertdate = DateTime.Parse(DateStr);
System.DateTime convertdateformat = DateTime.Parse(convertdate.ToString("yyyy/MM/dd HH:mm:ss", new System.Globalization.CultureInfo("en-US")));
DateXResult = convertdateformat.ToString();
return DateXResult;
}
else
{
DateXResult = "";
return DateXResult;
}
}
private void ComboBox1_Selectedvalue(object sender, EventArgs e)
{
try
{
string con = contocarpark.con;
SqlConnection cn = new SqlConnection(con);
cn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM DAILY_LOG_ZONE", cn);
da.Fill(ds, "combolist");
comboBox1.DataSource = ds;
comboBox1.DisplayMember = "combolist.ZONE_NAME";
comboBox1.ValueMember = "combolist.ZONE_ID";
cn.Close();
tbCarOutId.Focus();
}
catch (Exception)
{
MessageBox.Show("เกิดข้อผิดพลาดติดต่อผู้ดูแลระบบด่วน!", "ฐานข้อมูลผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void carZoneToolStripMenuItem_Click(object sender, EventArgs e)
{
zone f = new zone();
f.ShowDialog();
try
{
string con = contocarpark.con;
SqlConnection cn = new SqlConnection(con);
cn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM DAILY_LOG_TYPEPAID WHERE ACTIVE = 1", cn);
da.Fill(ds, "combolist");
comboBox1.DataSource = ds;
comboBox1.DisplayMember = "combolist.TYPE_NAME";
comboBox1.ValueMember = "combolist.TYPE_ID";
cn.Close();
//cn.Open();
//DataSet ds2 = new DataSet();
//SqlDataAdapter da2 = new SqlDataAdapter("SELECT * FROM DAILY_LOG_ZONE", cn);
//da2.Fill(ds2, "combolist");
//comboBox2.DataSource = ds2;
//comboBox2.DisplayMember = "combolist.ZONE_NAME";
//comboBox2.ValueMember = "combolist.ZONE_ID";
//cn.Close();
}
catch (Exception)
{
MessageBox.Show("เกิดข้อผิดพลาดติดต่อผู้ดูแลระบบด่วน!", "ฐานข้อมูลผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Showdata()
{
string con = contocarpark.con;
SqlConnection Conn = new SqlConnection(con);
String Sql = "SELECT QUEUE_NO,VEHICLE_CARNO,CONVERT(CHAR(8),TIME_IN, 114) AS REALTIMEIN FROM DAILY_LOG_PARK WHERE STATUS_CAR = '1' AND ZONE_ID = " + comboBox1.SelectedValue.GetHashCode() + "order by TIME_IN DESC";
SqlCommand cmd = new SqlCommand(Sql, Conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet data = new DataSet();
adapter.Fill(data, "showcar");
//dataGridView1.DataSource = data.Tables["showcar"];
//setdatagrid();
int countcar = data.Tables["showcar"].Rows.Count;
label7.Text = countcar.ToString();
Conn.Close();
Conn.Open();
String Sql2 = "SELECT QUEUE_NO,VEHICLE_CARNO,CONVERT(CHAR(8),TIME_IN, 114) AS REALTIMEIN FROM DAILY_LOG_PARK WHERE STATUS_CAR = '1'";
SqlCommand cmd2 = new SqlCommand(Sql2, Conn);
SqlDataAdapter adapter2 = new SqlDataAdapter(cmd2);
DataSet data2 = new DataSet();
adapter2.Fill(data2, "showallcar");
int countallcar = data2.Tables["showallcar"].Rows.Count;
label25.Text = countallcar.ToString();
Conn.Close();
label31.Text = comboBox1.Text;
Conn.Open();
String Sql4 = "SELECT ZONE_LIMIT FROM DAILY_LOG_ZONE WHERE ZONE_ID = " + comboBox1.SelectedValue.GetHashCode() + "";
SqlCommand cmd4 = new SqlCommand(Sql4, Conn);
SqlDataAdapter adapter4 = new SqlDataAdapter(cmd4);
DataSet data4 = new DataSet();
adapter4.Fill(data4, "showzonelimit");
int countlimit = data4.Tables["showzonelimit"].Rows.Count;
label12.Text = countlimit.ToString();
if (label12.Text == "0")
{
label12.Text = "0";
}
else if (label12.Text != "0")
{
label12.Text = data4.Tables["showzonelimit"].Rows[0]["ZONE_LIMIT"].ToString();
}
Conn.Close();
int limitzone = Convert.ToInt32(label12.Text);
int freecarzone = limitzone - countcar;
label35.Text = Convert.ToString(freecarzone);
Conn.Open();
String Sql5 = "SELECT SUM(ZONE_LIMIT) as allcarlimit FROM DAILY_LOG_ZONE";
SqlCommand cmd5 = new SqlCommand(Sql5, Conn);
SqlDataAdapter adapter5 = new SqlDataAdapter(cmd5);
DataSet data5 = new DataSet();
adapter5.Fill(data5, "sumzone");
int countsumlimit = data5.Tables["sumzone"].Rows.Count;
label33.Text = countsumlimit.ToString();
if (label33.Text == "0")
{
label33.Text = "0";
}
else if (label33.Text != "0")
{
label33.Text = data5.Tables["sumzone"].Rows[0]["allcarlimit"].ToString();
}
Conn.Close();
int limitall = Convert.ToInt32(label33.Text);
int freecarall = limitall - countallcar;
label36.Text = Convert.ToString(freecarall);
}
private void tbCarOutId_TextChanged(object sender, EventArgs e)
{
if (tbCarOutId.TextLength != 7)
{
label29.Text = "";
label30.Text = "";
label38.Text = "";
label40.Text = "";
label41.Text = "";
label42.Text = "";
label43.Text = "";
//label44.Text = "";
tbPaid.Clear();
textBox2.Clear();
textBox3.Clear();
SetControlsState(false);
return;
}
}
private void tbCarOutId_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar == 13)
{
try
{
SqlConnection _SqlConnection = new SqlConnection(contocarpark.con);
SqlCommand _SqlCommand = new SqlCommand();
SqlDataAdapter _SqlDataAdapter = new SqlDataAdapter();
using (_SqlCommand.Connection = _SqlConnection)
{
_SqlConnection.Open();
_SqlCommand.CommandText = "SELECT AUTO_ID FROM DAILY_LOG_PARK WHERE QUEUE_NO = '" + tbCarOutId.Text + "' AND ";
_SqlDataAdapter = _SqlCommand.ExecuteReader();
if (_SqlDataAdapter.Read())
{
auto_id = _SqlDataAdapter.GetHashCode();
SetControlsState(true);
}
else
{
SetControlsState(false);
MessageBox.Show("ไม่มีข้อมูลในระบบ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbCarOutId.Focus();
tbCarOutId.SelectAll();
return;
}
if (!_SqlDataAdapter.IsClosed)
{
_SqlDataAdapter.Close();
}
string OutTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
string InTime = "";
_SqlCommand.CommandText = "SELECT DAILY_LOG_PARK.TIME_IN";
_SqlCommand.CommandText = "DAILY_LOG_PARK WHERE DAILY_LOG_PAK.AUTO_ID = '" + auto_id + "'";
_SqlDataAdapter = _SqlCommand.ExecuteReader();
if (_SqlDataAdapter.Read())
{
InTime = _SqlDataAdapter["TIME_IN"].ToString();
}
else
{
return;
}
if (!_SqlDataAdapter.IsClosed)
{
_SqlDataAdapter.Close();
}
IN = Convert.ToDateTime(InTime);
IN = Convert.ToDateTime(IN.ToString("dd/MM/yyyy HH:mm:ss", new System.Globalization.CultureInfo("en-US")));
label29.Text = IN.ToString("dd/MM/yyyy HH:mm:ss");
label30.Text = OUT.ToString("dd/MM/yyyy HH:mm:ss");
TimeSpan DateDiff = OUT.Subtract(IN);
int hour, min;
hour = (DateDiff.Hours + (DateDiff.Days * 24));
min = DateDiff.Minutes;
label38.Text = hour.ToString();
label40.Text = min.ToString();
DataSet ds = (DataSet)comboBox1.DataSource;
string x = ds.Tables[0].Rows[comboBox1.SelectedIndex][5].ToString();
if (x == "0")
{
min = 0;
}
CallPrice((hour * 60) + 60);
}
}
catch (Exception ex)
{
MessageBox.Show("Message.ex");
}
finally
{
}
}
}
private void CallPrice(int mins)
{
if (mins <= 0)
{
label41.Text = "0.00";
tbPaid.Text = "0";
return;
}
try
{
SqlConnection _Sqlconnection = new SqlConnection(contocarpark.con);
SqlCommand _SqlCommand = new SqlCommand();
using (_SqlCommand.Connection = _Sqlconnection)
{
_Sqlconnection.Open();
_SqlCommand.CommandText = "SELECT FREE_HOUR, PRICE_PER_HOUR FROM DAILY_LOG_TYPEPAID WHERE TYPE_ID = @id ";
_SqlCommand.Parameters.AddWithValue("id", comboBox1.SelectedValue.ToString());
SqlDataAdapter _SqlDataAdapter = _SqlCommand.ExecuteReader();
if (_SqlDataAdapter.Read())
{
int FreeHrs = int.Parse(_SqlDataAdapter["FREE_HOUR"].ToString());
double PricePerHr = double.Parse(_SqlDataAdapter["PRICE_PER_HOUR"].ToString());
double PricePerMin = PricePerHr / 60;
double TotalPrice = (mins - (FreeHrs * 60)) * PricePerMin;
label41.Text = TotalPrice <= 0 ? "FREE" : TotalPrice.ToString("0");
if (label41.Text == "FREE")
{
tbPaid.Text = "0";
}
tbPaid.Focus();
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
private void SetControlsState(bool p)
{
comboBox1.Enabled = p;
tbPaid.ReadOnly = !p;
}
private void tbPaid_TextChanged(object sender, EventArgs e)
{
CallChange();
}
private void CallChange()
{
if (tbPaid.TextLength == 0)
{
label43.Text = "";
return;
}
double x = 0;
if (double.TryParse(tbPaid.Text, out x) == true)
{
int hrs = 0, mins = 0;
if (int.TryParse(label38.Text, out hrs))
{
}
if (int.TryParse(label40.Text, out mins))
{
}
if (((hrs * 60) + mins) <= 0)
{
return;
}
CallPrice((hrs * 60) + 60);
double paid = 0, price = 0;
if (double.TryParse(label41.Text, out price))
{
}
if (double.TryParse(tbPaid.Text, out paid))
{
}
double result = paid - price;
label43.Text = Convert.ToString(result);
}
else
{
tbPaid.Text = tbPaid.Text.Substring(0, tbPaid.TextLength -1);
tbPaid.SelectionStart = tbPaid.TextLength;
}
}
private void label43_TextChanged(object sender, EventArgs e)
{
try
{
string text1 = label43.Text;
if (text1.Length > 6 && text1.Length < 8)
{
comboBox1.Focus();
tbPaid.Text = "";
label43.Text = "";
}
else
{
}
}
catch (Exception)
{
MessageBox.Show("เกิดข้อผิดพลาดติดต่อผู้ดูแลระบบด่วน!", " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void paidTypeToolStripMenuItem_Click(object sender, EventArgs e)
{
Paidtype f = new Paidtype();
f.ShowDialog();
try
{
string con = contocarpark.con;
SqlConnection cn = new SqlConnection(con);
cn.Open();
DataSet ds1 = new DataSet();
SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM DAILY_LOG_TYPEPAID", cn);
da1.Fill(ds1, "combolist");
comboBox1.DataSource = ds1;
comboBox1.DisplayMember = "combolist.TYPE_NAME";
comboBox1.ValueMember = "combolist.TYPE_ID";
cn.Close();
}
catch (Exception)
{
MessageBox.Show("เกิดข้อผิดพลาดติดต่อผู้ดูแลระบบด่วน!", "ฐานข้อมูลผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int hrs = 0, mins = 0;
if (int.TryParse(label38.Text, out hrs))
{
}
if (int.TryParse(label40.Text, out mins))
{
}
DataSet ds = (DataSet)comboBox1.DataSource;
string s = ds.Tables[0].Rows[comboBox1.SelectedIndex][4].ToString(), x = ds.Tables[0].Rows[comboBox1.SelectedIndex][5].ToString();
if (x == "0")
{
mins = 0;
}
CallPrice((hrs * 60) + mins);
CallChange();
label46.Text = ds.Tables[0].Rows[comboBox1.SelectedIndex][2].ToString();
label47.Text = ds.Tables[0].Rows[comboBox1.SelectedIndex][3].ToString();
label49.Text = ds.Tables[0].Rows[comboBox1.SelectedIndex][4].ToString();
}
}
}
|
|
|
|
|
Date :
2012-12-27 21:59:29 |
By :
มือใหม่หัดเขียน ค่ะ^^ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตัวที่มัน error ค่ะ
Code (C#)
private void tbCarOutId_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar == 13)
{
try
{
SqlConnection _SqlConnection = new SqlConnection(contocarpark.con);
SqlCommand _SqlCommand = new SqlCommand();
SqlDataAdapter _SqlDataAdapter = new SqlDataAdapter();
using (_SqlCommand.Connection = _SqlConnection)
{
_SqlConnection.Open();
_SqlCommand.CommandText = "SELECT AUTO_ID FROM DAILY_LOG_PARK WHERE QUEUE_NO = '" + tbCarOutId.Text + "' AND ";
_SqlDataAdapter = _SqlCommand.ExecuteReader();
if (_SqlDataAdapter.Read())
{
auto_id = _SqlDataAdapter.GetHashCode();
SetControlsState(true);
}
else
{
SetControlsState(false);
MessageBox.Show("ไม่มีข้อมูลในระบบ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbCarOutId.Focus();
tbCarOutId.SelectAll();
return;
}
if (!_SqlDataAdapter.IsClosed)
{
_SqlDataAdapter.Close();
}
string OutTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
string InTime = "";
_SqlCommand.CommandText = "SELECT DAILY_LOG_PARK.TIME_IN";
_SqlCommand.CommandText = "DAILY_LOG_PARK WHERE DAILY_LOG_PAK.AUTO_ID = '" + auto_id + "'";
_SqlDataAdapter = _SqlCommand.ExecuteReader();
if (_SqlDataAdapter.Read())
{
InTime = _SqlDataAdapter["TIME_IN"].ToString();
}
else
{
return;
}
if (!_SqlDataAdapter.IsClosed)
{
_SqlDataAdapter.Close();
}
IN = Convert.ToDateTime(InTime);
IN = Convert.ToDateTime(IN.ToString("dd/MM/yyyy HH:mm:ss", new System.Globalization.CultureInfo("en-US")));
label29.Text = IN.ToString("dd/MM/yyyy HH:mm:ss");
label30.Text = OUT.ToString("dd/MM/yyyy HH:mm:ss");
TimeSpan DateDiff = OUT.Subtract(IN);
int hour, min;
hour = (DateDiff.Hours + (DateDiff.Days * 24));
min = DateDiff.Minutes;
label38.Text = hour.ToString();
label40.Text = min.ToString();
DataSet ds = (DataSet)comboBox1.DataSource;
string x = ds.Tables[0].Rows[comboBox1.SelectedIndex][5].ToString();
if (x == "0")
{
min = 0;
}
CallPrice((hour * 60) + 60);
}
}
catch (Exception ex)
{
MessageBox.Show("Message.ex");
}
finally
{
}
}
}
|
ประวัติการแก้ไข 2012-12-27 22:01:57
|
|
|
|
Date :
2012-12-27 22:01:22 |
By :
มือใหม่หัดเขียน ค่ะ^^ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองเปลี่ยน
SqlDataAdapter เป็น SqlDataReader ดูครับว่าได้ไหมครับ
|
|
|
|
|
Date :
2012-12-27 22:36:02 |
By :
Niratiam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วค่ะ
ขอบคุณ @Niratiam มั่กมากค่ะ
|
|
|
|
|
Date :
2012-12-27 22:56:02 |
By :
มือใหม่หัดเขียน ค่ะ^^ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ไม่ให้มัน error ได้แล้ว แต่เกิดปัญหามาอีกว่า
ข้อมูลคีย์ไปที่ textbox แล้ว ข้อมูลดึงจาก sql มันไม่แสดง ที่ label
แย่จัง ช่วยเช็คดูให้อีกหน่อยค่ะ
|
|
|
|
|
Date :
2012-12-28 15:48:57 |
By :
มือใหม่หัดเขียน ค่ะ^^ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอดู code ที่แก้แล้วหน่อยครับ แล้วก็ code จังหวะที่ต้องการดึง sql มาแสดงบน label ครับ
|
|
|
|
|
Date :
2012-12-28 16:02:17 |
By :
Niratiam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
_SqlCommand.CommandText = "SELECT DAILY_LOG_PARK.TIME_IN from";
_SqlCommand.CommandText = "DAILY_LOG_PARK WHERE DAILY_LOG_PAK.AUTO_ID = '" + auto_id + "'";
อันนี้ผมเดานะครับ ลืมคำว่า from หรือป่าวครับ
|
|
|
|
|
Date :
2012-12-28 16:11:58 |
By :
Niratiam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลืมจริงๆ ค่ะ
แต่ก้อเอา from เพิ่มเข้าไปแล้วค่ะ แต่ก้อยังไม่ได้
|
|
|
|
|
Date :
2012-12-28 16:19:12 |
By :
kainoi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ต้องลอง debug ดูข้อมูลแต่ละขั้นแล้วละครับ
ส่วนพวก textbox ผมแนะนำให้ใส่ .Trim() ไว้ด้วยครับ
เผื่อมีช่องว่างเวลานำไปใช้ where ครับ
ยังไงลองดูนะครับ สู้ๆ ครับ
|
|
|
|
|
Date :
2012-12-28 16:27:50 |
By :
Niratiam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณค่ะ
จะลองดูค่ะ ^
|
|
|
|
|
Date :
2012-12-28 16:31:17 |
By :
kainoi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วค่ะ
ต้องเพิ่ม [0] ที่บรรทัด auto_id = Reader[0].GetHashCode(); ค่ะ
แต่ก้อขอบคุณ คุณ Niratiam นะคะ ^ ^
|
|
|
|
|
Date :
2012-12-28 16:43:21 |
By :
kainoi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|