123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539 |
- using Common.system;
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using XHZB.Desktop.Utils;
- using XHZB.Model;
-
- namespace XHZB.Desktop
- {
- /// <summary>
- /// 批注
- /// </summary>
- public partial class PracticeWindow : Window
- {
- private readonly ZBPageModel pageData = new ZBPageModel();
- private readonly BlackboardNew myblackboard;
- internal double pwidth = SystemParameters.PrimaryScreenWidth;
- internal double pHeight = SystemParameters.PrimaryScreenHeight;
- private readonly List<string> ImageInfo = new List<string>();
- private readonly int serverReturnCode = 0;
- //private readonly RegisterController registerController = new RegisterController();
- /// <summary>
- /// 保存图片路径
- /// </summary>
- private string Rfpath = string.Empty;
- /// <summary>
- /// 初始创建黑板
- /// </summary>
- private readonly bool isfirstload = true;
- private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
- private int Size = 3;
- private string AskidName = string.Empty;
-
- /// <summary>
- /// 批注
- /// </summary>
- public PracticeWindow()
- {
- InitializeComponent();
- if (isfirstload)
- {
- myblackboard = new BlackboardNew(blackboard_canvas, Colors.Red);
- initData();
- isfirstload = false;
- }
- }
-
- /// <summary>
- /// 初始化页面
- /// </summary>
- public void Initialize()
- {
- this.Opacity = 1;
- m_grid.Background = new SolidColorBrush(Colors.Black);
- AskidName = string.Empty;
- isFDetais = true;
- pageData.pagenum = ImageInfo.Count;
- Rfpath = string.Empty;
- Uri uri = new Uri(ImageInfo[pageData.currpage - 1], UriKind.Absolute);
- BitmapImage bitmapImage = new BitmapImage(uri);
- myblackboard.changepage(pageData.currpage - 1);
- m_image.Source = bitmapImage;
- }
-
- private void initData()
- {
- pageData.menuList.Add(new ZBMenuModel()
- {
- Name = "铅笔",
- Pic = "../Images/Blackboard/class_2s.png",
- Selected = true
- });
- pageData.menuList.Add(new ZBMenuModel()
- {
- Name = "颜色",
- Pic = "../Images/Blackboard/class_c1.png",
- Selected = false
- });
- pageData.menuList.Add(new ZBMenuModel()
- {
- Name = "粗细",
- Pic = "../Images/Blackboard/class_s1.png",
- Selected = false
- });
- pageData.menuList.Add(new ZBMenuModel()
- {
- Name = "橡皮",
- Pic = "../Images/Blackboard/class_3un.png",
- Selected = false
- });
- pageData.menuList.Add(new ZBMenuModel()
- {
- Name = "清空",
- Pic = "../Images/Blackboard/class_6un.png",
- Selected = false
- });
- pageData.menuList.Add(new ZBMenuModel()
- {
- Name = "撤销",
- Pic = "../Images/Blackboard/class_4un.png",
- Selected = false
- });
- pageData.menuList.Add(new ZBMenuModel()
- {
- Name = "恢复",
- Pic = "../Images/Blackboard/class_5un.png",
- Selected = false
- });
-
- pageData.menuList.Add(new ZBMenuModel()
- {
- Name = "退出",
- Pic = "../Images/Blackboard/class_7un.png",
- Selected = false
- });
-
- DataContext = pageData;
- }
-
- /// <summary>
- /// 暂修改为传图片地址 新增一页
- /// </summary>
- /// <param name="_imageInfo"></param>
- public void addImage(string _imageInfo)
- {
- ImageInfo.Add(_imageInfo);
-
- pageData.currpage = ImageInfo.Count;
- Initialize();
- }
-
- private void menu_item_Click(object sender, RoutedEventArgs e)
- {
- int clickindex = 0;
- List<Button> buttons = VTHelper.FindChilds<Button>(toolbar_list, "toolbar_item");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- clickindex = i;
- break;
- }
- }
- if (clickindex < pageData.menuList.Count)
- {
- //ZBMenu menudata = pageData.menuList[clickindex];
- if (clickindex == 0)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
- if (pageData.menuList[0].Selected)
- {
-
- }
- else
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- myblackboard.change_pen(Color, Size);
- }
- }
- if (clickindex == 1)
- {
- tip_Color.Visibility = Visibility.Visible;
- tip_Size.Visibility = Visibility.Collapsed;
- }
- if (clickindex == 2)
- {
- tip_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Visible;
- }
- else if (clickindex == 3)
- {
- tip_Color.Visibility = Visibility.Collapsed;
- pageData.menuList[0].Selected = false;
- pageData.menuList[3].Selected = true;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2un.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3s.png";
- myblackboard.change_erase();
- }
- else if (clickindex == 4)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
- myblackboard.clear();
- }
- else if (clickindex == 5)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
- myblackboard.undo();
- }
- else if (clickindex == 6)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
- myblackboard.redo();
- }
- else if (clickindex == 7)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
-
- //Hide();
-
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(new Action(() =>
- {
- m_image.Source = null;
- blackboard_canvas.Strokes.Clear();
-
- m_grid.Background = new SolidColorBrush(Colors.Transparent);
- this.Opacity = 0;
- }));
-
- Thread.Sleep(50);
- Dispatcher.Invoke(new Action(() =>
- {
- Hide();
- }));
- }))).Start();
- }
- }
- }
-
- // 保存图片
- private void save_button_Click(object sender, RoutedEventArgs e)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
- try
- {
- string filepath = APP.GetImagePath(out string serverSavePath);
- Rfpath = serverSavePath;
- //TeachingDataStatic.ClassScreenshot.Add(filepath);//统计截图
- ImageHelper.SaveUIToImage(m_grid, filepath, (int)Math.Round(m_grid.ActualWidth), (int)Math.Round(m_grid.ActualHeight));
- //}
-
-
- tip_tb.Text = "保存成功";
- tip_outer.Visibility = Visibility.Visible;
- new Thread(o =>
- {
- int seconds = 3;//通知持续5s后消失
- System.Threading.Thread.Sleep(TimeSpan.FromSeconds(seconds));
- //Invoke到主进程中去执行
- Dispatcher.Invoke(new Action(() =>
- {
- tip_outer.Visibility = Visibility.Hidden;
- }));
- }).Start();
-
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
- }
- catch (Exception err)
- {
- Console.WriteLine(err.Message);
- }
- }
-
- /// <summary>
- /// 上一页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void last_button_Click(object sender, RoutedEventArgs e)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
- if (pageData.currpage > 1)
- {
- pageData.currpage -= 1;
- Initialize();
- }
- }
-
- /// <summary>
- /// 下一页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void next_btn_Click(object sender, RoutedEventArgs e)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
- if (pageData.currpage < pageData.pagenum)
- {
- pageData.currpage += 1;
- Initialize();
- }
- }
-
- private void Window_Activated(object sender, EventArgs e)
- {
- //Console.WriteLine("Window_Activated");
- }
- bool isFDetais = true;
- /// <summary>
- /// 简答题详情
- /// </summary>
- public void Detai(bool isDetai, string askidName)
- {
- isFDetais = isDetai;
- //AskidName = askidName;
- }
- private void Window_Deactivated(object sender, EventArgs e)
- {
- try
- {
- if (isFDetais)
- {
- ////Console.WriteLine("Window_Deactivated");
- ToolbarWindow toolbarWin = (ToolbarWindow)Owner;
- if (toolbarWin != null)
- {
- toolbarWin.Show();
- }
-
-
- Console.WriteLine("imageList.Count" + ImageInfo.Count);
- }
-
- }
- catch (Exception ex)
- {
-
-
- }
-
- }
-
- /// <summary>
- /// 课堂--保存图片服务-调用
- /// </summary>
- /// <returns></returns>
- private object InvokeServering()
- {
- //Savefile savefile = new Savefile
- //{
- // roomid = Shared.TeachingData.REQ_StartClass.roomid,
- // rfpath = Rfpath.Replace("\\", "/")
- //};
- //;
- //savefile.rftype = 2;
- //savefile.createid = ZCommonData.loginUser.userid;
- //savefile.schoolid = ZCommonData.loginUser.schoolid;
- //savefile.createtime = DataProvider.TimestampTotalSeconds();
- //ZSqliteManger.insertClassData(new ClassData()
- //{
- // unix = DataProvider.TimestampTotalSeconds(),
- // roomid = ZCommonData.roomid,
- // api = "savefile",
- // json = ZJsonHelper.ToJson(savefile),
- // askid = DataProvider.TimestampAddRandomNumber()
- //});
- return APP.ErrorMessage;
- }
-
- /// <summary>
- /// 课堂--保存图片服务-返回结果
- /// </summary>
- /// <returns></returns>
- public void InvokeServerCompate(object obj)
- {
- if (serverReturnCode == APP.ServerScuessCode)
- {
- }
- }
- /// <summary>
- /// 页面关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_Closed(object sender, EventArgs e)
- {
- tip_Size.Visibility = Visibility.Collapsed;
- tip_Color.Visibility = Visibility.Collapsed;
- click_closeClick();
- }
-
- #region 关闭委托
-
- /// <summary>
- /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public delegate void CloseClick();
-
- /// <summary>
- /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
- /// </summary>
- public event CloseClick click_closeClick;
-
- #endregion 关闭委托
- /// <summary>
- /// 画笔颜色事件 白色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnWhite_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Color = Colors.White;
- myblackboard.change_pen(Color, Size);
- tip_Color.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 红色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRed_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Color = Colors.Red;
- myblackboard.change_pen(Color, Size);
- tip_Color.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 灰色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnGray_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Color = Colors.Gray;
- myblackboard.change_pen(Color, Size);
- tip_Color.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 青色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Color = Colors.LimeGreen;
- myblackboard.change_pen(Color, Size);
- tip_Color.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 黄色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnYellow_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Color = Colors.Gold;
- myblackboard.change_pen(Color, Size);
- tip_Color.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 蓝色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBlue_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Color = Colors.DeepSkyBlue;
- myblackboard.change_pen(Color, Size);
- tip_Color.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnFine_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Size = 3;
- myblackboard.change_pen(Color, Size);
- tip_Size.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnIn_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Size = 6;
- myblackboard.change_pen(Color, Size);
- tip_Size.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 粗
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnCrude_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[0].Selected = true;
- pageData.menuList[3].Selected = false;
- pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
- pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
- Size = 12;
- myblackboard.change_pen(Color, Size);
- tip_Size.Visibility = Visibility.Collapsed;
- }
- }
- }
|