public static bool AddStuTODB(StudentObject student) { Console.WriteLine("Student: " + student.Firstname); try { string connetionString = null; string sql = null; connetionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Giuseppe\\Documents\\SchoolManagement\\SchoolManagementSolution\\SchoolServer2\\DatabaseForSchool.mdf;Integrated Security=True"; using (SqlConnection cnn = new SqlConnection(connetionString)) { sql = "insert into Students ([FirstName], [LastName], [Grade], [Age], [Gender], [GPA]) values(@first,@last,@grade,@age,@gender,@gpa)"; cnn.Open(); using (SqlCommand cmd = new SqlCommand(sql, cnn)) { cmd.Parameters.AddWithValue("@first", student.Firstname); cmd.Parameters.AddWithValue("@last", student.Lastname); cmd.Parameters.AddWithValue("@grade", student.Grade); cmd.Parameters.AddWithValue("@age", student.Age); cmd.Parameters.AddWithValue("@gender", student.Gender); cmd.Parameters.AddWithValue("@gpa", student.Gpa); cmd.ExecuteNonQuery(); Console.WriteLine("Row inserted !! "); return(true); } } } catch { Console.WriteLine("FAILED"); return(false); } }
public static void AddStudentInfoToDB(StudentObject student) { try { TcpClient tcpclnt = new TcpClient(); MessageBox.Show("Connecting....."); tcpclnt.Connect("192.168.1.114", 8000); MessageBox.Show("Connected"); Stream stm = tcpclnt.GetStream(); byte[] ba = ObjectToByteArray(student); stm.Write(ba, 0, ba.Length); byte[] bb = new byte[100]; int k = stm.Read(bb, 0, 100); tcpclnt.Close(); } catch (Exception e) { MessageBox.Show("Error..... " + e.StackTrace); } }
private void sAddButton_Click(object sender, EventArgs e) { if (!Validation.isTextBoxValid(errorProvider1, sUserIdTextBox, sPassowrdtextBox, sFirstNametextBox, sLastNametextBox, sEmailTextBox, sPhoneTextBox)) { return; } //add student adminConnect = new AdminConnect(); StudentObject student = new StudentObject(); student.UserId = sUserIdTextBox.Text; student.Password = sPassowrdtextBox.Text; student.FirstName = sFirstNametextBox.Text; student.LastName = sLastNametextBox.Text; student.Phone = sPhoneTextBox.Text; student.Email = sEmailTextBox.Text; if (adminConnect.AddUser(student) <= 0) { //show error MessageBox.Show("Instructor not added", "Add error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } else { //display success message MessageBox.Show("Instructor added successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } }
public List <StudentObject> getDataOnline() { List <StudentObject> listStudentSycOnline = new List <StudentObject>(); ConnectionEntities objConEn = new ConnectionEntities(); eTrainingOnlineEntities objConnEntitiesOn = objConEn.getTrainingCenterOn(); //ConnectionEntities objConEn = new ConnectionEntities(); //TrainingCenterEntities objConnEntities = objConEn.getTrainingCenter(); //IQueryable<Student> lstStudent = objConnEntities.Students; //var listTempOnline = objConnEntitiesOn.Students.Where(p => p.DateCreate < DateTime.Now) // .AsEnumerable() // .Where(p => p.DateCreate > DateTime.Now.AddDays(-3)); //var listTempOnline = objConnEntitiesOn.Students.Where(i => i.DateCreate > DateTime.Now.AddDays(-7)).ToList(); var listTempOnline = objConnEntitiesOn.SP_Student_GetOnlineStudentFromLast3days(); foreach (var item in listTempOnline) { StudentObject objS = new StudentObject(item.Id, item.FirstName, item.LastName, item.FullName, item.Sex, item.DateBirthday, item.Mobile, item.Email, item.Address, item.DateCreate, item.DateLastUpdate, item.Description, item.CourseId, item.StatusId, item.UserId); listStudentSycOnline.Add(objS); } return(listStudentSycOnline); }
private void addStuBtn_Click(object sender, EventArgs e) { StudentObject student = new StudentObject(firstNameTxt.Text, lastNameTxt.Text, gradeTxt.Text, ageTxt.Text, genderTxt.Text, gpaTxt.Text); AddStudentInfo.AddStudentInfoToDB(student); LoadStudentInfo(); }
private static List <Lesson> getLessonss(StudentObject studentObject, int programCode, int yearCode, int periodCode) { var lessons = new List <Lesson>(); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("StudentNo", studentObject.Id); parameters.Add("yearCode", "" + yearCode); parameters.Add("yearCodeSpecified", "true"); parameters.Add("donemNo", "" + periodCode); parameters.Add("donemNoSpecified", "true"); parameters.Add("dalId", "" + programCode); parameters.Add("dalIdSpecified", "true"); parameters.Add("pass", studentObject.Password); string html = GetString("NotSorgu", parameters).Replace("a:", ""); XElement root = XElement.Parse(html); root = root.Elements().FirstOrDefault(); root = root.Elements().FirstOrDefault(); foreach (var item in root.Elements().Where(x => x.HasElements)) { Lesson lesson = new Lesson(); lesson.Code = item.Elements().ToList()[6].Value; lesson.AbsentState = GetAbsentType(item.Elements().ToList()[7].Value); lesson.Name = item.Elements().ToList()[5].Value.Tidy(); lesson.FirstMidterm = new Exam() { Mark = string.IsNullOrEmpty(item.Elements().ToList()[16].Value) ? (int?)null : item.Elements().ToList()[16].Value == "G" ? 0 : Convert.ToInt32(item.Elements().ToList()[16].Value), Date = string.IsNullOrEmpty(item.Elements().ToList()[18].Value) ? (DateTime?)null : Convert.ToDateTime(item.Elements().ToList()[18].Value) }; lesson.SecondMidterm = new Exam() { Mark = string.IsNullOrEmpty(item.Elements().ToList()[19].Value) ? (int?)null : item.Elements().ToList()[19].Value == "G" ? 0 : Convert.ToInt32(item.Elements().ToList()[19].Value), Date = string.IsNullOrEmpty(item.Elements().ToList()[21].Value) ? (DateTime?)null : Convert.ToDateTime(item.Elements().ToList()[21].Value) }; lesson.ThirdMidterm = new Exam() { Mark = string.IsNullOrEmpty(item.Elements().ToList()[22].Value) ? (int?)null : item.Elements().ToList()[22].Value == "G" ? 0 : Convert.ToInt32(item.Elements().ToList()[22].Value), Date = string.IsNullOrEmpty(item.Elements().ToList()[24].Value) ? (DateTime?)null : Convert.ToDateTime(item.Elements().ToList()[24].Value) }; lesson.Final = new Exam() { Mark = string.IsNullOrEmpty(item.Elements().ToList()[10].Value) ? (int?)null : item.Elements().ToList()[10].Value == "G" ? 0 : Convert.ToInt32(item.Elements().ToList()[10].Value), Date = string.IsNullOrEmpty(item.Elements().ToList()[12].Value) ? (DateTime?)null : Convert.ToDateTime(item.Elements().ToList()[12].Value) }; lesson.Integration = new Exam() { Mark = string.IsNullOrEmpty(item.Elements().ToList()[0].Value) ? (int?)null : item.Elements().ToList()[0].Value == "G" ? 0 : Convert.ToInt32(item.Elements().ToList()[0].Value), Date = string.IsNullOrEmpty(item.Elements().ToList()[4].Value) ? (DateTime?)null : Convert.ToDateTime(item.Elements().ToList()[4].Value) }; lesson.IntegrationRight = item.Elements().ToList()[2].Value == "true"; lessons.Add(lesson); } return(lessons); }
public UserObject ViewUser(string userId, UserObject.UserRole userRole) { try { string sqlSelect = $"SELECT u.[userId], u.[password], u.[roleId], u.[fName], u.[lName], u.[email], u.[phone] FROM user_tbl u WHERE userId = @UserId"; if (userRole != UserObject.UserRole.Instructor || userRole != UserObject.UserRole.Student) { throw new NullReferenceException(); } parameters = new List <ParameterList>(); UserObject user = null; switch (userRole) { case UserObject.UserRole.Instructor: user = new InstructorObject(); break; case UserObject.UserRole.Student: user = new StudentObject(); break; default: break; } parameters.Add(new ParameterList() { Key = "@UserId", Value = userId }); adminDataAccess = new DataAccess(); Task <DataTable> task = Task.Run(() => adminDataAccess.GetDataAsync(sqlSelect, parameters)); user.UserId = task.Result.Columns["userId"].ToString(); user.Password = task.Result.Columns["password"].ToString(); user.userRole = (UserObject.UserRole)Convert.ToInt32(task.Result.Columns["roleId"]); user.FirstName = task.Result.Columns["fName"].ToString(); user.LastName = task.Result.Columns["lName"].ToString(); user.Email = task.Result.Columns["email"].ToString(); user.Phone = task.Result.Columns["phone"].ToString(); if (user == null) { throw new NullReferenceException(); } else { return(user); } } catch (Exception ex) { throw; } }
internal static List <Graduation> GetGraduation(StudentObject studentObject) { var student = new Student(); student.Id = studentObject.Id; student.Password = studentObject.Password; return(student.GetGraduation()); }
internal static List <Document> GetDocuments(StudentObject studentObject) { var student = new Student(); student.Id = studentObject.Id; student.Password = studentObject.Password; return(student.GetDocuments()); }
internal static List <Program> GetPrograms(StudentObject studentObject) { var student = new Student(); student.Id = studentObject.Id; student.Password = studentObject.Password; return(student.GetPrograms()); }
static void Main(string[] args) { LW.InitLog(); LW.SetLogLevel(LogLevel.Dbg); DataBaseOperation.InitialiseClient(); LW.D(DataBaseOperation.QuerySingleData(new DBQuery().WhereEqualTo("realname", "刘浩宇"), out UserObject me)); LW.D(me); ClassObject co = new ClassObject() { CDepartment = "学部", CGrade = "1年级", CNumber = "5班", TeacherID = me.ObjectId }; LW.D(DataBaseOperation.CreateData(ref co)); me.ClassList.Add(co.ObjectId); LW.D(co); SchoolBusObject bo = new SchoolBusObject() { BusName = "校车方向1", TeacherID = me.ObjectId }; LW.D(DataBaseOperation.CreateData(ref bo)); LW.D(bo); for (int cn = 1; cn < 40; cn++) { StudentObject stu = new StudentObject() { BusID = bo.ObjectId, ClassID = co.ObjectId, Sex = "M", StudentName = "学生-" + cn.ToString("000"), AHChecked = false, CSChecked = false, LSChecked = false }; LW.D(DataBaseOperation.CreateData(ref stu)); LW.D(stu); if (cn < 21) { me.ChildList.Add(stu.ObjectId); } } me.HeadImagePath = "liuhaoyu.gif"; LW.D(DataBaseOperation.UpdateData(ref me)); LW.D(me); }
public void Student_InsertIntoOfflineServerSync(StudentObject objStuTemp) { eTrainingOfflineEntities db = new Common().getTrainingOfflineCenterInfo(); db.SP_Student_InsertIntoOfflineServerSync(objStuTemp.Id, objStuTemp.FirstName, objStuTemp.LastName, objStuTemp.FullName, objStuTemp.Sex, objStuTemp.DateBirthday, objStuTemp.Mobile, objStuTemp.Email, objStuTemp.Address, objStuTemp.DateCreate, objStuTemp.DateLastUpdate, objStuTemp.Description, objStuTemp.CourseId, objStuTemp.StatusId, objStuTemp.UserId); }
private void TouchesEnded(Vector3 position) { touchPosWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y); RaycastHit2D[] hitInformation = Physics2D.RaycastAll(touchPosWorld2D, Camera.main.transform.forward); bool isWrong = true; Vector3 posBuffer = draggingObject.gameObject.transform.position; // Verificação se eu soltei o objeto em cima do lugar que eu deveria soltar. foreach (RaycastHit2D hit in hitInformation) { if (draggingObject.target != null && hit.transform.gameObject == draggingObject.target) { StudentObject interactable = draggingObject.target.GetComponent <StudentObject>(); interactable.owner.status = StudentStatus.Neutral; draggingObject.owner.status = StudentStatus.Chaotic; draggingObject.owner.timer = GameManager.GetSharedInstance().stealInTime; PlayerActionFeedback tick1 = PlayerActionFeedback.GetNewPlayerActionFeedback(interactable.owner.myDesk.transform); PlayerActionFeedback tick2 = PlayerActionFeedback.GetNewPlayerActionFeedback(draggingObject.owner.myDesk.transform); tick1.transform.localScale = new Vector3(0.2f, 0.2f, 1); tick2.transform.localScale = new Vector3(0.2f, 0.2f, 1); tick1.ShowCorrect(); tick2.ShowCorrect(); draggingObject.target.SetActive(false); draggingObject.gameObject.SetActive(false); isWrong = false; } } if (isWrong) { GameObject go = new GameObject("TheEmptyOne"); PlayerActionFeedback tick1 = PlayerActionFeedback.GetNewPlayerActionFeedback(go.transform); // tick1.transform.position = transform.position; go.transform.position = new Vector3(posBuffer.x, posBuffer.y - 0.4f, 0); tick1.transform.localScale = new Vector3(0.09f, 0.09f, 1); tick1.ShowWrong(); } isDragging = false; }
internal static Student GetStudent(StudentObject studentObject) { var student = new Student(); student.Id = studentObject.Id; student.Password = studentObject.Password; student.Programs = student.GetPrograms(); student.Graduation = student.GetGraduation(); student.Documents = student.GetDocuments(); return(student); }
private void TouchesBegin(Vector3 position) { touchPosWorld = Camera.main.ScreenToWorldPoint(position); Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y); RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward); if (hitInformation.collider != null && hitInformation.transform.gameObject.tag == "Stolen") { isDragging = true; draggingObject = hitInformation.transform.gameObject.GetComponent <StudentObject>(); } }
public static RequestObject GetDocuments(string studentId, string password) { var requestObject = new RequestObject(); requestObject.Type = RequestType.GetDocuments; var studentObject = new StudentObject(); studentObject.Id = studentId; studentObject.Password = password; requestObject.Student = studentObject; return(requestObject); }
public ViewStudentInfo(int parentsCount, bool classFound, bool classTeacherFound, bool busFound, bool busTeacherFound, StudentObject student, ClassObject @class, UserObject CTeacher, UserObject[] Parents, SchoolBusObject schoolbus, UserObject BTeacher, bool StudentFound) { ParentsCount = parentsCount; ClassFound = classFound; ClassTeacherFound = classTeacherFound; BusFound = busFound; BusTeacherFound = busTeacherFound; _student = student; _class = @class; _CTeacher = CTeacher; _Parents = Parents; _schoolbus = schoolbus; _BTeacher = BTeacher; this.StudentFound = StudentFound; }
public void SpawnObject(int textureIndex) { GameObject go = Instantiate(prefab); go.transform.SetParent(gameObject.transform); go.transform.localPosition = new Vector3(0, 0.35f, 0); objectInPlace = go.GetComponent <StudentObject>(); objectInPlace.originalPlace = go.transform.localPosition; objectInPlace.ChangeTexture(textureIndex); objectInPlace.SetAlpha(0.4f); // objectInPlace.transform.localScale = new Vector3(0.2f, 0.2f, 1); objectInPlace.gameObject.SetActive(false); }
public static byte[] ObjectToByteArray(StudentObject student) { using (MemoryStream ms = new MemoryStream()) { BinaryWriter bw = new BinaryWriter(ms); bw.Write("Add To Student Database"); bw.Write(student.Firstname); bw.Write(student.Lastname); bw.Write(student.Grade); bw.Write(student.Age); bw.Write(student.Gender); bw.Write(student.Gpa); return(ms.ToArray()); } }
// Update is called once per frame void Update() { ProcessInput(); // Se eu estou arrastando algo, esse algo tem que crescer e sair de baixo do meu dedo. if (isDragging && draggingObject != null) { draggingObject.Grow(); draggingObject.gameObject.transform.position = new Vector3(touchPosWorld.x, touchPosWorld.y + 0.7f, 0); } // Mas ele tem que voltar a ser algo normal caso eu deixe de arrastar algo. else if (!isDragging && draggingObject != null) { draggingObject.ResetPosition(); draggingObject.ResetSize(); draggingObject = null; } }
public List <StudentObject> GetOffline() { List <StudentObject> listStudentOffline = new List <StudentObject>(); ConnectionEntities objConEn = new ConnectionEntities(); eTrainingOfflineEntities objConnEntitiesOff = objConEn.getTrainingCenterOff(); var listTempOffline = objConnEntitiesOff.SP_Student_GetOfflineStudentFromLast3days(); foreach (var item in listTempOffline) { StudentObject objS = new StudentObject(item.Id, item.FirstName, item.LastName, item.FullName, item.Sex, item.DateBirthday, item.Mobile, item.Email, item.Address, item.DateCreate, item.DateLastUpdate, item.Description, item.CourseId, item.StatusId, item.UserId); listStudentOffline.Add(objS); } return(listStudentOffline); }
private static List <Period> getPeriodss(StudentObject studentObject, int programCode) { var periods = new List <Period>(); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("StudentNo", studentObject.Id); parameters.Add("pass", studentObject.Password); string html = GetString("Filtering", parameters).Replace("a:", ""); XElement root = XElement.Parse(html); root = root.Elements().FirstOrDefault(); root = root.Elements().FirstOrDefault(); foreach (var yil in root.Elements().ToList()[3].Elements()) { foreach (var donem in root.Elements().ToList()[1].Elements()) { string periodName = donem.Elements().ToList()[0].Value.Tidy(); int periodCode = Convert.ToInt32(donem.Elements().ToList()[1].Value); string year = yil.Elements().ToList()[0].Elements().ToList()[0].Value; int yearCode = Convert.ToInt32(yil.Elements().ToList()[0].Elements().ToList()[1].Value); var period = new Period(); period.Code = periodCode; period.Name = periodName; period.Year = year; period.YearCode = yearCode; period.ProgramCode = programCode; period.Lessons = getLessonss(studentObject, programCode, yearCode, periodCode); if (period.Lessons.Any()) { periods.Add(period); } } } return(periods); }
public void ObjectInstruction(byte[] buffer) { using (MemoryStream ms = new MemoryStream(buffer)) { BinaryReader br = new BinaryReader(ms); string instruct = br.ReadString(); if (instruct == "Login") { LoginObject info = new LoginObject(); info.Username = br.ReadString(); info.Password = br.ReadString(); socket.Send(StringToByteArrayForLogin(ValidateLogin.ValidateCredentials(info))); Console.WriteLine("\nSent Acknowledgement"); } else if (instruct == "Add To Student Database") { StudentObject student = new StudentObject(); student.Firstname = br.ReadString(); student.Lastname = br.ReadString(); student.Grade = br.ReadString(); student.Age = br.ReadString(); student.Gender = br.ReadString(); student.Gpa = br.ReadString(); socket.Send(StringToByteArrayForLogin(AddStudent.AddStuTODB(student))); } else if (instruct == "Add To Faculty Database") { FacultyObject faculty = new FacultyObject(); faculty.Firstname = br.ReadString(); faculty.Lastname = br.ReadString(); faculty.Age = br.ReadString(); faculty.Gender = br.ReadString(); faculty.Class = br.ReadString(); socket.Send(StringToByteArrayForLogin(AddFaculty.AddFacTODB(faculty))); } } }
public List <StudentObject> GetListFromWebIMIC() { List <StudentObject> listStudentFromWeb = new List <StudentObject>(); ConnectionEntities objConEn = new ConnectionEntities(); WEBIMICDBEntities objStudenWeb = objConEn.getWebImic(); var listTempOffline = objStudenWeb.WEB_IMIC_SP_RegisterDetail_GetForEtraining(); foreach (var item in listTempOffline) { string[] Chuoi_Tach = item.FullName.Split(' '); string FirstName = Chuoi_Tach[Chuoi_Tach.Length - 1]; string LastName = ""; bool flag = true; for (int i = 0; i < Chuoi_Tach.Length - 1; i++) { if (flag) { LastName += Chuoi_Tach[i]; flag = false; } else { LastName += " " + Chuoi_Tach[i]; } } string Description = "[From Web]" + item.Message; int id = 0; StudentObject objS = new StudentObject(id, FirstName, LastName, item.FullName, 0, item.CreatedTime, item.Phone, item.Email, item.Address, item.CreatedTime, item.CreatedTime, Description, 41, 1, 1); listStudentFromWeb.Add(objS); objStudenWeb.WEB_IMIC_SP_RegisterDetail_UpdateIsSeen(item.RegisterDetailId); } return(listStudentFromWeb); }
internal static Student getStudentt(StudentObject studentObject) { var student = new Student(); student.Id = studentObject.Id; student.Password = studentObject.Password; Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("StudentNo", student.Id); parameters.Add("pass", student.Password); string html = GetString("StudentLogin", parameters).Replace("a:", ""); XElement root = XElement.Parse(html); root = root.Elements().FirstOrDefault(); root = root.Elements().FirstOrDefault(); student.Name = root.Elements().ToList()[0].Value.Tidy() + " " + root.Elements().ToList()[6].Value.Tidy(); student.Programs = getProgramss(student); student.Graduation = student.GetGraduation(); student.Documents = student.GetDocuments(); return(student); }
static void Main(string[] args) { L.InitLog(); XConfig.LoadConfig("XConfig.conf"); DataBaseOperation.InitialiseClient(); UserObject me = new UserObject() { HeadImagePath = "liuhaoyu.gif", Password = "", PhoneNumber = "18632738306", Sex = "M", UserGroup = new UserGroup(true, true, true, true), UserName = "******", Precision = 3, RealName = "刘浩宇", CurrentPoint = new System.Drawing.PointF(0, 0) }; L.D(DataBaseOperation.CreateData(ref me).Stringify()); //L.D(DataBaseOperation.QuerySingle(new DBQuery().WhereEqualTo("UserName", "liuhaoyu"), out UserObject me).ToString()); L.D(me.Stringify()); string[] dePartMent = { "小学", "初中", "普高", "中加", "剑桥" }; string[] namelist = { "钟天泽", "刑从珊", "牟绮南", "陈绮琴", "柯良俊", "伦腾骏", "闪安梦", "浑诗霜", "晁振华", "李易绿", "咎鸿宝", "士芳茵", "隗依晨", "宿德庸", "夏侯清嘉", "乜白亦", "出依波", "邬天青", "惠秋月", "次兴言", "支嘉珍", "枝承嗣", "濮阳亦绿", "革湛英", "韶琼思", "是觅晴", "抄念之", "泉觅翠", "道德元", "貊依丝", "邶芳春", "贺问梅", "蒉晨濡", "鞠德曜", "蔺暄文", "业英悟", "应芳泽", "苦飞双", "欧锦欣", "第五语梦", "悉晓燕", "保鸿畴", "乌孙思懿", "许天蓝", "亥乐水", "邱雅寒", "阿新蕾", "植叶欣", "图门昊伟", "万娅欣", "夕运凯", "高香芹", "夙成周", "狄访风", "无君昊", "温阳焱", "宋合乐", "苑梦蕊", "徭烨磊", "令狐晴岚", "佟佳湛芳", "赫连安珊", "郁阳曦", "迮姝美", "伏觅双", "苍正雅", "冼和硕", "平子珍", "子车晨潍", "危清婉", "九思松", "太叔冬灵", "宏宛亦", "错淑君", "奈明明", "冉盼夏", "嘉水冬", "建永福", "党瑾瑶", "信孤晴", "訾萧曼", "零向真", "风英韶", "后开畅", "凭桃雨", "苏高峯", "让绿蝶", "盛文林", "范绿兰", "施胤雅", "卓安萱", "辜元正", "肖自强", "舒畅然", "公良幻梅", "丹星纬", "堵博易", "虎坚秉", "甲玉泽", "孟竹月", "詹彩萱" }; List <ClassObject> classList = new List <ClassObject>(); List <SchoolBusObject> busList = new List <SchoolBusObject>(); for (int i = 1; i < 16; i++) { ClassObject @class = new ClassObject() { CDepartment = dePartMent[RandomInt(0, 3)], CGrade = RandomInt(1, 14) + "年级", CNumber = RandomInt(1, 8) + "班", TeacherID = me.ObjectId }; L.D(DataBaseOperation.CreateData(ref @class).ToString()); L.D(@class.Stringify()); classList.Add(@class); } string[] places = { "城镇", /*"莆陂", "城阜", "泉州", "上庄", "辰洞" */ }; foreach (var item in places) { SchoolBusObject bo = new SchoolBusObject() { BusName = item, TeacherID = me.ObjectId, BigWeekOnly = RandomBool, AHChecked = false, CSChecked = false, LSChecked = false }; L.D(DataBaseOperation.CreateData(ref bo).ToString()); L.D(bo.Stringify()); busList.Add(bo); } foreach (var item in namelist) { StudentObject stu = new StudentObject() { BusID = busList[RandomInt(0, busList.Count)].ObjectId, ClassID = classList[RandomInt(0, classList.Count)].ObjectId, Sex = RandomBool ? "M" : "F", StudentName = item, AHChecked = false, CSChecked = false, LSChecked = false, TakingBus = true, WeekType = (StudentBigWeekMode)RandomInt(0, 3), DirectGoHome = (DirectGoHomeMode)RandomInt(0, 3) }; L.D(DataBaseOperation.CreateData(ref stu).ToString()); L.D(stu.Stringify()); bool sexParent = RandomBool; UserObject user = new UserObject() { Sex = sexParent ? "M" : "F", ChildList = new List <string>() { stu.ObjectId }, PhoneNumber = "00000000000", RealName = stu.StudentName + "的" + (sexParent ? "爸爸" : "妈妈"), UserGroup = new UserGroup(false, false, false, true), UserName = "******" + stu.ObjectId, HeadImagePath = "" }; L.D(DataBaseOperation.CreateData(ref user).ToString()); L.D(user.Stringify()); if (RandomBool) { if (stu != null) { me.ChildList.Add(stu.ObjectId); } } } me.HeadImagePath = "liuhaoyu.gif"; me.ClassList.Add(classList[RandomInt(0, classList.Count)].ObjectId); L.D(DataBaseOperation.UpdateData(ref me).ToString()); L.D(me.Stringify()); DatabaseSocketsClient.KillConnection(); return; }
public Task SendStudentInfo(StudentObject student) => Clients.All.SendStudentInfo(student);
private void OpenExcel(object sender, EventArgs e) { if (CurrentClass == null) { MessageBox.Show("请先加载一个班级~", "操作不对……"); return; } statusPanel.Visible = true; statusLabel.Text = "正在打开Excel...."; DoLog(statusLabel.Text); Application.DoEvents(); ExcelApplication _Excel = new ExcelApplication(); statusLabel.Text = "请选择Excel文档"; DoLog(statusLabel.Text); Application.DoEvents(); OpenExcelFileDialog.FileName = ""; OpenExcelFileDialog.ShowDialog(); if (OpenExcelFileDialog.FileName == "") { statusPanel.Visible = false; return; } ExcelFilePath = OpenExcelFileDialog.FileName; ExcelFilePathTxt.Text = ExcelFilePath; //Excel.OpenExcelApp(); statusLabel.Text = "正在读取Excel文件,请稍等......"; DoLog(statusLabel.Text); Application.DoEvents(); if (!_Excel.OpenExcelFile(ExcelFilePath, true, false)) { MessageBox.Show("打开Excel文件失败!请查看Log文件!"); statusPanel.Visible = false; return; } statusLabel.Text = "获取文件长度......"; DoLog(statusLabel.Text); Application.DoEvents(); int LastLine = _Excel.LastLine(1, 100); if (LastLine == -1) { MessageBox.Show("读取Excel文件出现问题:无法获取文件长度"); statusPanel.Visible = false; return; } string StuName, StuDirection; for (int LineNum = 4; LineNum <= (LastLine - 1); LineNum++) { bool IsUpdate = false; StuName = _Excel.ReadContent <string>(LineNum, 1); StuDirection = _Excel.ReadContent <string>(LineNum, 2); foreach (DataGridViewRow item in StudentData.Rows) { statusLabel.Text = $"更新现有数据:{StuName}"; DoLog(statusLabel.Text); Application.DoEvents(); //IList<StudentObject> students = ((IList<StudentObject>)studentDataBindSourc.List).TakeWhile(new Func<StudentObject, int, bool>((stu, num) => { return stu.StudentName == StuName; })).ToList(); //UNKNOWN CHANGE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (string.IsNullOrEmpty((string)item.Cells[1].Value) && (string)item.Cells[1].Value == StuName) { item.Cells[1].Value = StuName; item.Cells[2].Value = StuDirection; IsUpdate = true; break; } } if (!IsUpdate) { statusLabel.Text = $"添加新数据:{StuName}"; DoLog(statusLabel.Text); Application.DoEvents(); StudentObject student = new StudentObject(); student.StudentName = StuName; student.ClassID = CurrentClass.ObjectId; if (BusDataPair.ContainsKey(StuDirection)) { student.BusID = BusDataPair[StuDirection]; } else { MessageBox.Show("校车数据库中找不到学生乘坐的校车名:" + StuDirection); } studentDataBindSourc.Add(student); } } statusLabel.Text = $"正在释放Excel......"; DoLog(statusLabel.Text); Application.DoEvents(); GC.Collect(); _Excel.QuitExcel(); statusPanel.Visible = false; }
//private void StuPartOS_SelectedIndexChanged(object sender, EventArgs e) //{ // ClassYear.Items.Clear(); // switch (ClassPartOS.Text) // { // case "小学部": // ClassYear.Items.AddRange(new string[] { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级" }); // break; // case "初中部": // ClassYear.Items.AddRange(new string[] { "初一", "初二", "初三" }); // break; // case "普通高中部": // case "中加高中部": // ClassYear.Items.AddRange(new string[] { "高一", "高二", "高三" }); // break; // case "剑桥高中部": // ClassYear.Items.AddRange(new string[] { "Year 10", "Year 11", "Year 12", "Year 13" }); // break; // default: // ClassYear.Items.Add("请选择学部"); // break; // } // ClassYear.SelectedIndex = 0; //} #endregion private void SureAndUpload(object sender, EventArgs e) { statusPanel.Visible = true; for (int index = 0; index < StudentData.Rows.Count - 1; index++) { DoLog("正在校验数据完整性"); statusLabel.Text = $"正在检测数据完整性......第{index}项,共{StudentData.Rows.Count - 2}项"; DoLog("数据完整性校验完成"); Application.DoEvents(); DataGridViewRow StuRow = StudentData.Rows[index]; StuRow.DefaultCellStyle.BackColor = Color.White; StuRow.DefaultCellStyle.ForeColor = Color.Black; if (string.IsNullOrEmpty((string)StuRow.Cells[2].Value) && string.IsNullOrEmpty((string)StuRow.Cells[3].Value)) { MessageBox.Show("这一行:" + StuRow.Cells[1].Value.ToString() + "还没有填写完整!"); return; } } statusLabel.Text = $"正在确认上传"; Application.DoEvents(); switch (MessageBox.Show("上传会改写已经存在的项,并且将重置学生签到信息,是否继续?", "提示", MessageBoxButtons.YesNo)) { case DialogResult.Yes: break; case DialogResult.No: default: statusLabel.Text = $"上传数据已取消!"; DoLog(statusLabel.Text); Thread.Sleep(1000); statusPanel.Visible = false; return; break; } foreach (DataGridViewRow StuRow in StudentData.Rows) { statusLabel.Text = $"正在处理校车ID"; DoLog(statusLabel.Text); Application.DoEvents(); //Combo Box is valueD, use the 2nd cell if (!string.IsNullOrEmpty((string)StuRow.Cells[2].Value)) { if (BusDataPair.ContainsKey((string)StuRow.Cells[2].Value)) { StuRow.Cells[3].Value = BusDataPair[(string)StuRow.Cells[2].Value]; } else { MessageBox.Show($"在数据库中找不到匹配的校车信息: {(string)StuRow.Cells[2].Value}"); } } else { //Nothing to do for NOT GIVEN student Bus Direction } } statusLabel.Text = $"分配数据空间...."; DoLog(statusLabel.Text); Application.DoEvents(); StudentObject StudentObj = new StudentObject(); StudentObj.CSChecked = false; StudentObj.LSChecked = false; StudentObj.AHChecked = false; this.Enabled = false; statusLabel.Text = $"开始上传...."; DoLog(statusLabel.Text); this.SureAndUploadBtn.Text = "上传中..."; Application.DoEvents(); List <string> ErrDetail = new List <string>(); for (int RowNum = 0; RowNum < (StudentData.RowCount - 1); RowNum++) { StudentObj.StudentName = (string)StudentData.Rows[RowNum].Cells[1].Value; StudentObj.BusID = (string)StudentData.Rows[RowNum].Cells[3].Value; StudentObj.ClassID = CurrentClass.ObjectId; statusLabel.Text = $"正在上传第{RowNum}项,共{StudentData.RowCount - 2}项。"; DoLog("学生姓名:" + StudentObj.StudentName); Application.DoEvents(); //If Record is NOT in the Server Database, SHOWN AS NO "OBJECT ID" GIVEN if (string.IsNullOrEmpty((string)StudentData.Rows[RowNum].Cells[0].Value)) { if (Database.DataBaseOperation.CreateData(ref StudentObj) == DBQueryStatus.ONE_RESULT) { statusLabel.Text = $"正在上传第{RowNum}项,共{StudentData.RowCount - 2}项,完成!"; Application.DoEvents(); StudentData.Rows[RowNum].DefaultCellStyle.BackColor = Color.Green; continue; } else { statusLabel.Text = $"正在上传第{RowNum}项,共{StudentData.RowCount - 2}项,出错!"; StudentData.Rows[RowNum].DefaultCellStyle.BackColor = Color.Red; StudentData.Rows[RowNum].DefaultCellStyle.ForeColor = Color.White; } } //Record is in the Database, only update needed else { StudentObj.ObjectId = (string)StudentData.Rows[RowNum].Cells[0].Value; if (Database.DataBaseOperation.UpdateData(ref StudentObj) == 0) { statusLabel.Text = $"正在上传第{RowNum}项,共{StudentData.RowCount - 2}项,完成!"; StudentData.Rows[RowNum].DefaultCellStyle.BackColor = Color.LawnGreen; Application.DoEvents(); continue; } else { statusLabel.Text = $"正在上传第{RowNum}项,共{StudentData.RowCount - 2}项,出错!"; StudentData.Rows[RowNum].DefaultCellStyle.BackColor = Color.Red; StudentData.Rows[RowNum].DefaultCellStyle.ForeColor = Color.White; } } } statusLabel.Text = $"上传操作完成,正在处理后续工作。"; Application.DoEvents(); if (ErrDetail.Count == 0) { DoLog("成功完成操作!已经上传 " + (StudentData.RowCount - 1).ToString() + " 条数据"); MessageBox.Show("所有项目已经成功上传!"); } else { DoLog("上传部分失败!共 " + ErrDetail.Count.ToString() + " 条失败"); string ErrMsg = "\r\n"; foreach (string item in ErrDetail) { ErrMsg = ErrMsg + item; } LW.E("Error when updating these students data: " + ErrMsg); MessageBox.Show("有部分内容上传失败,它们是:" + ErrMsg + "请尝试重新上传"); } this.SureAndUploadBtn.Text = "确认并上传(&S)"; statusPanel.Visible = false; this.Enabled = true; }
public JsonResult GET(string BusID, string SignData, string Data) { //THIS FUNCTION IS SHARED BY BUSTEACHER AND PARENTS if (!ValidateSession()) { return(SessionError); } if (!(CurrentUser.UserGroup.IsParent || CurrentUser.UserGroup.IsBusManager || CurrentUser.UserGroup.IsAdmin)) { return(UserGroupError); } string str = Encoding.UTF8.GetString(Convert.FromBase64String(Data)); if (str.Contains(";") && str.Split(';').Length != 5) { return(RequestIllegal); } string[] p = str.Split(';'); string SType = p[0]; string SValue = p[1]; //P[2] = SALT string TeacherID = p[3]; string StudentID = p[4]; if (Cryptography.SHA256Encrypt(SValue + p[2] + ";" + SType + BusID + TeacherID) != SignData) { return(RequestIllegal); } DBQuery busFindQuery = new DBQuery(); busFindQuery.WhereEqualTo("objectId", BusID); busFindQuery.WhereEqualTo("TeacherObjectID", TeacherID); switch (DataBaseOperation.QueryMultipleData(busFindQuery, out List <SchoolBusObject> BusList)) { case DBQueryStatus.INTERNAL_ERROR: return(InternalError); case DBQueryStatus.NO_RESULTS: return(DataBaseError); default: if (BusList.Count == 1 && BusList[0].ObjectId == BusID && BusList[0].TeacherID == TeacherID) { DBQuery _stuQuery = new DBQuery(); _stuQuery.WhereEqualTo("objectId", StudentID); _stuQuery.WhereEqualTo("BusID", BusID); switch (DataBaseOperation.QueryMultipleData(_stuQuery, out List <StudentObject> StuList)) { case DBQueryStatus.INTERNAL_ERROR: return(InternalError); case DBQueryStatus.NO_RESULTS: return(DataBaseError); default: if (!bool.TryParse(SValue, out bool Value)) { return(RequestIllegal); } StudentObject stu = StuList[0]; if (SType.ToLower() == "leave") { stu.LSChecked = Value; } else if (SType.ToLower() == "pleave") { stu.AHChecked = Value; } else if (SType.ToLower() == "come") { stu.CSChecked = Value; } else { return(RequestIllegal); } if (DataBaseOperation.UpdateData(ref stu) == DBQueryStatus.ONE_RESULT) { Dictionary <string, string> dict = stu.ToDictionary(); dict.Add("ErrCode", "0"); dict.Add("ErrMessage", "null"); dict.Add("SignMode", SType); dict.Add("SignResult", Value.ToString()); dict.Add("Updated", DateTime.Now.ToString()); return(Json(dict)); } else { return(InternalError); } } } else { return(RequestIllegal); } } }