//public IActionResult Profile() //{ // var model = repository.GetRecords(); // return View(model); //} //public IActionResult UploadPic(VolunteerRecord record) //{ // repository.SaveRecord(record); // UploadImage(record); // return RedirectToAction("Profile"); //} public void UploadImage(VolunteerRecord record) { if (record.RecordID > 0) { foreach (var file in Request.Form.Files) { var img = new Image { RecordID = record.RecordID, ImageTitle = file.FileName }; using (var ms = new MemoryStream()) { file.CopyTo(ms); img.ImageData = ms.ToArray(); ms.Close(); ms.Dispose(); } repository.SaveImage(img); } TempData["message"] = "Image(s) stored in database!"; } else { TempData["message"] = "Cannot add images to a non existent product!"; } }
/// <summary> /// 儲存 /// </summary> private void buttonX1_Click(object sender, EventArgs e) { int x = 1; DSXmlHelper dsx = new DSXmlHelper("xml"); foreach (DataGridViewRow row in dataGridViewX1.Rows) { if (row.IsNewRow) { continue; } foreach (DataGridViewCell cell in row.Cells) { if (cell is DataGridViewComboBoxExCell) { string name = "" + cell.Value; if (ClubDic.ContainsKey(name)) { CLUBRecord cr = ClubDic[name]; dsx.AddElement("Club"); dsx.SetAttribute("Club", "Index", x.ToString()); dsx.SetAttribute("Club", "Ref_Club_ID", cr.UID); x++; } } } } List <string> list = K12.Presentation.NLDPanels.Student.SelectedSource; List <StudentRecord> StudentList = Student.SelectByIDs(list); List <VolunteerRecord> VolList = new List <VolunteerRecord>(); List <VolunteerRecord> DelList = _A.Select <VolunteerRecord>(string.Format("ref_student_id in ('{0}')", string.Join("','", list))); foreach (StudentRecord stud in StudentList) { VolunteerRecord Vol = new VolunteerRecord(); Vol.SchoolYear = integerInput1.Value; Vol.Semester = integerInput2.Value; Vol.RefStudentID = stud.ID; Vol.Content = dsx.BaseElement.OuterXml; VolList.Add(Vol); } _A.DeletedValues(DelList); //清掉選擇學生的社團記錄 _A.InsertValues(VolList); //新增 MsgBox.Show("儲存完成!!"); }
/// <summary> /// 排序2個學生 /// </summary> private int SortByStudent(VolunteerRecord vr1, VolunteerRecord vr2) { if (StudentDic.ContainsKey(vr1.RefStudentID) && StudentDic.ContainsKey(vr2.RefStudentID)) { StudentRecord sr1 = StudentDic[vr1.RefStudentID]; StudentRecord sr2 = StudentDic[vr2.RefStudentID]; return(SortClassIndex.SortStudentDouble(sr1, sr2)); } else { return(0); } }
/// <summary> /// 全校亂數選社 /// </summary> private void buttonX2_Click(object sender, EventArgs e) { //學生 List <StudentRecord> StudentList = new List <StudentRecord>(); foreach (StudentRecord each in Student.SelectAll()) { if (each.Status == StudentRecord.StudentStatus.一般 || each.Status == StudentRecord.StudentStatus.延修) { StudentList.Add(each); } } //亂數 RandomStudent <StudentRecord>(StudentList); List <VolunteerRecord> VolList = new List <VolunteerRecord>(); foreach (StudentRecord each in StudentList) { //亂數 RandomStudent <CLUBRecord>(ClubList); VolunteerRecord vr = new VolunteerRecord(); vr.RefStudentID = each.ID; vr.SchoolYear = integerInput1.Value; vr.Semester = integerInput2.Value; DSXmlHelper dsx = new DSXmlHelper("xml"); int x = 1; foreach (CLUBRecord club in ClubList) { if (學生選填志願數 >= x) { dsx.AddElement("Club"); dsx.SetAttribute("Club", "Index", x.ToString()); dsx.SetAttribute("Club", "Ref_Club_ID", club.UID); x++; } else { break; } } vr.Content = dsx.BaseElement.OuterXml; VolList.Add(vr); } _A.InsertValues(VolList); }
public void SaveRecord(VolunteerRecord record) { if (record.RecordID == 0) { _db.VolunteerRecords.Add(record); _db.SaveChanges(); } else { VolunteerRecord dbEntry = _db.VolunteerRecords .FirstOrDefault(p => p.RecordID == record.RecordID); if (dbEntry != null) { dbEntry.EventName = record.EventName; dbEntry.Notes = record.Notes; _db.SaveChanges(); } } }
//覆寫 public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard) { #region 志願數 int 學生選填志願數 = GetVolunteerData.GetVolumnteerCount(); StudentDic = new Dictionary <string, StudentRecord>(); #endregion //Dictionary<string, int> IndexDic = new Dictionary<string, int>(); //int j = 1; List <string> FieldList = new List <string>(); FieldList.Add("學年度"); //目前欄位 FieldList.Add("學期"); //目前欄位 for (int x = 1; x <= 學生選填志願數; x++) { FieldList.Add(string.Format("志願{0}", x)); //目前欄位 //IndexDic.Add(string.Format("志願{0}", x), j); //j++; } List <CLUBRecord> ClubList = tool._A.Select <CLUBRecord>(); Dictionary <string, CLUBRecord> CLUBDic = new Dictionary <string, CLUBRecord>(); foreach (CLUBRecord each in ClubList) { if (!CLUBDic.ContainsKey(each.UID)) { CLUBDic.Add(each.UID, each); } } //取得所選學生之社團志願序(學年度/學期/學生 為單位) wizard.ExportableFields.AddRange(FieldList); wizard.ExportPackage += (sender, e) => { List <VolunteerRecord> VolUnDic = GetVolunteerData.GetStudentVolunteerDic(e.List); //取得學生清單 List <StudentRecord> StudentList = Student.SelectByIDs(e.List); StudentList = SortClassIndex.K12Data_StudentRecord(StudentList); foreach (StudentRecord each in StudentList) { if (!StudentDic.ContainsKey(each.ID)) { StudentDic.Add(each.ID, each); } } VolUnDic.Sort(SortByStudent); for (int i = 0; i < VolUnDic.Count; i++) { #region MyRegion VolunteerRecord vr = VolUnDic[i]; RowData row = new RowData(); row.ID = VolUnDic[i].RefStudentID; if (!string.IsNullOrEmpty(vr.Content)) { Dictionary <string, string> dic = new Dictionary <string, string>(); DSXmlHelper dsx = new DSXmlHelper(); dsx.Load(vr.Content); foreach (XmlElement each in dsx.BaseElement.SelectNodes("Club")) { string index = each.GetAttribute("Index"); string clubID = each.GetAttribute("Ref_Club_ID"); if (CLUBDic.ContainsKey(clubID)) { if (!dic.ContainsKey("志願" + index)) { dic.Add("志願" + index, CLUBDic[clubID].ClubName); } } } foreach (string field in e.ExportFields) { if (wizard.ExportableFields.Contains(field)) { switch (field) { case "學年度": row.Add(field, "" + VolUnDic[i].SchoolYear); break; case "學期": row.Add(field, "" + VolUnDic[i].Semester); break; } if (dic.ContainsKey(field)) { row.Add(field, dic[field]); } } } } e.Items.Add(row); #endregion } }; }