public BoMon LayBoMonTheoMa(string maBM) { if (maBM is null) { bm = new BoMon { MaBoMon = null, TenBoMon = "Không có bộ môn" }; return(bm); } else { data = new DataTable(); string str = "select * from BoMon where MaBoMon = '" + maBM + "'"; data = Server.LayDuLieuBang(str); if (data.Rows.Count > 0) { bm = new BoMon { MaBoMon = data.Rows[0]["MaBoMon"].ToString(), TenBoMon = data.Rows[0]["TenBM"].ToString(), MaKhoa = data.Rows[0]["MaKhoa"].ToString(), MaChuNhiem = data.Rows[0]["MaChuNhiem"].ToString() }; return(bm); } } return(null); }
protected void btnUpdate_Click(object sender, EventArgs e) { if (txtId.Text == "" || Convert.ToInt32(txtId.Text) < 1) { lblUpdateMessage.Text = "Vui lòng nhập một ID môn học > 0"; txtId.Focus(); return; } DCVimaruDataContext dc = new DCVimaruDataContext(); BoMon bomon = dc.BoMons.Single(t => t.MaBoMon == Convert.ToInt32(cboFilterDepartment.SelectedValue)); int parent = Convert.ToInt32(bomon.Id); MoodleCategory category; XmlDocument doc = new XmlDocument(); category = new MoodleCategory { Id = Convert.ToInt32(txtId.Text), Name = HttpUtility.HtmlDecode(txtName.Text), Parent = parent, IdNumber = HttpUtility.HtmlDecode(txtIdnumber.Text), Description = HttpUtility.HtmlDecode(txtName.Text), DescriptionFormat = 1, Theme = null }; List <MoodleCategory> lst = new List <MoodleCategory>(); lst.Add(category); doc.LoadXml(MoodleCategory.UpdateCategories(lst, (string)Session["token"])); doc.Save("D:\\subject_" + txtId.Text + ".xml"); }
public async Task <Uri> CreateBoMonAsync(BoMon boMon) { var url = base_url + "/bo-mons"; HttpResponseMessage response = await client.PostAsJsonAsync(url, boMon); response.EnsureSuccessStatusCode(); // return URI of the created resource. return(response.Headers.Location); }
private void btnLuu_Click(object sender, EventArgs e) { if (!txtMaBM.Text.Trim().Equals("")) { if (them) { try { XepThoiKhoaBieuDataContext dbs = new XepThoiKhoaBieuDataContext(); BoMon bm = new BoMon(); bm.MaBM = Convert.ToInt32(txtMaBM.Text); bm.TenBM = txtTenBM.Text; dbs.BoMons.InsertOnSubmit(bm); dbs.SubmitChanges(); LoadData(); MessageBox.Show("Đã thêm xong"); } catch (Exception) { MessageBox.Show("Không thêm được,Lỗi rồi!!"); } } else { try { int r = dgvBoMon.CurrentCell.RowIndex; string ma = dgvBoMon.Rows[r].Cells[0].Value.ToString(); XepThoiKhoaBieuDataContext dbs = new XepThoiKhoaBieuDataContext(); var ng = (from p in dbs.BoMons where p.MaBM.ToString() == ma select p).SingleOrDefault(); if (ng != null) { ng.TenBM = txtTenBM.Text; dbs.SubmitChanges(); LoadData(); } LoadData(); MessageBox.Show("Đã sửa xong!"); } catch (Exception) { MessageBox.Show("Không sửa được,Lỗi rồi!!"); } } } else { MessageBox.Show("Bộ Môn chưa có,Lỗi rồi!!"); txtMaBM.Focus(); } LoadData(); }
protected void btnCreate_Click(object sender, EventArgs e) { SaveCheckedValues(); grvDepartment.AllowPaging = false; grvDepartment.DataBind(); MoodleCategory category; XmlDocument doc = new XmlDocument(); ArrayList arrIDs = ConvertToArrayList(txtListId.Text); string idnum = "0"; DCVimaruDataContext dc = new DCVimaruDataContext(); Khoa khoa = dc.Khoas.Single(t => t.MaKhoa == cboFilter.SelectedValue); int parent = Convert.ToInt32(khoa.Id); foreach (GridViewRow row in grvDepartment.Rows) { if (row.Cells[2].Text != "0") { continue; } idnum = grvDepartment.DataKeys[row.RowIndex]["MaBoMon"].ToString(); if (arrIDs.Contains(idnum)) { category = new MoodleCategory { Name = HttpUtility.HtmlDecode(row.Cells[4].Text), Parent = parent, IdNumber = HttpUtility.HtmlDecode(row.Cells[3].Text), Description = HttpUtility.HtmlDecode(row.Cells[4].Text), DescriptionFormat = 1, Theme = null }; List <MoodleCategory> lst = new List <MoodleCategory>(); lst.Add(category); doc.LoadXml(MoodleCategory.CreateCategories(lst, (string)Session["token"])); doc.Save("D:\\department_" + category.IdNumber + ".xml"); if (doc.DocumentElement.Name == "RESPONSE") { long id = (long)Convert.ToUInt32(doc.DocumentElement.ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText); BoMon bomon = dc.BoMons.Single(t => t.MaBoMon == Convert.ToInt32(category.IdNumber)); bomon.Id = id; dc.SubmitChanges(); } } } grvDepartment.AllowPaging = true; }
// thêm bộ môn public bool Add(BoMon info) { try { db_.BoMons.Add(info); db_.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } return(true); }
public IActionResult InsertBoMon(BoMon bm) { int count; StoreContext context = HttpContext.RequestServices.GetService(typeof(firstWeb.Models.StoreContext)) as StoreContext; count = context.InsertBoMon(bm); if (count > 0) { ViewData["thongbao"] = "Insert thành công"; } else { ViewData["thongbao"] = "Insert không thành công"; } return(View()); }
public ActionResult Edit(BoMon obj) { var db = new TeachingScheduleEntities(); if (obj.MaBoMon == 0) { obj.Active = true; db.BoMons.Add(obj); } else { db.Entry(obj).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); }
public BoMon LayBoMonTheoGiaoVien(string maGV) { List <BoMon> listBM = new List <BoMon>(); data = new DataTable(); string str = "LayBoMonTheoGiaoVien '" + maGV + "'"; data = Server.LayDuLieuBang(str); if (data.Rows.Count > 0) { bm = new BoMon { TenBoMon = data.Rows[0]["TenBM"].ToString(), NgayChuyenDen = data.Rows[0]["NgayChuyenDen"].ToString() }; return(bm); } return(null); }
public JsonResult AddBoMon(string tenNganh) { try { var n = new BoMon(); Random random = new Random(); while (true) { n.TrangThai = true; n.Ten = tenNganh; var ma = "BM" + random.Next(10000000, 90000000); if (!db.GiaoViens.ToList().Exists(x => x.MaGV.Equals(ma))) { n.Ma_BoMon = ma; break; } ; } db.BoMons.Add(n); GiaoVien giaoVien = new GiaoVien(); giaoVien.MaGV = n.Ma_BoMon; giaoVien.TenGV = n.Ten; giaoVien.MaBoMon = n.Ma_BoMon; giaoVien.TrangThai = false; db.GiaoViens.Add(giaoVien); db.SaveChanges(); TaiKhoan taiKhoan = new TaiKhoan(); taiKhoan.TenDangNhap = n.Ma_BoMon; taiKhoan.MatKhau = "" + 1; taiKhoan.TaiKhoan1 = n.Ma_BoMon; taiKhoan.ChưcVu = "BoMon"; taiKhoan.TrangThai = true; db.TaiKhoans.Add(taiKhoan); db.SaveChanges(); return(Json(new { code = 200, msg = "Thêm mới thành công" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { code = 500, msg = "Không thành công" + e.Message }, JsonRequestBehavior.AllowGet)); } }
// Sửa thông tin public bool Edit(BoMon info) { try { var info0 = GetSingleByID(info.MaBM); if (info0 != null) { info0.TenBM = info.TenBM; info0.MaKhoa = info.MaKhoa; db_.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } return(true); }
public List <BoMon> LayBoMonTheoKhoa(string maK) { List <BoMon> listBM = new List <BoMon>(); data = new DataTable(); string str = "select * from BoMon where MaKhoa = '" + maK + "'"; data = Server.LayDuLieuBang(str); foreach (DataRow item in data.Rows) { bm = new BoMon { MaBoMon = item["MaBoMon"].ToString(), TenBoMon = item["TenBM"].ToString(), MaKhoa = item["MaKhoa"].ToString(), MaChuNhiem = item["MaChuNhiem"].ToString() }; listBM.Add(bm); } return(listBM); }