public ActionResult Activity_Create(Act_pho ap1, HttpPostedFileBase photo) { //將檔案轉成二進位存進資料庫中 var imgSize = photo.ContentLength; byte[] imgByte = new byte[imgSize]; photo.InputStream.Read(imgByte, 0, imgSize); ap1.activity_photo.Activity_photo1 = imgByte; //product.BytesImage = imgByte; //新增到資料庫中 db.Activities.Add(ap1.activity); db.Activity_photo.Add(ap1.activity_photo); db.SaveChanges(); ap1.activity.Activity_Photo_id = ap1.activity_photo.Activity_photo_id; var q = db.Activity_photo.Select(n => n.Activity_photo_id).ToList().LastOrDefault(); var x = db.Activities.Select(c => c.Activity_Photo_id).ToList().LastOrDefault(); x = q; var a = db.Activities.Select(k => k.Activity_no).ToList().LastOrDefault(); var p = db.Activities.Find(a); db.Entry(p).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Activity_Browse")); }
private void Btn_pass_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = System.Windows.MessageBox.Show("確定成案?", "提示", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { VolunteerEntities dbContext = new VolunteerEntities(); var q = from a in dbContext.Abnormal_event where a.Abnormal_event_ID == Event_ID select a; var q2 = (from n in dbContext.Stages where n.Stage_type == "異常事件" && n.Stage1 == "成案審核" select n.Stage_ID).First(); foreach (var a in q) { a.Rejection_Reason = "NULL"; a.Stage = q2; } dbContext.SaveChanges(); this.Close(); } }
private void Btn_send_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = System.Windows.MessageBox.Show("確定駁回?", "提示", MessageBoxButton.OKCancel); VolunteerEntities dbContext = new VolunteerEntities(); var q = from a in dbContext.Abnormal_event where a.Abnormal_event_ID == Event_ID select a; var q2 = (from n in dbContext.Stages where n.Stage_type == "異常事件" && n.Stage1 == "駁回" select n.Stage_ID).First(); if (this.nopass_textbox.Text.Trim() == "") { System.Windows.MessageBox.Show("請填寫駁回原因"); } else { if (result == MessageBoxResult.OK) { foreach (var a in q) { a.Rejection_Reason = this.nopass_textbox.Text; a.Stage = q2; } dbContext.SaveChanges(); this.Close(); } } }
public void UpdateExperience(Experience_VM experience, string Filename) { VolunteerEntities dbContext = new VolunteerEntities(); var q = from n in dbContext.Experiences where n.Experience_no == experience.Experience_no select n; var q2 = (from n in dbContext.Volunteers where n.Chinese_name == experience.Volunteer select new { Volunteer_no = n.Volunteer_no }).First(); foreach (var row in q) { row.Experience1 = experience.Experience; row.Volunteer_no = q2.Volunteer_no; row.Experience_content = experience.Experience_content; if (!string.IsNullOrEmpty(Filename)) { row.Experience_photo = Filename; } row.Issued = false; row.Home_issued = false; } dbContext.SaveChanges(); }
private void btn_send_Click(object sender, RoutedEventArgs e) { VolunteerEntities dbContext = new VolunteerEntities(); var q = from a in dbContext.Abnormal_event where a.Abnormal_event_ID == Event_ID select a; if (this.tb_Volunteer.Text.Trim() == "" || this.tb_Supervisor.Text.Trim() == "" || (this.tb_result.Text.Trim() == "")) { MessageBox.Show("不可空白"); } else { if (MessageBox.Show("確定要送出嗎?", "送出", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { foreach (var a in q) { a.Stage = 11; a.Volunteer_description = this.tb_Volunteer.Text; a.Supervisor_description = this.tb_Supervisor.Text; a.Result = this.tb_result.Text; a.Closing_date = DateTime.Now; } dbContext.SaveChanges(); this.Close(); } } }
public void Insert_Volunteer_Service_period(Volunteer_Schedule_saveModel[] SM) { using (VolunteerEntities db = new VolunteerEntities()) { for (int i = 0; i < SM.Length; i += 1) { var stage_type = SM[i].GStage; if (stage_type != "續留") { var stage = (from s in db.Stages where s.Stage1 == stage_type && s.Stage_type == "排班意願" select s.Stage_ID).ToList(); Service_period2 sm = new Service_period2() { Volunteer_no = SM[i].Volunteer_no, Service_period_no = SM[i].Service_period_no, Srevice_group = SM[i].Srevice_group, Application_unit = SM[i].Application_unit, Stage = stage[0] }; db.Service_period2.Add(sm); } } db.SaveChanges(); } }
public void Insert_indexphoto(string Filename) { VolunteerEntities dbContext = new VolunteerEntities(); Indexphoto indexphoto = new Indexphoto(); indexphoto.Indexphoto1 = Filename; indexphoto.Issued = false; dbContext.Indexphotoes.Add(indexphoto); dbContext.SaveChanges(); }
public void Insert_indexvideolink(string Filename) { VolunteerEntities dbContext = new VolunteerEntities(); Indexvideolink indexvideolink = new Indexvideolink(); indexvideolink.Videolink = Filename; indexvideolink.Issued = false; dbContext.Indexvideolinks.Add(indexvideolink); dbContext.SaveChanges(); }
// PUT: api/Events/5 public HttpResponseMessage Put(string id, [FromBody] Event value) { try { using (VolunteerEntities entities = new VolunteerEntities()) { var entity = entities.Events.FirstOrDefault(e => e.eventID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "EventID " + id + " NOT FOUND")); } else { /* * entity.eventName = value.eventName; * entity.eventInfo = value.eventInfo; * entity.eventDate = value.eventDate; * entity.eventStartTime = value.eventStartTime; * entity.eventEndTime = value.eventEndTime; * entity.eventSetupTime = value.eventSetupTime; * entity.eventTeardownTime = value.eventTeardownTime; * entity.eventConcessionStartTime = value.eventConcessionStartTime; * entity.eventConcessionEndTime = value.eventConcessionEndTime; * entity.eventConcessionSlots = value.eventConcessionSlots; * entity.eventFrontDeskStartTime = value.eventFrontDeskStartTime; * entity.eventFrontDeskEndTime = value.eventFrontDeskEndTime; * entity.eventFrontDeskSlots = value.eventFrontDeskSlots; * entity.orgID = value.orgID; */ entities.Events.Remove(entity); entities.SaveChanges(); entities.Events.Add(value); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
// POST: api/Events public HttpResponseMessage Post([FromBody] Event value) { try { using (VolunteerEntities entities = new VolunteerEntities()) { entities.Events.Add(value); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, value); message.Headers.Location = new Uri(Request.RequestUri + value.eventID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult Issued(int id = 0) { Volunteer_Web.Models.Experience experience = dbContext.Experiences.Find(id); if (experience.Issued == true) { experience.Issued = false; } else { experience.Issued = true; } dbContext.SaveChanges(); return(RedirectToAction("Experience")); }
public void Updata_indexvideolink(int id) { VolunteerEntities dbContext = new VolunteerEntities(); var q = from n in dbContext.Indexvideolinks where n.Indexvideolink_no == id select n; foreach (var row in q) { if ((bool)row.Issued) { row.Issued = false; } else { row.Issued = true; } } dbContext.SaveChanges(); }
public void UpdateExperience_Home_issued(int id) { VolunteerEntities dbContext = new VolunteerEntities(); var q = from n in dbContext.Experiences where n.Experience_no == id select n; foreach (var row in q) { if ((bool)row.Home_issued) { row.Home_issued = false; } else { row.Home_issued = true; } } dbContext.SaveChanges(); }
// DELETE: api/Events/5 public HttpResponseMessage Delete(string id) { try { using (VolunteerEntities entities = new VolunteerEntities()) { var entity = entities.Events.FirstOrDefault(e => e.eventID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "EventID " + id + " NOT FOUND")); } else { entities.Events.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public void InsertExperience(Experience_VM _experience, string Filename) { VolunteerEntities dbContext = new VolunteerEntities(); int VolunteerNo = 0; foreach (var row in dbContext.Volunteers.Where(p => p.Chinese_name == _experience.Volunteer)) { VolunteerNo = row.Volunteer_no; } Experience experience = new Experience(); experience.Experience1 = _experience.Experience; experience.Volunteer_no = VolunteerNo; experience.Experience_content = _experience.Experience_content; experience.Experience_photo = Filename; experience.Issued = false; experience.Home_issued = false; dbContext.Experiences.Add(experience); dbContext.SaveChanges(); }
//按下修改表單後, 表單從volunteer資料讀取資料 //修改要修改的東西後 按"確認"按鈕 修改資料 private void Button_Click(object sender, RoutedEventArgs e) { // WLC DateTime myBirthDay = new DateTime(); DateTime myJoin_date = new DateTime(); DateTime myLeave_date = new DateTime(); if ((!string.IsNullOrEmpty(cbBirthDayYear.Text)) && (!string.IsNullOrEmpty(cbBirthDayMonth.Text)) && (!string.IsNullOrEmpty(cbBirthDayDay.Text))) { myBirthDay = DateTime.Parse(cbBirthDayYear.Text + "/" + cbBirthDayMonth.Text + "/" + cbBirthDayDay.Text); } if ((!string.IsNullOrEmpty(cbJoin_dateYear.Text)) && (!string.IsNullOrEmpty(cbJoin_dateMonth.Text)) && (!string.IsNullOrEmpty(cbJoin_dateDay.Text))) { myJoin_date = DateTime.Parse(cbJoin_dateYear.Text + "/" + cbJoin_dateMonth.Text + "/" + cbJoin_dateDay.Text); } if ((!string.IsNullOrEmpty(cbLeave_dateYear.Text)) && (!string.IsNullOrEmpty(cbLeave_dateMonth.Text)) && (!string.IsNullOrEmpty(cbLeave_dateDay.Text))) { myLeave_date = DateTime.Parse(cbLeave_dateYear.Text + "/" + cbLeave_dateMonth.Text + "/" + cbLeave_dateDay.Text); } VolunteerEntities dbContext = new VolunteerEntities(); //// System.Windows.Data.CollectionViewSource volunteerViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("volunteerViewSource"))); //dbContext.Volunteer.ToList(); //// volunteerViewSource.Source = dbContext.Volunteer.Local; //dbContext.Volunteer.Local.Add(new Volunteer var q = from a in dbContext.Volunteer where a.Volunteer_no == Volunteer_no select a; foreach (var a in q) { a.Chinese_name = txtChineseName.Text; a.English_name = txtEnglishName.Text; a.sex = cbsex.Text; a.birthday = myBirthDay; a.IDcrad_no = txtIDcrad_no.Text; a.Medical_record_no = txtMedical_record_no.Text; // WLC if (int.TryParse(cbIdentity_type.Text, out int Identity_type)) { a.Identity_type = Identity_type; } if (int.TryParse(txtSeniority.Text, out int Seniority)) { a.Seniority = Seniority; } a.Join_date = myJoin_date; a.Leave_date = myLeave_date; a.Leave_reason = cbLeaveReason.Text; if (int.TryParse(txtPhone_no.Text, out int Phone_no)) { a.Phone_no = Phone_no; } if (int.TryParse(txtMobile_no.Text, out int Mobile_no)) { a.Mobile_no = Mobile_no; } a.Vest_no = txtVest_no.Text; if (int.TryParse(txtPostal_code.Text, out int Postal_code)) { a.Postal_code = Postal_code; } a.Address = txtAddress.Text; a.Education = cbEducation.Text; if (int.TryParse(txtLssuing_unit_no.Text, out int Lssuing_unit_no)) { a.Lssuing_unit_no = Lssuing_unit_no; } a.Service_manual_no = txtService_manual_no.Text; a.Personality_scale = txtPersonality_scale.Text; a.Photo = imagebyte; } foreach (var n in AAA) { Expertise2 e1 = new Expertise2 { Volunteer_no = Volunteer_no, Expertise_no = n }; dbContext.Expertise2.Add(e1); } foreach (var n in AAA1) { var q1 = from de in dbContext.Expertise2 where de.Expertise_no == n && de.Volunteer_no == Volunteer_no select new { pk = de.Primary_key }; foreach (var x in q1) { Expertise2 ex = dbContext.Expertise2.Find(x.pk); dbContext.Expertise2.Remove(ex); } } foreach (var n in BBB) { Service_Group1 e1 = new Service_Group1 { Volunteer_no = Volunteer_no, Group_no = n }; dbContext.Service_Group1.Add(e1); } foreach (var n in BBB1) { var q1 = from de in dbContext.Service_Group1 where de.Group_no == n && de.Volunteer_no == Volunteer_no select new { pk = de.Primary_key }; foreach (var x in q1) { Service_Group1 ex = dbContext.Service_Group1.Find(x.pk); dbContext.Service_Group1.Remove(ex); } } try { dbContext.SaveChanges(); } catch { throw; } MessageBox.Show("修改成功"); }
//亞衡 ////加入一個靜態變數 用來存放當前加入的Volunteer //public static int _Volunteer_no; //從空白的表單 填完資料後 //最後按"確認"按鈕 新增資料 private void Button_Click1(object sender, RoutedEventArgs e) { // WLC DateTime myBirthDay = new DateTime(); DateTime myJoin_date = new DateTime(); DateTime myLeave_date = new DateTime(); if ((!string.IsNullOrEmpty(cbBirthDayYear.Text)) && (!string.IsNullOrEmpty(cbBirthDayMonth.Text)) && (!string.IsNullOrEmpty(cbBirthDayDay.Text))) { myBirthDay = DateTime.Parse(cbBirthDayYear.Text + "/" + cbBirthDayMonth.Text + "/" + cbBirthDayDay.Text); } if ((!string.IsNullOrEmpty(cbJoin_dateYear.Text)) && (!string.IsNullOrEmpty(cbJoin_dateMonth.Text)) && (!string.IsNullOrEmpty(cbJoin_dateDay.Text))) { myJoin_date = DateTime.Parse(cbJoin_dateYear.Text + "/" + cbJoin_dateMonth.Text + "/" + cbJoin_dateDay.Text); } if ((!string.IsNullOrEmpty(cbLeave_dateYear.Text)) && (!string.IsNullOrEmpty(cbLeave_dateMonth.Text)) && (!string.IsNullOrEmpty(cbLeave_dateDay.Text))) { myLeave_date = DateTime.Parse(cbLeave_dateYear.Text + "/" + cbLeave_dateMonth.Text + "/" + cbLeave_dateDay.Text); } int intIdentity_type = 0; int intPhone_no = 0; int intMobile_no = 0; int intPostal_code = 0; int intLssuing_unit_no = 0; int intSeniority = 0; if (int.TryParse(cbIdentity_type.Text, out int Identity_type)) { intIdentity_type = Identity_type; } if (int.TryParse(txtSeniority.Text, out int Seniority)) { intSeniority = Seniority; } if (int.TryParse(txtPhone_no.Text, out int Phone_no)) { intPhone_no = Phone_no; } if (int.TryParse(txtMobile_no.Text, out int Mobile_no)) { intMobile_no = Mobile_no; } if (int.TryParse(txtPostal_code.Text, out int Postal_code)) { intPostal_code = Postal_code; } if (int.TryParse(txtLssuing_unit_no.Text, out int Lssuing_unit_no)) { intLssuing_unit_no = Lssuing_unit_no; } VolunteerEntities dbContext = new VolunteerEntities(); // System.Windows.Data.CollectionViewSource volunteerViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("volunteerViewSource"))); dbContext.Volunteer.ToList(); // volunteerViewSource.Source = dbContext.Volunteer.Local; dbContext.Volunteer.Local.Add(new Volunteer { Chinese_name = txtChineseName.Text, English_name = txtEnglishName.Text, sex = cbsex.Text, birthday = myBirthDay, IDcrad_no = txtIDcrad_no.Text, Medical_record_no = txtMedical_record_no.Text, //WLC Identity_type = intIdentity_type, Seniority = intSeniority, Join_date = myJoin_date, Leave_date = myLeave_date, Leave_reason = cbLeaveReason.Text, Phone_no = intPhone_no, Mobile_no = intMobile_no, Vest_no = txtVest_no.Text, Postal_code = intPostal_code, Address = txtAddress.Text, Education = cbEducation.Text, Lssuing_unit_no = intLssuing_unit_no, Service_manual_no = txtService_manual_no.Text, Personality_scale = txtPersonality_scale.Text, Photo = imagebyte }); //dbContext.SaveChanges()後,會得到新的dbContext.Volunteer的Volunteer_no流水號 dbContext.SaveChanges(); //查詢 "新的dbContext.Volunteer的Volunteer_no流水號" 的那一筆 資料 var q = (from n in dbContext.Volunteer select new { n.Volunteer_no }).ToList().LastOrDefault(); foreach (var n in AAA) { Expertise2 e1 = new Expertise2 { Volunteer_no = q.Volunteer_no, Expertise_no = n }; dbContext.Expertise2.Add(e1); } foreach (var n in BBB) { Service_Group1 sg1 = new Service_Group1 { Volunteer_no = q.Volunteer_no, Group_no = n }; dbContext.Service_Group1.Add(sg1); } dbContext.SaveChanges(); MessageBox.Show("志工資料新增成功"); // int numberb=0; //foreach(var b in q ) //{ // numberb = b.Volunteer_no; //} //dbContext.Expertise2.ToList(); //dbContext.Expertise2.Local.Add(new Expertise2 //{ // Volunteer_no = numberb //}); //亞衡 連線 作法 找出volunteer_no========================================================================= //try //{ // using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Volunteer;Integrated Security=True")) // { // using (SqlCommand cmd = new SqlCommand()) // { // cmd.CommandText = "insert into [Volunteer].[Volunteer](Chinese_name,English_name,sex,birthday,IDcrad_no,Medical_record_no,Identity_type,Seniority,Join_date,Leave_date,Leave_reason,Phone_no,Mobile_no,Vest_no,Postal_code,Address,Education,Lssuing_unit_no,Service_manual_no,Personality_scale,Photo)" + // "values(@Chinese_name,@English_name,@sex,@birthday,@IDcrad_no,@Medical_record_no,@Identity_type,@Seniority,@Join_date,@Leave_date,@Leave_reason,@Phone_no,@Mobile_no,@Vest_no,@Postal_code,@Address,@Education,@Lssuing_unit_no,@Service_manual_no,@Personality_scale,@Photo);" + // "select Volunteer_no from [Volunteer].[Volunteer] where Volunteer_no=Scope_Identity()"; // cmd.Connection = conn; // cmd.Parameters.Add("@Chinese_name", SqlDbType.NVarChar).Value = txtChineseName.Text; // cmd.Parameters.Add("@English_name", SqlDbType.NVarChar).Value = txtEnglishName.Text; // cmd.Parameters.Add("@sex", SqlDbType.NChar).Value = cbsex.Text; // cmd.Parameters.Add("@birthday", SqlDbType.DateTime).Value = myBirthDay; // cmd.Parameters.Add("@IDcrad_no", SqlDbType.NVarChar).Value = txtIDcrad_no.Text; // cmd.Parameters.Add("@Medical_record_no", SqlDbType.NChar).Value = txtMedical_record_no.Text; // cmd.Parameters.Add("@Identity_type", SqlDbType.Int).Value = intIdentity_type; // cmd.Parameters.Add("@Seniority", SqlDbType.Int).Value = intSeniority; // cmd.Parameters.Add("@Join_date", SqlDbType.Date).Value = myJoin_date; // cmd.Parameters.Add("@Leave_date", SqlDbType.Date).Value = myLeave_date; // cmd.Parameters.Add("@Leave_reason", SqlDbType.NChar).Value = cbLeaveReason.Text; // cmd.Parameters.Add("@Phone_no", SqlDbType.Int).Value = intPhone_no; // cmd.Parameters.Add("@Mobile_no", SqlDbType.Int).Value = intMobile_no; // cmd.Parameters.Add("@Vest_no", SqlDbType.NChar).Value = txtVest_no.Text; // cmd.Parameters.Add("@Postal_code", SqlDbType.Int).Value = intPostal_code; // cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = txtAddress.Text; // cmd.Parameters.Add("@Education", SqlDbType.NVarChar).Value = cbEducation.Text; // cmd.Parameters.Add("@Lssuing_unit_no", SqlDbType.Int).Value = Lssuing_unit_no; // cmd.Parameters.Add("@Service_manual_no", SqlDbType.NChar).Value = txtService_manual_no.Text; // cmd.Parameters.Add("@Personality_scale", SqlDbType.NVarChar).Value = txtPersonality_scale.Text; // cmd.Parameters.Add("@Photo", SqlDbType.VarBinary).Value = imagebyte; // conn.Open(); // _Volunteer_no = (int)cmd.ExecuteScalar(); //================================================================= }
//存入個人資料 public ActionResult InsertSign_up() { //session轉VM Sign_up_session sign_Up_Session = Session["Sign_up_session"] as Sign_up_session; Sign_up_questionnaireVM Sign_up_question = Session["Question"] as Sign_up_questionnaireVM; //轉dbset並存檔 //存個人資料 日期沒輸入的預設為1800/1/1 Sign_up sign = new Sign_up(); sign.Chinese_name = sign_Up_Session.Chinese_name; sign.Identity_card = sign_Up_Session.Identity_card; sign.Sex = sign_Up_Session.Sex; sign.Birthday = sign_Up_Session.Birthday; sign.Phone = sign_Up_Session.Phone; sign.Mobile = sign_Up_Session.Mobile; sign.Email = sign_Up_Session.Email; sign.Address = sign_Up_Session.Address; sign.Education = sign_Up_Session.Education; sign.Job = sign_Up_Session.Job; sign.Stage = 1; sign.Sign_up_type = sign_Up_Session.Sign_up_type; //日期預設 sign.Sign_up_date = Convert.ToDateTime("1800-01-01 00:00:00"); sign.Approval_date = Convert.ToDateTime("1800-01-01 00:00:00"); dbContext.Entry(sign).State = System.Data.Entity.EntityState.Added; dbContext.SaveChanges(); //找出此新志工的暫時ID int Number = dbContext.Sign_up.Where(p => p.Identity_card == sign.Identity_card).First().Sign_up_no; //存專長資料 foreach (var exp in sign_Up_Session.Expertises) { Sign_up_expertise se = new Sign_up_expertise(); se.Sign_up_no = Number; se.Expertise = Convert.ToInt32(Regex.Replace(exp, "[^0-9]", "")); dbContext.Entry(se).State = System.Data.Entity.EntityState.Added; } //存表單資料 //存Q1 foreach (var q1 in Sign_up_question.Q1) { // var q1num = ; Sign_up_questionnaire sq = new Sign_up_questionnaire(); sq.Sign_up_no = Number; sq.Question_no = 1; sq.Answer_num = Convert.ToInt32(Regex.Replace(q1, "[^0-9]", "")); //選到其他,則加入其他的值 if (Regex.Replace(q1, "[^0-9]", "") == "06") { sq.Other_result1 = Sign_up_question.Q1else; } dbContext.Entry(sq).State = System.Data.Entity.EntityState.Added; } //存Q2 foreach (var q2 in Sign_up_question.Q2) { var q2num = Regex.Replace(q2, "[^0-9]", ""); Sign_up_questionnaire sq = new Sign_up_questionnaire(); sq.Sign_up_no = Number; sq.Question_no = 2; sq.Answer_num = Convert.ToInt32(q2num); //選到其他,則加入其他的值 if (q2num == "08") { sq.Other_result1 = Sign_up_question.Q2else; } dbContext.Entry(sq).State = System.Data.Entity.EntityState.Added; } //存Q3 foreach (var q3 in Sign_up_question.Q3) { var q3num = Regex.Replace(q3, "[^0-9]", ""); Sign_up_questionnaire sq = new Sign_up_questionnaire(); sq.Sign_up_no = Number; sq.Question_no = 3; sq.Answer_num = Convert.ToInt32(q3num); //選到其他,則加入其他的值 if (q3num == "09") { sq.Other_result1 = Sign_up_question.Q3doc; } dbContext.Entry(sq).State = System.Data.Entity.EntityState.Added; } //存Q4 foreach (var q4 in Sign_up_question.Q4) { var q4num = Regex.Replace(q4, "[^0-9]", ""); Sign_up_questionnaire sq = new Sign_up_questionnaire(); sq.Sign_up_no = Number; sq.Question_no = 4; sq.Answer_num = Convert.ToInt32(q4num); //選到其他,則加入其他的值 if (q4num == "08") { sq.Other_result1 = Sign_up_question.Q4else; } dbContext.Entry(sq).State = System.Data.Entity.EntityState.Added; } //Q5 Sign_up_questionnaire q5 = new Sign_up_questionnaire(); q5.Sign_up_no = Number; q5.Question_no = 5; q5.Answer_num = 1; q5.Other_result1 = Sign_up_question.Q5unit; q5.Other_result2 = Sign_up_question.Q5years; q5.Other_result3 = Sign_up_question.Q5content; dbContext.Entry(q5).State = System.Data.Entity.EntityState.Added; //Q6 Sign_up_questionnaire q6jobs = new Sign_up_questionnaire(); q6jobs.Sign_up_no = Number; q6jobs.Question_no = 6; q6jobs.Other_result1 = Sign_up_question.Q6jobs; dbContext.Entry(q6jobs).State = System.Data.Entity.EntityState.Added; //Q7 Sign_up_questionnaire q7 = new Sign_up_questionnaire(); q7.Sign_up_no = Number; q7.Question_no = 7; q7.Other_result1 = Sign_up_question.Q7; dbContext.Entry(q7).State = System.Data.Entity.EntityState.Added; //Q8 foreach (var q8 in Sign_up_question.Q8) { var q8num = Regex.Replace(q8, "[^0-9]", ""); Sign_up_questionnaire sq = new Sign_up_questionnaire(); sq.Sign_up_no = Number; sq.Question_no = 8; sq.Answer_num = Convert.ToInt32(q8num); dbContext.Entry(sq).State = System.Data.Entity.EntityState.Added; } //存服務時間 var service_period_vm = Session["Service_period"] as Service_period_VM; int[] wish1 = service_period_vm.wish1; int[] wish2 = service_period_vm.wish2; int[] wish3 = service_period_vm.wish3; foreach (var i in wish1) { Sign_up_Service_period service_period = new Sign_up_Service_period(); service_period.Sign_up_no = Number; service_period.Wish_order = 1; service_period.Service_period_no = i; dbContext.Entry(service_period).State = System.Data.Entity.EntityState.Added; } if (wish2 != null) { foreach (var i in wish2) { Sign_up_Service_period service_period = new Sign_up_Service_period(); service_period.Sign_up_no = Number; service_period.Wish_order = 2; service_period.Service_period_no = i; dbContext.Entry(service_period).State = System.Data.Entity.EntityState.Added; } } if (wish3 != null) { foreach (var i in wish3) { Sign_up_Service_period service_period = new Sign_up_Service_period(); service_period.Sign_up_no = Number; service_period.Wish_order = 3; service_period.Service_period_no = i; dbContext.Entry(service_period).State = System.Data.Entity.EntityState.Added; } } //存可面試時間 var interview_period_vm = Session["Interview_period"] as Interview_period_VM; int[] interview_wish = interview_period_vm.wish1; foreach (var i in interview_wish) { Sign_up_interview_period interview_period = new Sign_up_interview_period(); interview_period.Sign_up_no = Number; interview_period.interview_period_no = i; dbContext.Entry(interview_period).State = System.Data.Entity.EntityState.Added; } dbContext.SaveChanges(); return(Redirect("~/Home/NewVolunteer/7")); }
//存入個人資料 public ActionResult InsertSign_up() { //session轉VM Sign_up_session sign_Up_Session = Session["Sign_up_session"] as Sign_up_session; Student_questionnaireVM Student_question = Session["Question"] as Student_questionnaireVM; //轉dbset並存檔 //存個人資料 日期沒輸入的預設為1800/1/1 Sign_up sign = new Sign_up(); sign.Chinese_name = sign_Up_Session.Chinese_name; sign.Identity_card = sign_Up_Session.Identity_card; sign.Sex = sign_Up_Session.Sex; sign.Birthday = sign_Up_Session.Birthday; sign.Phone = sign_Up_Session.Phone; sign.Mobile = sign_Up_Session.Mobile; sign.Email = sign_Up_Session.Email; sign.Address = sign_Up_Session.Address; sign.Education = sign_Up_Session.Education; sign.Job = sign_Up_Session.Job; sign.Stage = 1; sign.Sign_up_type = sign_Up_Session.Sign_up_type; //日期預設 sign.Sign_up_date = Convert.ToDateTime("1800-01-01 00:00:00"); sign.Approval_date = Convert.ToDateTime("1800-01-01 00:00:00"); dbContext.Entry(sign).State = System.Data.Entity.EntityState.Added; dbContext.SaveChanges(); //找出此新志工的暫時ID int Number = dbContext.Sign_up.Where(p => p.Identity_card == sign.Identity_card).First().Sign_up_no; //存專長資料 foreach (var exp in sign_Up_Session.Expertises) { Sign_up_expertise se = new Sign_up_expertise(); se.Sign_up_no = Number; se.Expertise = Convert.ToInt32(Regex.Replace(exp, "[^0-9]", "")); dbContext.Entry(se).State = System.Data.Entity.EntityState.Added; } //存表單資料 //存Q9 是否參加訓練 { Sign_up_questionnaire q9 = new Sign_up_questionnaire(); q9.Sign_up_no = Number; q9.Question_no = 9; q9.Other_result1 = Student_question.training.ToString(); dbContext.Entry(q9).State = System.Data.Entity.EntityState.Added; } //存Q10 家長是否知道 { Sign_up_questionnaire q10 = new Sign_up_questionnaire(); q10.Sign_up_no = Number; q10.Question_no = 10; q10.Other_result1 = Student_question.knowing.ToString(); dbContext.Entry(q10).State = System.Data.Entity.EntityState.Added; } //存Q11 緊急連絡人名 { Sign_up_questionnaire q11 = new Sign_up_questionnaire(); q11.Sign_up_no = Number; q11.Question_no = 11; q11.Other_result1 = Student_question.Emergency_Name.ToString(); dbContext.Entry(q11).State = System.Data.Entity.EntityState.Added; } //存Q12 緊急連絡人電話 { Sign_up_questionnaire q12 = new Sign_up_questionnaire(); q12.Sign_up_no = Number; q12.Question_no = 12; q12.Other_result1 = Student_question.Emergency_Phone.ToString(); dbContext.Entry(q12).State = System.Data.Entity.EntityState.Added; } //存Q13 學校名稱 { Sign_up_questionnaire q13 = new Sign_up_questionnaire(); q13.Sign_up_no = Number; q13.Question_no = 13; q13.Other_result1 = Student_question.School_Name.ToString(); dbContext.Entry(q13).State = System.Data.Entity.EntityState.Added; } //存Q14 學校規定 { Sign_up_questionnaire q14 = new Sign_up_questionnaire(); q14.Sign_up_no = Number; q14.Question_no = 14; q14.Other_result1 = Student_question.School_Regulation.ToString(); dbContext.Entry(q14).State = System.Data.Entity.EntityState.Added; } //存學生服務時間 var service_period_vm = Session["Service_period"] as Service_period_VM; int[] wish1 = service_period_vm.wish1; foreach (var i in wish1) { Sign_up_Service_period service_period = new Sign_up_Service_period(); service_period.Sign_up_no = Number; service_period.Wish_order = 1; service_period.Service_period_no = i; dbContext.Entry(service_period).State = System.Data.Entity.EntityState.Added; } dbContext.SaveChanges(); return(Redirect("~/Student/NewVolunteer/6")); }
//新增活動事件▼ public void btn_addActivity_Click(object sender, RoutedEventArgs e) {//新增活動事件 if (VM_Activity_name == null || VM_Activity_type == null || VM_Group_name == null) { System.Windows.Forms.MessageBox.Show("欄位有空格無法新增"); return; } else if (VM_Activity_startdate == null) { System.Windows.Forms.MessageBox.Show("起始日期空白", "新增活動失敗"); return; } else if (VM_Activity_enddate == null || Convert.ToDateTime(VM_Activity_enddate) < Convert.ToDateTime(VM_Activity_startdate)) { System.Windows.Forms.MessageBox.Show("結束日期空白或短於起始日期", "新增活動失敗"); return; } System.IO.MemoryStream MS = new System.IO.MemoryStream(); //將圖轉成二進位 JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(VM_Activity_photos)); encoder.Save(MS); VM_Activity_photo_byte = MS.GetBuffer(); //先新增一筆活動▼新增照片時才有活動編號可用 if (VM_Activity_type_ID == 0) { VM_Activity_type_ID = 1; } if (VM_Group_no == 0) { VM_Group_no = 1; } Activity Ac = new Activity() { Activity_name = VM_Activity_name, lecturer = VM_lecturer, Activity_type_ID = VM_Activity_type_ID, Group_no = VM_Group_no, Undertake_unit = "社工室", Undertaker = VM_supervision_ID, Undertake_phone = VM_supervision_phone.ToString(), Undertake_email = VM_supervision_email, Member = VM_Member, Spare = VM_Spare, Place = VM_Place, Summary = VM_Summary, Activity_startdate = DateTime.Parse(VM_Activity_startdate), Activity_enddate = DateTime.Parse(VM_Activity_enddate) }; Myentity.Activities.Add(Ac); Myentity.SaveChanges(); //再新增照片進資料庫▼ var q = (from A in Myentity.Activities where A.Activity_name == VM_Activity_name select new { ActID = A.Activity_no }).Single(); Activity_photo Ap = new Activity_photo() { Activity_id = q.ActID, Activity_photo1 = VM_Activity_photo_byte }; Myentity.Activity_photo.Add(Ap); Myentity.SaveChanges(); //再回頭修改剛新增的活動-活動照片ID var q1 = (from p in Myentity.Activity_photo where p.Activity_id == q.ActID select new { P_photoID = p.Activity_photo_id, P_activityID = p.Activity_id }).Single(); var q2 = (from A2 in Myentity.Activities where A2.Activity_no == q1.P_activityID select A2).Single(); q2.Activity_Photo_id = q1.P_photoID; Myentity.SaveChanges(); if (wrapPanelmodel.wrapPanel != null && WrapPanelModel.wrapPanel.Children.Count > 0) { for (int i = 0; i < list_photo_save.Count; i += 1) { BitmapImage bi = new BitmapImage(new Uri(list_photo_save[i])); System.IO.MemoryStream MS2 = new System.IO.MemoryStream(); //將圖轉成二進位 JpegBitmapEncoder encoder2 = new JpegBitmapEncoder(); encoder2.Frames.Add(BitmapFrame.Create(bi)); encoder2.Save(MS2); VM_Activity_photo_byte = MS2.GetBuffer(); Activity_photo ap = new Activity_photo() { Activity_id = q1.P_activityID, Activity_photo1 = VM_Activity_photo_byte }; Myentity.Activity_photo.Add(ap); } } Myentity.SaveChanges(); MessageBox.Show("新增成功"); System.Windows.Forms.Application.Exit(); }