//刪除勾選的照片▼ public void btn_amend_delete_Click(object sender, RoutedEventArgs e) { if (list_photo_click.Count != 0) { for (int j = 0; j < list_photo_click.Count; j += 1) { for (int i = 0; i < WrapPanelModel.wrapPanel.Children.Count; i += 1) { int n = 0; Activity_Addimage_use a = WrapPanelModel.wrapPanel.Children[i] as Activity_Addimage_use; if (a != null) { if (list_photo_click[j] == int.Parse(a.Name.Trim('a'))) { n = list_photo_click[j]; WrapPanelModel.wrapPanel.Children.Remove(WrapPanelModel.wrapPanel.Children[i]); if (a.Tag != null) { list_photo.Remove(a.Tag.ToString()); //list_photo_save.Remove(a.Tag.ToString()); } delete_use.Add(list_photo_click[j]); var q = (from p in Myentity.Activity_photo where p.Activity_photo_id == n select p).FirstOrDefault(); if (q != null) { Myentity.Activity_photo.Remove(q); // Myentity.SaveChanges(); } } } } } for (int i = 0; i < delete_use.Count; i += 1) { for (int j = 0; j < list_photo_click.Count; j += 1) { if (list_photo_click[j] == delete_use[i]) { list_photo_click.Remove(list_photo_click[j]); break; } } } } else { return; } list_photo_click.Clear(); }
//自訂控制項被點選後▼ private void UserControl_A_MouseleftbuttonDown(object sender, MouseButtonEventArgs e) { Activity_Addimage_use myaim = ((Activity_Addimage_use)sender); Viewbox v = new Viewbox(); StackPanel sp = new StackPanel(); Window w = new Window(); TextBox TB = new TextBox(); Button btn = new Button(); Viewbox vb = new Viewbox(); btn.HorizontalAlignment = HorizontalAlignment.Center; btn.Height = 25; btn.Width = 100; btn.Content = "關閉"; w.Width = 400; w.Height = 500; w.Title = "顯示照片"; TB.Height = 25; TB.FontSize = 16; TB.TextAlignment = TextAlignment.Center; TB.Text = myaim.Title; Image i = new Image(); i.Source = myaim.imagesource; i.Height = 400; i.Stretch = System.Windows.Media.Stretch.Fill; sp.Orientation = Orientation.Vertical; sp.Children.Add(TB); sp.Children.Add(i); sp.Children.Add(btn); TB.TextChanged += delegate(object sender1, TextChangedEventArgs e1) { myaim.Title = ((TextBox)sender1).Text; }; vb.Stretch = System.Windows.Media.Stretch.Fill; vb.Child = sp; w.Content = vb; w.Show(); btn.Click += delegate(object sender1, RoutedEventArgs e1) { w.Close(); }; }
//產生自訂控制項▼ public void getWrapPanel() { for (int i = 0; i < list_photo.Count; i += 1) { //int name_end = (list_photo[i].Length - list_photo[i].LastIndexOf('\\')) - (list_photo[i].Length - list_photo[i].IndexOf('.')); int name_end = (list_photo[i].Length - list_photo[i].IndexOf('.')) - (list_photo[i].Length - list_photo[i].LastIndexOf('\\')); Activity_Addimage_use UserControl = new Activity_Addimage_use(); //UserControl.Title = list_photo[i].Substring(list_photo[i].LastIndexOf('\\') + 1, name_end - 1); UserControl.Title = list_photo[i].Substring(list_photo[i].LastIndexOf('\\') + 1); UserControl.imagesource = new BitmapImage(new Uri(list_photo[i])); UserControl.Height = 150; //210 UserControl.Width = 200; //200 UserControl.Margin = new Thickness(5); WrapPanelModel.wrapPanel.Children.Add(UserControl); UserControl.Name = "a" + (photo_name + 1); UserControl.Tag = list_photo[i]; photo_name += 1; UserControl.click += UserControl_click; UserControl.A_MouseleftbuttonDown += UserControl_A_MouseleftbuttonDown; //滑鼠左鍵按下時 } }
////查詢的事件▼ public Activity_AddAction_ViewModel(string name, DateTime startdate, WrapPanel vm_wrapPanel) { addact = false; amendact = true; wrapPanelmodel = new WrapPanelModel(); wrapPanelmodel.wrapPanel = vm_wrapPanel; //將傳入的WrapPanel,傳給wrapPanelmodel屬性 addcommand = new Delegatecommand(btn_amend_addimage_Click); //執行附加的方法 var q = (from find_act in Myentity.Activities where find_act.Activity_name == name && find_act.Activity_startdate == startdate select find_act).Single(); var q1 = (from find_supersion in Myentity.Volunteer_supervision where find_supersion.supervision_ID == q.Undertaker select find_supersion).Single(); var q2 = (from find_photo in Myentity.Activity_photo where find_photo.Activity_id == q.Activity_no select find_photo).ToList(); var q3 = (from t in Myentity.Activity_type where t.Activity_type_ID == q.Activity_type_ID select t).Single(); var q4 = (from g in Myentity.Service_group where g.Group_no == q.Group_no select g).Single(); for (int i = 0; i < q2.Count; i += 1) { if (i == 0) { byte[] img = q2[i].Activity_photo1; BitmapImage Bi = new BitmapImage(); Bi.BeginInit(); Bi.StreamSource = new System.IO.MemoryStream(img); Bi.EndInit(); VM_Activity_Photo_id = q2[i].Activity_photo_id; VM_Activity_photos = Bi; } else { //int name_end = (list_photo[i].Length - list_photo[i].LastIndexOf('\\')) - (list_photo[i].Length - list_photo[i].IndexOf('.')); byte[] img = q2[i].Activity_photo1; BitmapImage Bi = new BitmapImage(); Bi.BeginInit(); Bi.StreamSource = new System.IO.MemoryStream(img); Bi.EndInit(); Activity_Addimage_use UserControl = new Activity_Addimage_use(); // UserControl.Title = list_photo[i].Substring(list_photo[i].LastIndexOf('\\') + 1, name_end - 1); UserControl.imagesource = Bi; //new BitmapImage(new Uri(list_photo[i])); UserControl.Height = 150; //210 UserControl.Width = 200; //200 UserControl.Margin = new Thickness(5); WrapPanelModel.wrapPanel.Children.Add(UserControl); UserControl.Name = "a" + q2[i].Activity_photo_id; photo_name += 1; UserControl.click += UserControl_click; UserControl.A_MouseleftbuttonDown += UserControl_A_MouseleftbuttonDown; } } VM_Activity_no = q.Activity_no; VM_Activity_name = q.Activity_name; VM_lecturer = q.lecturer; if (q.Activity_type_ID == 1) { VM_Activity_type_ID = 0; } else { VM_Activity_type_ID = q.Activity_type_ID; } if (Convert.ToInt32(q.Group_no) == 1) { VM_Group_no = 0; } else { VM_Group_no = Convert.ToInt32(q.Group_no); } VM_Activity_type = q3.Activity_type1; VM_Group_name = q4.Group_name; VM_Place = q.Place; VM_Activity_startdate = q.Activity_startdate.Value.ToShortDateString(); VM_Activity_enddate = q.Activity_enddate.Value.ToShortDateString(); VM_supervision_ID = Convert.ToInt32(q.Undertaker); VM_supervision_Name = q1.supervision_Name; VM_supervision_phone = int.Parse(q.Undertake_phone); VM_supervision_email = q.Undertake_email; VM_Member = Convert.ToInt32(q.Member); VM_Spare = Convert.ToInt32(q.Spare); VM_Summary = q.Summary; getcombo(); }