public Dien LayDien(string mactd) { using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = @"SELECT maCongToDien,chiSoDau,chiSoCuoi,ngayGhi,gia,TieuThu FROM DIEN WHERE maCongToDien = @mactd"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@mactd", mactd); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { Dien hd = new Dien { Macongtodien = (string)reader["maCongToDien"], ChisoDau = (string)reader["chiSoDau"], ChisoCuoi = (string)reader["chiSoDau"], // ThanhTien =(long)reader["thanhTien"], NgayGhi = reader["ngayGhi"].ToString(), DonGia = (float)reader["gia"], TieuThu = (string)reader["TieuThu"], }; return(hd); } } return(null); }
public Dien NAME(string maCongToDien) { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM DIEN WHERE maCongToDien = @md ", connection); cmd.Parameters.AddWithValue("@md", maCongToDien); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { Dien D = new Dien { Macongtodien = (string)reader["maCongToDien"], ChisoDau = (string)reader["chiSoDau"], ChisoCuoi = (string)reader["chiSoCuoi"], DonGia = (float)reader["gia"], TieuThu = (string)reader["TieuThu"], ThanhTien = (long)reader["thanhTien"], NgayGhi = reader["ngayGhi"].ToString(), }; return(D); } return(null); } }
protected void btnThem_Click(object sender, EventArgs e) { int csd; int csc; int dg; csd = Convert.ToInt16(txtChisocdau.Text); csc = Convert.ToInt16(txtChisocuoi.Text); dg = Convert.ToInt16(txtDongia.Text); int tthu; tthu = (csc - csd); txtTieuthu.Text = tthu.ToString(); Dien DN = LayDuLieuTuForm(); DienDAO DienDAO = new DienDAO(); bool exist = DienDAO.checkmact(DN.Macongtodien); if (exist) { lblThongBao.Text = "Mã công tơ nước đã tồn tại"; } else { bool result = DienDAO.Them(DN); if (result) { lblThongBao.Text = "Tính thành công"; LayDuLieuTuGirdview(); } else { lblThongBao.Text = "Lỗi"; } } }
protected void btnSua_Click(object sender, EventArgs e) { int csd; int csc; int dg; csd = Convert.ToInt16(txtChisocdau.Text); csc = Convert.ToInt16(txtChisocuoi.Text); dg = Convert.ToInt16(txtDongia.Text); int tthu; tthu = (csc - csd); txtTieuthu.Text = tthu.ToString(); Dien D = LayDuLieuTuForm(); DienDAO DienDAO = new DienDAO(); bool result = DienDAO.ChinhSua(D); if (result) { lblThongBao.Text = "Cập nhật thành công : " + D.NgayGhi; LayDuLieuTuGirdview(); } else { lblThongBao.Text = "Cập nhật không thành công, vui lòng kiểm tra lại"; } }
public void DoDuLieuVaoCacTruong(Dien nv) { txtMacongtodien.Text = nv.Macongtodien; txtChisocdau.Text = nv.ChisoDau; txtChisocuoi.Text = nv.ChisoCuoi; txtNgayghi.Text = nv.NgayGhi; txtDongia.Text = nv.DonGia.ToString(); txtTieuthu.Text = nv.TieuThu; }
public bool Them(Dien DN) { using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = @"INSERT INTO DIEN(maCongToDien,chiSoDau,chiSoCuoi,tieuThu, gia, thanhTien,ngayGhi) VALUES(@mctd,@csd,@csc,@tthu,@Gia,@ttien,@ngayghi)"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@mctd", DN.Macongtodien); cmd.Parameters.AddWithValue("@csd", DN.ChisoDau); cmd.Parameters.AddWithValue("@csc", DN.ChisoCuoi); cmd.Parameters.AddWithValue("@tthu", DN.TieuThu); cmd.Parameters.AddWithValue("@Gia", DN.DonGia); cmd.Parameters.AddWithValue("@ttien", DN.ThanhTien); cmd.Parameters.AddWithValue("@ngayghi", Convert.ToDateTime(DN.NgayGhi)); connection.Open(); int result = cmd.ExecuteNonQuery(); return(result >= 1); } }
public bool ChinhSua(Dien DN) { using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = @"UPDATE DIEN SET chiSoDau= @csd, chiSoCuoi = @csc, tieuThu = @tthu, gia= @Gia, thanhTien = @ttien, ngayGhi=@ngayghi WHERE maCongToDien = @mctd"; SqlCommand command = new SqlCommand(sql, connection); command.Parameters.AddWithValue("@mctd", DN.Macongtodien); command.Parameters.AddWithValue("@csd", DN.ChisoDau); command.Parameters.AddWithValue("@csc", DN.ChisoCuoi); command.Parameters.AddWithValue("@tthu", DN.TieuThu); command.Parameters.AddWithValue("@Gia", DN.DonGia); command.Parameters.AddWithValue("@ttien", DN.ThanhTien); command.Parameters.AddWithValue("@ngayghi", Convert.ToDateTime(DN.NgayGhi)); connection.Open(); int result = command.ExecuteNonQuery(); if (result >= 1) { return(true); } } return(false); }
private Dien LayDuLieuTuForm() { string maCongToDien = txtMacongtodien.Text; string chisodau = txtChisocdau.Text; string chisocuoi = txtChisocuoi.Text; string ngayghi = txtNgayghi.Text; float gia = float.Parse(txtDongia.Text); string tieuthu = txtTieuthu.Text; double thanhtien = double.Parse(tieuthu) * gia; long thanhtien1 = Convert.ToInt64(thanhtien); Dien D = new Dien { Macongtodien = maCongToDien, ChisoDau = chisodau, ChisoCuoi = chisocuoi, NgayGhi = ngayghi, TieuThu = tieuthu, DonGia = gia, ThanhTien = thanhtien1, }; return(D); }