private void Btnxacnhan_Click(object sender, EventArgs e) { try { conn = DBUtils.GetDBConnection(); conn.Open(); DateTime aDateTime = DateTime.Now; txtngaydkmoi.Text = aDateTime.ToString(); if (conn != null && stcomport.Equals(0) && !txtmathemoi.Text.Equals("")) { string updateQuery = "UPDATE dvesdkvethang SET ngaydangky = '" + txtngaydkmoi.Text + "', tagid = '" + txtmathemoi.Text + "' WHERE ten = '" + txtten.Text + "' "; MySqlCommand cmdupdate = new MySqlCommand(updateQuery, conn); cmdupdate.CommandText = updateQuery; cmdupdate.Connection = conn; cmdupdate.ExecuteNonQuery(); MessageBox.Show("Đổi thẻ thành công!"); conn.Close(); conn.Dispose(); this.Hide(); giaodienchinh to_giaodienchinh = new giaodienchinh(); to_giaodienchinh.ShowDialog(); this.Close(); } else { MessageBox.Show("Có lỗi, kiểm tra kết nối USB/Server !"); } } catch (MySqlException ex) { MessageBox.Show("Có lỗi kết nối xãy ra"); } }
private void BtnquaylaiADM_Click(object sender, EventArgs e) { this.Hide(); giaodienchinh to_gdchinh = new giaodienchinh(); to_gdchinh.ShowDialog(); this.Close(); }
private void Button1_Click(object sender, EventArgs e) { this.Hide(); giaodienchinh to_giaodienchinh = new giaodienchinh(); to_giaodienchinh.ShowDialog(); this.Close(); }
private void BtnDN_Click(object sender, EventArgs e) { try { conn = DBUtils.GetDBConnection(); conn.Open(); if (flag.Equals(1)) { string query1 = "UPDATE dveslogin SET ghinho= '1' WHERE id = 0"; MySqlCommand cm1 = new MySqlCommand(query1, conn); cm1.CommandText = query1; //Assign the connection using Connection cm1.Connection = conn; //Execute query cm1.ExecuteNonQuery(); //MessageBox.Show("check"); } else { string query2 = "UPDATE dveslogin SET ghinho= '0' WHERE id = 0"; MySqlCommand cm2 = new MySqlCommand(query2, conn); cm2.CommandText = query2; //Assign the connection using Connection cm2.Connection = conn; //Execute query cm2.ExecuteNonQuery(); // MessageBox.Show("uncheck"); } if (txtDN.Text.Equals(tendn) && txtMK.Text.Equals(mk)) { this.Hide(); giaodienchinh to_gdchinh = new giaodienchinh(); to_gdchinh.ShowDialog(); this.Close(); } else { MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu !"); } } catch (Exception) { MessageBox.Show("Error"); } finally { if (conn != null) { conn.Close(); conn.Dispose(); } } }
private void Btnxacnhan_Click(object sender, EventArgs e) { try { conn = DBUtils.GetDBConnection(); conn.Open(); if (conn != null) { DialogResult dialogResult = MessageBox.Show("Xóa dữ liệu ?", "Xác nhận xóa người dùng", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { string Query = "DELETE FROM dvesdkvethang WHERE ten='" + txtten.Text + "';"; MySqlCommand cmdzs = new MySqlCommand(Query, conn); cmdzs.CommandText = Query; cmdzs.Connection = conn; cmdzs.ExecuteNonQuery(); } else if (dialogResult == DialogResult.No) { //do something else } } else { MessageBox.Show("Không có kết nối đến Server !"); } } catch (MySqlException ex) { conn.Close(); conn.Dispose(); MessageBox.Show("Lỗi kết nối đến server !"); } finally { if (conn != null) { conn.Close(); conn.Dispose(); this.Hide(); giaodienchinh to_giaodienchinh = new giaodienchinh(); to_giaodienchinh.ShowDialog(); this.Close(); } } }
private void Btnxacnhan_Click(object sender, EventArgs e) { // đọc tagid từ reader try { if (stcomport.Equals(1)) { DateTime aDateTime = DateTime.Now; //thangdk = aDateTime.ToString("MM"); //namdk = aDateTime.ToString("yyyy"); //thanghh = Int32.Parse(thangdk); //ngaydangky = aDateTime.ToString(); //ngayhethan = ngaydangky; txtngaydangky.Text = aDateTime.ToString("dd/M/yyyy hh:mm tt"); //MessageBox.Show(txtngaydangky.Text); txtngayhethan.Text = aDateTime.AddMonths(1).ToString("dd/M/yyyy hh:mm tt"); conn = DBUtils.GetDBConnection(); conn.Open(); if (!txttagid.Text.Equals("") && !txthoten.Text.Equals("") && !txtdiachi.Text.Equals("") && !txtbienso.Text.Equals("") && !txttien.Text.Equals("") && !txtngaydangky.Text.Equals("") && !txtngayhethan.Text.Equals("")) { string[] thang = txtngaydangky.Text.Split('/'); var comm = conn.CreateCommand(); comm.CommandText = "INSERT INTO dvesdkvethang(ten, tagid, bienso, loaixe, ngaydangky, ngayhethan, tien, thang) VALUES(@ten, @id, @bx, @xe, @start, @stop, @tien,@thang)"; comm.Parameters.AddWithValue("@ten", txthoten.Text); comm.Parameters.AddWithValue("@id", txttagid.Text); comm.Parameters.AddWithValue("@bx", txtbienso.Text); comm.Parameters.AddWithValue("@xe", chonxe); comm.Parameters.AddWithValue("@start", txtngaydangky.Text); comm.Parameters.AddWithValue("@stop", txtngayhethan.Text); comm.Parameters.AddWithValue("@tien", txttien.Text); comm.Parameters.AddWithValue("@thang", thang[1]); comm.ExecuteNonQuery(); DialogResult dialogResult = MessageBox.Show("Đã đồng ý với thông tin người dùng ?", "Đăng ký người dùng mới", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); conn.Dispose(); } this.Hide(); giaodienchinh to_giaodienchinh = new giaodienchinh(); to_giaodienchinh.ShowDialog(); this.Close(); } else if (dialogResult == DialogResult.No) { //do something else } } else { MessageBox.Show("Đăng ký không thành công, điền đầy đủ thông tin !"); } } else { MessageBox.Show("Vui lòng kết nối đến USB COM"); } } catch (MySqlException) { conn.Close(); conn.Dispose(); MessageBox.Show("Đăng ký không thành công, lỗi kết nối đến server !"); } }
private void Btngiahan_Click(object sender, EventArgs e) { try { conn = DBUtils.GetDBConnection(); conn.Open(); if (conn != null && !txttagid.Text.Equals("")) { string getdata = "SELECT * FROM dvesdkvethang"; MySqlCommand cmdzs = new MySqlCommand(getdata, conn); rdr = cmdzs.ExecuteReader(); while (rdr.Read()) { if (txttagid.Text.Equals(rdr.GetString("tagid"))) { txtten.Text = rdr.GetString("ten"); txtbienso.Text = rdr.GetString("bienso"); stttagid = 1; rdr.Close(); break; } } rdr.Close(); DateTime aDateTime = DateTime.Now; txtngaygiahan.Text = aDateTime.ToString(); txtngayghtieptheo.Text = aDateTime.AddMonths(1).ToString(); if (conn != null && stttagid == 1) { if (txttien.Text.Equals("")) { MessageBox.Show("Vui lòng nhập số tiền đã thu!"); } else { string updateQuery = "UPDATE dvesdkvethang SET ngaydangky = '" + txtngaygiahan.Text + "', ngayhethan = '" + txtngayghtieptheo.Text + "',tien = '" + txttien.Text + "' WHERE tagid = '" + txttagid.Text + "' "; MySqlCommand cmdupdate = new MySqlCommand(updateQuery, conn); cmdupdate.CommandText = updateQuery; cmdupdate.Connection = conn; cmdupdate.ExecuteNonQuery(); MessageBox.Show("Gia hạn thành công!"); } } } else { MessageBox.Show("Không có kết nối đến server hoặc quét thẻ cần gia hạn !"); } } catch (MySqlException ex) { conn.Close(); conn.Dispose(); MessageBox.Show("Lỗi kết nối đến server !"); } finally { //MessageBox.Show("**************"); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); conn.Dispose(); } this.Hide(); giaodienchinh to_giaodienchinh = new giaodienchinh(); to_giaodienchinh.ShowDialog(); this.Close(); } }
private void Btnxacnhan_Click(object sender, EventArgs e) { this.Hide(); giaodienchinh to_giaodienchinh = new giaodienchinh(); to_giaodienchinh.ShowDialog(); this.Close(); /* * try * { * * conn = DBUtils.GetDBConnection(); * conn.Open(); * * if (conn != null && txtten.Text != null) * { * * string getdata = "SELECT * FROM dvesdkvethang"; * MySqlCommand cmdzs = new MySqlCommand(getdata, conn); * rdr = cmdzs.ExecuteReader(); * while (rdr.Read()) * { * lstten.Items.Add(rdr.GetString("ten")); * if (txtten.Text == (rdr.GetString("ten"))) * { * txttagid.Text = rdr.GetString("tagid"); * txtbienso.Text = rdr.GetString("bienso"); * txtloaixe.Text = rdr.GetString("loaixe"); * txtngaybatdau.Text = rdr.GetString("ngaydangky"); * txtngayhenhan.Text = rdr.GetString("ngayhethan"); * txttien.Text = rdr.GetString("tien"); * } * * } * * } * else * { * MessageBox.Show("Không có kết nối đến Server !"); * } * * * } * catch (MySqlException ex) * { * conn.Close(); * conn.Dispose(); * MessageBox.Show("Lỗi kết nối đến server !"); * } * finally * { * if (rdr != null) * { * rdr.Close(); * } * * if (conn != null) * { * conn.Close(); * conn.Dispose(); * } * * } * //this.Hide(); * //giaodienchinh to_giaodienchinh = new giaodienchinh(); * //to_giaodienchinh.ShowDialog(); * //this.Close(); */ }
private void get_tongtien() { try { //int demthuong=0; string prethuong = "", prethang = ""; //while (true) //{ if (conn != null) { //MessageBox.Show("vé thường"); string[] thangtmp = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; string getvethuongtable = "SELECT thang FROM dvesvetrongngay"; MySqlCommand cmdvethuong = new MySqlCommand(getvethuongtable, conn); rdrthuong = cmdvethuong.ExecuteReader(); while (rdrthuong.Read()) { foreach (string tmp in thangtmp) { //MessageBox.Show(rdrthuong.GetString("thang")+" "+tmp); if (rdrthuong.GetString("thang") == tmp && (rdrthuong.GetString("thang") != prethuong)) { realthuong[Int32.Parse(tmp) - 1] = tmp; //demthuong++; prethuong = tmp; //MessageBox.Show("TRÙNG VÉ THƯỜNG----"); break; } else { //break; } } //break; } rdrthuong.Close(); //MessageBox.Show("VÉ THƯỜNG"+" "+realthuong[6] +" "+realthuong[7]); for (int k = 0; k < 12; k++) { if (realthuong[k] == null) { realthuong[k] = "0"; // MessageBox.Show(k.ToString()); } } // ********** SUM VÉ THƯỜNG *************************************************************************************************** for (int j = 0; j < 12; j++) { if (realthuong[j] != "0") { //Console.WriteLine("VÉ THƯỜNG" + " " + realthuong[j]); string resultvethuong = "SELECT sum(tien) FROM dvesvetrongngay WHERE thang = '" + realthuong[j] + "'"; MySqlCommand cmdresultvethuong = new MySqlCommand(resultvethuong, conn); vethuong[j] = Int32.Parse(cmdresultvethuong.ExecuteScalar().ToString()); } else { vethuong[j] = 0; } //Console.WriteLine(vethuong[j]); } // **************** VÉ THÁNG ************************* string getvethangtable = "SELECT thang FROM dvesdkvethang"; MySqlCommand cmdvethang = new MySqlCommand(getvethangtable, conn); rdrthang = cmdvethang.ExecuteReader(); while (rdrthang.Read()) { foreach (string tmp in thangtmp) { //MessageBox.Show(rdrthang.GetString("thang") + " " + tmp); if (rdrthang.GetString("thang") == tmp && (rdrthang.GetString("thang") != prethang)) { realthang[Int32.Parse(tmp) - 1] = tmp; //demthang++; prethang = tmp; //MessageBox.Show("TRÙNG VÉ THÁNG----"); break; } else { //break; } } //break; } rdrthang.Close(); //MessageBox.Show("VÉ THÁNG" + " " + realthang[6]); for (int l = 0; l < 12; l++) { if (realthang[l] == null) { realthang[l] = "0"; } } for (int h = 0; h < 12; h++) { if (realthang[h] != "0") { string resultvethang = "SELECT sum(tien) FROM dvesdkvethang WHERE thang = '" + realthang[h] + "'"; MySqlCommand cmdresultvethang = new MySqlCommand(resultvethang, conn); vethang[h] = Int32.Parse(cmdresultvethang.ExecuteScalar().ToString()); // MessageBox.Show(h.ToString()); } else { vethang[h] = 0; } } } } catch (Exception) { MessageBox.Show("ERROR"); conn.Close(); conn.Dispose(); this.Hide(); giaodienchinh to_giaodienchinh = new giaodienchinh(); to_giaodienchinh.ShowDialog(); this.Close(); } }
private void get_tongxe() { try { string prethuong = "", prethang = ""; if (conn != null) { //MessageBox.Show("vé thường"); string[] thangtmp = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; string getvethuongtable = "SELECT thang FROM dvesvetrongngay"; MySqlCommand cmdvethuong = new MySqlCommand(getvethuongtable, conn); rdrthuong = cmdvethuong.ExecuteReader(); while (rdrthuong.Read()) { foreach (string tmp in thangtmp) { if (rdrthuong.GetString("thang") == tmp) { switch (rdrthuong.GetString("thang")) { case "1": demthuong[0]++; break; case "2": demthuong[1]++; break; case "3": demthuong[2]++; break; case "4": demthuong[3]++; break; case "5": demthuong[4]++; break; case "6": demthuong[5]++; break; case "7": demthuong[6]++; break; case "8": demthuong[7]++; break; case "9": demthuong[8]++; break; case "10": demthuong[9]++; break; case "11": demthuong[10]++; break; case "12": demthuong[11]++; break; default: break; } } //MessageBox.Show(rdrthuong.GetString("thang")+" "+tmp); /* if (rdrthuong.GetString("thang") == tmp) * { * slthuong[Int32.Parse(tmp) - 1] = demthuong; * demthuong++; * * //MessageBox.Show("TRÙNG VÉ THƯỜNG----"); * //break; * } */ }//break; //demthuong = 1; } rdrthuong.Close(); //MessageBox.Show("VÉ THƯỜNG"+" "+realthuong[6] +" "+realthuong[7]); // **************** VÉ THÁNG ************************* string getvethangtable = "SELECT thang FROM dvesdkvethang"; MySqlCommand cmdvethang = new MySqlCommand(getvethangtable, conn); rdrthang = cmdvethang.ExecuteReader(); while (rdrthang.Read()) { foreach (string tmp in thangtmp) { if (rdrthang.GetString("thang") == tmp) { switch (rdrthang.GetString("thang")) { case "1": demthang[0]++; break; case "2": demthang[1]++; break; case "3": demthang[2]++; break; case "4": demthang[3]++; break; case "5": demthang[4]++; break; case "6": demthang[5]++; break; case "7": demthang[6]++; break; case "8": demthang[7]++; break; case "9": demthang[8]++; break; case "10": demthang[9]++; break; case "11": demthang[10]++; break; case "12": demthang[11]++; break; default: break; } } /* * //MessageBox.Show(rdrthang.GetString("thang") + " " + tmp); * if (rdrthang.GetString("thang") == tmp ) * { * slthang[Int32.Parse(tmp) - 1] = demthang; * demthang++; * * //MessageBox.Show("TRÙNG VÉ THÁNG----"); * //break; * } */ }//break; //demthang=1; } rdrthang.Close(); //MessageBox.Show("VÉ THÁNG" + " " + realthang[6]); } } catch (Exception) { MessageBox.Show("ERROR"); conn.Close(); conn.Dispose(); this.Hide(); giaodienchinh to_giaodienchinh = new giaodienchinh(); to_giaodienchinh.ShowDialog(); this.Close(); } }