|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528 |
- using Common.system;
- using System;
- using System.IO;
- 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 ZBlackboardWindow : Window
- {
- private readonly ZBPageModel pageData = new ZBPageModel();
- private readonly BlackboardNew myblackboard;
- private readonly int serverReturnCode = 0;
- //private readonly RegisterController registerController = new RegisterController();
- /// <summary>
- /// 保存图片路径
- /// </summary>
- private string Rfpath = string.Empty;
- private Color Color = Colors.White;
- private int Size = 3;
- /// <summary>
- /// 黑板
- /// </summary>
- public ZBlackboardWindow()
- {
- InitializeComponent();
-
- myblackboard = new BlackboardNew(blackboard_canvas);
- initData();
- }
-
- private void initData()
- {
- pageData.pagenum = 1;
- pageData.currpage = 1;
- 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_s5.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;
- }
-
- private void menu_item_Click(object sender, RoutedEventArgs e)
- {
- int clickindex = 0;
- System.Collections.Generic.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_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Collapsed;
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- if (pageData.menuList[0].Selected)
- {
- //tip_Color.Visibility = Visibility.Visible;
- }
- 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;
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- }
- if (clickindex == 2)
- {
- tip_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Visible;
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- }
- else if (clickindex == 3)
- {
- tip_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Collapsed;
- tip_BlackboardColor.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_BlackboardColor.Visibility = Visibility.Visible;
- tip_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Collapsed;
- }
- else if (clickindex == 5)
- {
- tip_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Collapsed;
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- myblackboard.clear();
- }
- else if (clickindex == 6)
- {
- tip_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Collapsed;
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- myblackboard.undo();
- }
- else if (clickindex == 7)
- {
- tip_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Collapsed;
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- myblackboard.redo();
- }
- else if (clickindex == 8)
- {
- tip_Color.Visibility = Visibility.Collapsed;
- tip_Size.Visibility = Visibility.Collapsed;
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- Hide();
-
- //new Thread(new ThreadStart(new Action(() =>
- //{
- // Dispatcher.Invoke(new Action(() =>
- // {
- // blackboard_canvas.Strokes.Clear();
- // }));
- // Thread.Sleep(500);
- // Dispatcher.Invoke(new Action(() =>
- // {
- // Hide();
- // }));
- //}))).Start();
-
-
- }
- }
- }
-
- private readonly string imagepaths = string.Empty;
-
- private void save_button_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- string imagepath = APP.classRoomImagePath();
-
- if (!Directory.Exists(imagepath))
- {
- Directory.CreateDirectory(imagepath);
- }
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- string filepath = Path.Combine(imagepath, timestr + ".jpg");
-
- //TeachingDataStatic.ClassScreenshot.Add(filepath);//课堂统计截图
- Rfpath = string.Empty;
- Rfpath = APP.dbImagePath() + timestr + ".jpg";
- int width = (int)Math.Round(blackboard_canvas.ActualWidth);
- int height = (int)Math.Round(blackboard_canvas.ActualHeight);
- RenderTargetBitmap bmpCopied = new RenderTargetBitmap(
- width,
- height,
- 96,
- 96,
- PixelFormats.Default
- );
- DrawingVisual dv = new DrawingVisual();
- using (DrawingContext dc = dv.RenderOpen())
- {
- VisualBrush vb = new VisualBrush(blackboard_canvas);
- dc.DrawRectangle(
- vb,
- null,
- new Rect(new System.Windows.Point(), new System.Windows.Size(width, height))
- );
- }
- bmpCopied.Render(dv);
- using (FileStream file = new FileStream(filepath, FileMode.Create, FileAccess.Write))
- {
- JpegBitmapEncoder encoder = new JpegBitmapEncoder
- {
- QualityLevel = 80
- };
- encoder.Frames.Add(BitmapFrame.Create(bmpCopied));
- encoder.Save(file);
- }
- tip_tb.Text = "保存成功";
- tip_outer.Visibility = Visibility.Visible;
- ZDelayUtil.delay(3, Dispatcher, new Action(() =>
- {
- tip_outer.Visibility = Visibility.Hidden;
- }));
-
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
- }
- catch (Exception err)
- {
- Console.WriteLine(err.Message);
- }
- }
-
- private void add_button_Click(object sender, RoutedEventArgs e)
- {
- pageData.pagenum += 1;
- pageData.currpage = pageData.pagenum;
- myblackboard.changepage(pageData.currpage - 1);
- }
-
- private void last_button_Click(object sender, RoutedEventArgs e)
- {
- if (pageData.currpage > 1)
- {
- pageData.currpage -= 1;
- myblackboard.changepage(pageData.currpage - 1);
- }
- }
-
- private void next_btn_Click(object sender, RoutedEventArgs e)
- {
- if (pageData.currpage < pageData.pagenum)
- {
- pageData.currpage += 1;
- myblackboard.changepage(pageData.currpage - 1);
- }
- }
-
- /// <summary>
- /// 课堂--保存图片服务-调用
- /// </summary>
- /// <returns></returns>
- private object InvokeServering()
- {
- //Savefile savefile = new Savefile
- //{
- // roomid = Shared.TeachingData.REQ_StartClass.roomid,
- // rfpath = Rfpath.Replace("\\", "/"),
- // rftype = 1,
- // createid = ZCommonData.loginUser.userid,
- // schoolid = ZCommonData.loginUser.schoolid,
- // 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)
- {
- 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;
- }
- /// <summary>
- /// 黑板颜色 白色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnWhites_Click(object sender, RoutedEventArgs e)
- {
- blackboard_canvas.Background = new SolidColorBrush(Colors.White);
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 黑板颜色 黑色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBlack_Click(object sender, RoutedEventArgs e)
- {
- blackboard_canvas.Background = new SolidColorBrush(Colors.Black);
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 黑板颜色 绿色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnGreen_Click(object sender, RoutedEventArgs e)
- {
- blackboard_canvas.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#043a25"));
- tip_BlackboardColor.Visibility = Visibility.Collapsed;
- }
- }
- }
|