private void btnGiaHan_Click(object sender, EventArgs e) { DataRow row = ((DataRowView)cbbMaDocGia.SelectedItem).Row; string madocgia = row[0].ToString(); SqlConnection Con = Conn.GetCon(); Con.Open(); string a = "select max(maphinop) from ThongTinNopPhi"; SqlCommand cmd = new SqlCommand(a, Con); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); string b = reader.GetValue(0).ToString(); Con.Close(); string c = ""; int d = 0; string e1 = ""; string f = ""; for (int i = 2; i < b.Length; i++) { c += b[i].ToString(); } d = Convert.ToInt32(c) + 1; e1 = Convert.ToString(d); for (int j = 0; j < (c.Length - e1.Length); j++) { f += c[j].ToString(); } b = "NP" + f + e1; using (QUANLYTHUVIENEntities db = new QUANLYTHUVIENEntities()) { //var thongtinnopphiQuery = from thongtinnopphi in db.THONGTINNOPPHIs THONGTINNOPPHI thongtinnopphi = new THONGTINNOPPHI(); thongtinnopphi.PHIDINHKY = int.Parse(tbxPhi.Text); thongtinnopphi.MADOCGIA = madocgia; thongtinnopphi.PHICAPTHE = 0; thongtinnopphi.PHATNOPTRE = 0; thongtinnopphi.PHATHUSACH = 0; thongtinnopphi.PHATMATSACH = 0; thongtinnopphi.NGAYNOP = DateTime.Now; thongtinnopphi.MAPHINOP = b; db.THONGTINNOPPHIs.Add(thongtinnopphi); db.SaveChanges(); string str = tbxNgayHetHan.Text.ToString().Trim(); str = str.Substring(6, 4); string day = tbxNgayHetHan.Text.ToString().Trim(); day = day.Substring(3, 2); string month = tbxNgayHetHan.Text.ToString().Trim(); month = month.Substring(0, 2); int year = Convert.ToInt32(str) + Convert.ToInt32(cbbNamGiaHan.Text); string hanmoi = month + "-" + day + "-" + year.ToString(); var ngayhethanQuery = from thongtindocgia in db.THONGTINDOCGIAs where thongtindocgia.MADOCGIA == madocgia select thongtindocgia; var ngayhethanObj = ngayhethanQuery.First(); ngayhethanObj.NGAYHETHAN = DateTime.Parse(hanmoi); ngayhethanObj.TRANGTHAIDOCGIA = 1; db.SaveChanges(); MessageBox.Show("Gia hạn thành công ."); this.Close(); frmCRGiaHanThe tt = new frmCRGiaHanThe(); tt.Show(); } }
private void tbxMaDG_TextChanged(object sender, EventArgs e) { SqlConnection con = Conn.GetCon(); string sql = ("select tendocgia from thongtindocgia where madocgia='" + tbxMaDG.Text + "'"); SqlCommand cmd = new SqlCommand(sql, con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { tbxTenDG.Text = dr[0].ToString(); con.Close(); string sql2 = ("select tennhom from nhomdocgia where manhom in ( select manhom from thongtindocgia where madocgia ='" + tbxMaDG.Text + "')"); SqlCommand cmd2 = new SqlCommand(sql2, con); con.Open(); SqlDataReader dr2 = cmd2.ExecuteReader(); if (dr2.Read()) { tbxTenNhom.Text = dr2[0].ToString(); con.Close(); string sql3 = ("select SOTIENPHATTREMOTNGAY,songaymuontoida from quydinh where maquydinh in ( select maquydinh from nhomdocgia where tennhom = N'" + tbxTenNhom.Text + "')"); SqlCommand cmd3 = new SqlCommand(sql3, con); con.Open(); SqlDataReader dr3 = cmd3.ExecuteReader(); if (dr3.Read()) { tbxTre.Text = dr3[0].ToString(); string ngaymuontoida = dr3[1].ToString(); double ngaymuontd = Convert.ToDouble(ngaymuontoida); con.Close(); string sql4 = ("select ngaymuon from phieumuontra where madocgia='" + tbxMaDG.Text + "'"); SqlCommand cmd4 = new SqlCommand(sql4, con); con.Open(); SqlDataReader dr4 = cmd4.ExecuteReader(); if (dr4.Read()) { tbxNMuon.Text = dr4[0].ToString(); tbxNgayMuon.Text = tbxNMuon.Text.Substring(0, 2) + "/" + tbxNMuon.Text.Substring(3, 2) + "/" + tbxNMuon.Text.Substring(6, 4); DateTime ngaymuon = new DateTime(Convert.ToInt32(tbxNMuon.Text.Substring(6, 4)), Convert.ToInt32(tbxNMuon.Text.Substring(3, 2)), Convert.ToInt32(tbxNMuon.Text.Substring(0, 2))); DateTime ngayphaitra = ngaymuon.AddDays(ngaymuontd); tbxNgayPhaiTra.Text = ngayphaitra.Day.ToString() + "/" + ngayphaitra.Month.ToString() + "/" + ngayphaitra.Year.ToString(); TimeSpan songaytre = DateTime.Now.Subtract(ngayphaitra); tbxNgayTre.Text = Convert.ToInt32(songaytre.TotalDays).ToString(); con.Close(); } else { tbxNgayPhaiTra.Text = null; tbxNgayTre.Text = null; tbxNMuon.Text = null; tbxNgayMuon.Text = null; con.Close(); } } else { tbxTre.Text = null; con.Close(); } } else { tbxTenNhom.Text = null; tbxTenDG.Text = null; con.Close(); } } }
private void tbxMaDG_TextChanged(object sender, EventArgs e) { SqlConnection con = Conn.GetCon(); string sql = ("select tendocgia from thongtindocgia where madocgia='" + tbxMaDG.Text + "'"); SqlCommand cmd = new SqlCommand(sql, con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { tbxTenDG.Text = dr[0].ToString(); con.Close(); string sql2 = ("select tennhom from nhomdocgia where manhom in ( select manhom from thongtindocgia where madocgia ='" + tbxMaDG.Text + "')"); SqlCommand cmd2 = new SqlCommand(sql2, con); con.Open(); SqlDataReader dr2 = cmd2.ExecuteReader(); if (dr2.Read()) { tbxTenNhom.Text = dr2[0].ToString(); con.Close(); string sql3 = ("select SOSACHMUONTOIDA,songaymuontoida from quydinh where maquydinh in ( select maquydinh from nhomdocgia where tennhom = N'" + tbxTenNhom.Text + "')"); SqlCommand cmd3 = new SqlCommand(sql3, con); con.Open(); SqlDataReader dr3 = cmd3.ExecuteReader(); if (dr3.Read()) { tbxSoSach.Text = dr3[0].ToString(); string a = dr3[1].ToString(); double b = Convert.ToDouble(a); con.Close(); DateTime ngaytra = DateTime.Now.AddDays(b); tbxNgayPhaiTra.Text = ngaytra.Day.ToString() + "/" + ngaytra.Month.ToString() + "/" + ngaytra.Year.ToString(); } else { con.Close(); tbxSoSach.Text = null; tbxNgayPhaiTra = null; } } else { con.Close(); tbxTenNhom.Text = null; } } else { tbxTenDG.Text = null; tbxTenNhom.Text = null; tbxSoSach.Text = null; con.Close(); } string sql1 = ("select tinhtrang from phieumuontra where madocgia = '" + tbxMaDG.Text + "'"); SqlCommand cmd1 = new SqlCommand(sql1, con); con.Open(); SqlDataReader dr1 = cmd1.ExecuteReader(); if (dr1.Read()) { if (dr1[0].ToString() == "0") { con.Close(); label8.Visible = true; btnMuon.Enabled = false; } else { con.Close(); label8.Visible = false; btnMuon.Enabled = true; } } else { label8.Visible = false; btnMuon.Enabled = true; } }