public int IndexOF(SV s) { int index = -1; for (int i = 0; i < n; i++) { if (arr[i] == s) { index = i; break; } } return(index); }
public SV getSVById(string mssv) { SV sv = new SV(); foreach (SV s in GetAllSV()) { if (mssv.Equals(s.MSSV)) { sv = s; break; } } return(sv); }
public void Sort() { for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if ((string.Compare(arr[j].Name, arr[i].Name) < 0)) { SV a = new SV(); a = arr[j]; arr[j] = arr[i]; arr[i] = a; } } } }
// sap xep theo DHT public void Sort() { SV temp = new SV(); for (int i = 0; i < this.count - 1; i++) { for (int j = i + 1; j < this.count; j++) { if (this.ds[i].DHT > this.ds[j].DHT) { temp = this.ds[i]; this.ds[i] = this.ds[j]; this.ds[j] = temp; } } } }
public void EditDataRowSV(SV s) { foreach (DataRow i in dtSV.Rows) { if (Convert.ToInt32(i["MSSV"].ToString()) == s.MSSV) { CSDL.Instance.dtSV.Rows.Remove(i); DataRow dr = dtSV.NewRow(); dr["MSSV"] = s.MSSV; dr["NameSV"] = s.NameSV; dr["Gender"] = s.Gender; dr["NS"] = s.NS; dr["ID_Lop"] = s.ID_Lop; dtSV.Rows.Add(dr); return; } } }
public void ExecuteDB(SV s) { bool check = false; foreach (SV i in GetAllSV()) { if (i.MSSV == s.MSSV) { check = true; } } if (check) { CSDL.Instance.EditDataRowSV(s); } else { CSDL.Instance.AddDataRowSV(s); } }
public List <SV> sortSV(string type, List <SV> l, int classID) { if ("Birthday" == type) { cmp = SV.Compare_Birth; } if ("MSSV" == type) { cmp = SV.Compare_MSSV; } if ("NameSV" == type) { cmp = SV.Compare_Name; } if ("ClassID" == type) { cmp = SV.Compare_ClassID; } if ("Gender" == type) { cmp = SV.Compare_Gender; } foreach (SV i in getSVbyClassID(classID)) { l.Add(i); } for (int i = 0; i < l.Count; i++) { for (int j = i + 1; j < l.Count; j++) { if (cmp(l[j], l[i])) { SV temp = new SV(); temp = l[i]; l[i] = l[j]; l[j] = temp; } } } return(l); }
public void updateSV(SV sv) { DataTable dtSV = new DataTable(); dtSV = CSDL.Instance.DTSV; foreach (DataRow dr in dtSV.Rows) { if (dr["MSSV"].Equals(sv.MSSV)) { dr["NameSV"] = sv.NameSV; dr["Gender"] = sv.Gender; dr["NS"] = sv.NS; dr["ID_Lop"] = sv.ID_Lop; break; } } dtSV.AcceptChanges(); CSDL.Instance.DTSV = dtSV; }
public SV getSV() { SV s = new SV(); s.MSSV = Convert.ToInt32(txt_mssv.Text); s.NameSV = txt_name.Text; if (radio_male.Checked == true) { s.Gender = true; } else { s.Gender = false; } s.Birthday = dtp_birthday.Value; int id_class = CDSL_Handle.Instance.getIDLSH(cbb_LSH.Text); s.ClassID = id_class; return(s); }
public void ChangeScoreSV(ref SV Info_change, string choice) { if (choice != "Name" && choice != "Age" && choice != "Address" && choice != "Gender" && choice != "All") { Info_change.getChoice = choice; Console.Write("\rNhap diem mon {0}: ", choice); double score_change = double.Parse(Console.ReadLine()); Info_change.getScore = score_change; } else if (choice == "Name" || choice == "Age" || choice == "Address" || choice == "Gender") { Info_change.getChoice = choice; Console.Write("\rNhap {0}: ", choice); string NAGA = Console.ReadLine(); Info_change.getNAGA = NAGA; } else { Info_change.InputInfo(); Info_change.InputScore(); } }
public void Add(SV s) { if (n == 0) { arr = new SV[n + 1]; arr[n] = s; } else { SV[] t = new SV[n]; for (int i = 0; i < n; i++) { t[i] = arr[i]; } arr = new SV[n + 1]; for (int i = 0; i < n; i++) { arr[i] = t[i]; } arr[n] = s; } n++; }
static void Main(string[] args) { SV s1 = new SV { MSSV = 1, Name = "NVA" }; SV s2 = new SV { MSSV = 2, Name = "NVB" }; SV s3 = new SV { MSSV = 3, Name = "NVC" }; SV s4 = new SV { MSSV = 4, Name = "NVD" }; QLSV.Instance.Add(s1); QLSV.Instance.Add(s4); QLSV.Instance.Insert(s3, 0); QLSV.Instance.Insert(s2, 1); QLSV.Instance.Sort(); Console.WriteLine(QLSV.Instance); Console.ReadKey(); }
public int Compare(object x, object y) { SV a = x as SV; SV b = y as SV; a.getChoice = choiceSort; b.getChoice = choiceSort; if (a == null || b == null) { throw new InvalidOperationException(); } if (a.getScore > b.getScore) { return(1); } else if (a.getScore < b.getScore) { return(-1); } else { return(0); } }
public int BinarySearch(SV s) { int l = 0; int r = this.count - 1; Sort(); s.Show(); while (r >= l) { int mid = (r + l) / 2; this.ds[mid].Show(); if (this.ds[mid].MSSV == s.MSSV && this.ds[mid].Name == s.Name && this.ds[mid].DHT == s.DHT) { return(mid); } if (this.ds[mid].DHT > s.DHT) { r = mid - 1; } //if (this.ds[mid].DHT < s.DHT) l = mid + 1; } return(-1); }
// Them 1 SV public void ThemSV(SV s) { if (this.count == 0) { this.count = 1; this.ds = new SV[count]; this.ds[0] = s; } else { int i = 0; SV[] Temp = new SV[count]; for (i = 0; i < count; i++) { Temp[i] = new SV(); Temp[i].MSSV = this.ds[i].MSSV; Temp[i].Name = this.ds[i].Name; Temp[i].DHT = this.ds[i].DHT; } count++; ds = new SV[count]; for (i = 0; i < count - 1; i++) { ds[i] = new SV(); ds[i].MSSV = Temp[i].MSSV; ds[i].Name = Temp[i].Name; ds[i].DHT = Temp[i].DHT; } ds[count - 1] = new SV(); ds[count - 1].MSSV = s.MSSV; ds[count - 1].Name = s.Name; ds[count - 1].DHT = s.DHT; } }
static void Main(string[] args) { double j = 1; Console.WriteLine("--------------------------------------Chuong Trinh Quan Li Sinh Vien--------------------------------------------"); bool choice = true; Console.Write("Nhap so sinh vien cua lop : "); int n = int.Parse(Console.ReadLine()); while (n > 10 || n < 0)//Xoa dong nay neu muon nhap hon 10 Sinh vien { Console.WriteLine("So sinh vien toi da random hoac tu nhap la 10 hoac ban da nhap so sinh vien khong hop le."); Console.Write("Nhap Lai : "); n = int.Parse(Console.ReadLine()); }// Va ca dong nay nua nha :)) List <SV> ArrSV = new List <SV>(n); Console.WriteLine("2 Che do : Random va tu nhap thong tin. "); Console.WriteLine("Ban muon random SV hay tu nhap . Neu chon random thi ghi Random neu tu nhap thi ghi gi cung duoc "); Console.Write("Lua chon cua ban : ");//Che do Random chi tu dong nhap duoc toi da 10 nguoi , neu nhap qua se bi crash string c_random = Console.ReadLine(); if (c_random != "Random")//Tu nhap vao { for (int i = 0; i < n; i++) { ArrSV.Add(new SV()); } inputInfo(ArrSV, ref j); } else//Random SV { for (int i = 0; i < n; i++) { ArrSV.Add(new SV()); } foreach (SV items in ArrSV) { items.RandomSV(); items.getMSSV = j; j++; } } do { Menu: StartProgam(); printInfo(ArrSV); functionProgam(); int rule = int.Parse(Console.ReadLine()); switch (rule) { case 1: //Sap xep theo diem Console.Write("Ban muon sap xep mon nao "); string subject = Console.ReadLine(); Sort_Score sub = new Sort_Score(); sub.inputChoice(subject); ArrSV.Sort(sub); Console.WriteLine("Sau khi sap xep theo Diem {0} :", subject); printInfo(ArrSV); Endprogam(ref choice); break; case 2: //Sap xep theo MSSV Sort_Score sub_2 = new Sort_Score(); sub_2.inputChoice("MSSV"); ArrSV.Sort(sub_2); Console.WriteLine("Sau khi sap xep theo MSSV :"); printInfo(ArrSV); Endprogam(ref choice); break; case 3: //Them SV Console.Write("Nhap so Sinh vien muon them : "); int addSV = int.Parse(Console.ReadLine()); List <SV> ArrAdd = new List <SV>(addSV); for (int i = 0; i < addSV; i++) { ArrAdd.Add(new SV()); } inputInfo(ArrAdd, ref j); ArrSV.AddRange(ArrAdd); printInfo(ArrSV); Endprogam(ref choice); break; case 4: //Xoa sinh vien Console.Write("Nhap ten Sinh vien muon xoa : "); string name_remove = Console.ReadLine(); SV reSV = ArrSV.Find(new SearchNameSV(name_remove).search);//Tim kiem vi tri SV can xoa trong list ban dau ArrSV.Remove(reSV); printInfo(ArrSV); Endprogam(ref choice); break; case 5: //Sua thong tin SV( p/s : Thong tin Age neu sua o lan dau nhap vao thi duoc nhung lan 2 se bi crash ct) StartChange: string y_choice = "y"; string _choice = "1"; do { Console.Write("Nhap ten sinh vien muon sua : "); string name_change = Console.ReadLine(); ThisSVchange: int index = ArrSV.FindIndex(new SearchNameSV(name_change).search); SV chSV = ArrSV.Find(new SearchNameSV(name_change).search); if (_choice != "0") { Console.WriteLine("\rThong tin sinh vien can doi : "); chSV.OutputInfo(); } ArrSV.Remove(chSV); Console.WriteLine("Ban muon doi thong tin nao cua sinh vien hay toan bo : "); Console.Write("Neu toan bo nhap All khong thi nhap thong tin can sua: "); string infochange = Console.ReadLine(); changeSV changeInfo = new changeSV(); changeInfo.ChangeScoreSV(ref chSV, infochange); ArrSV.Insert(index, chSV); printInfo(ArrSV); Continue(ref y_choice, "sua"); if (y_choice == "y") { Console.WriteLine("Ban muon tiep tuc sua sinh vien nay hay sua sinh vien khac "); Console.Write("Nhap 0 de tiep tuc sua sinh vien hay nhap gi cx duoc de sua sv khac"); _choice = Console.ReadLine(); if (_choice == "0") { goto ThisSVchange; } else { goto StartChange; } } } while (y_choice == "y"); Endprogam(ref choice); break; case 6: //Tim kiem sinh vien Console.Write("Nhap ten Sinh vien muon tim kiem : "); string name_search = Console.ReadLine(); SV searchSV = ArrSV.Find(new SearchNameSV(name_search).search);//Tim kiem vi tri SV can kiem trong list ban dau Console.WriteLine("Thong tin sinh vien sau khi tim kiem la: "); searchSV.OutputInfo(); Endprogam(ref choice); break; case 7: //Xoa toan bo thong tin SV ArrSV.Clear(); printInfo(ArrSV); break; case 8: //Xoa man hinh Console.WriteLine("Chuong trinh dang thuc hien xoa man hinh. "); Console.Clear(); Console.WriteLine("Man Hinh Da Xoa Xong."); Console.WriteLine("Dang Cap Nhap Lai Du Lieu"); Console.WriteLine("Data Update......"); Pause(); Console.WriteLine("Cap Nhap Data Hoan thanh"); Pause(); Console.Clear(); Console.WriteLine("--------------------------------------Chuong Trinh Quan Li Sinh Vien--------------------------------------------"); goto Menu; case 9: //Ket thuc chuong trinh Console.WriteLine("Ban da chon ket thuc chuong trinh. Cam on vi da su dung chuong trinh"); Console.WriteLine("See you again in next time. Bye"); choice = false; break; default: Console.WriteLine("Lua chon khong hop le "); Endprogam(ref choice); break; } } while (choice == true); Console.Read(); }
private int byDate(SV sv1, SV sv2) { return(sv1.NS.CompareTo(sv2.NS)); }
private int byName(SV sv1, SV sv2) { return(sv1.NameSV.CompareTo(sv2.NameSV)); }
// Sort private int byMSSV(SV sv1, SV sv2) { return(sv1.MSSV.CompareTo(sv2.MSSV)); }
static void Main(string[] args) { SV sv1 = new SV { MSSV = 111, Name = "A", DHT = 1.1 }; SV sv2 = new SV { MSSV = 222, Name = "B", DHT = 9.1 }; SV sv3 = new SV { MSSV = 333, Name = "C", DHT = 8.1 }; SV sv4 = new SV { MSSV = 444, Name = "D", DHT = 7.1 }; SV sv5 = new SV { MSSV = 555, Name = "E", DHT = 5.1 }; QLSV a = new QLSV(); a.ThemSV(sv1); a.ThemSV(sv2); a.ThemSV(sv3); a.ThemSV(sv4); /*a.ThemSV(sv4); * a.ThemSV(sv5); * Console.WriteLine("Danh sach SV:"); * a.Show(); * a.XoaSV1(3); * Console.WriteLine("Da xoa SV thu 3 ra khoi DS:"); * a.Show(); * a.XoaSV(sv1); * Console.WriteLine("Da xoa SV sv1 ra khoi DS:"); * a.Show(); * Console.WriteLine("Da xoa SV sv5 ra khoi DS:"); * a.XoaSV(sv5); * a.Show(); */ a.Insert(3, sv5); a.Sort(); //a.Show(); int k = a.BinarySearch(sv3); Console.WriteLine("Vi tri tim thay: {0}", k + 1); Console.WriteLine("Done!"); Console.ReadKey(); }
public void Remove(SV s) { RemoveAt(IndexOF(s)); }
public void passData(SV sv) { this.sv = sv; }
// Hàm gán cho delegage public bool search(SV p) { return(p.getName == namesearch); }