|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942 |
- using Common.system;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Configuration;
- using System.Data;
- using System.IO;
- using System.Security.Principal;
- using System.Text;
- using System.Threading;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using XHZB.Desktop.Utils;
- using XHZB.Model;
-
- namespace XHZB.Desktop
- {
-
-
-
- public partial class LoginWindow : Window
- {
- #region 字段&属性
-
- private Dictionary<int, string> _selGroupList;
-
-
-
- public Dictionary<int, string> selGroupList
- {
- get => _selGroupList;
- set => _selGroupList = value;
- }
- private int _Group;
-
-
-
- public int Group
- {
- get => _Group;
- set => _Group = value;
- }
-
-
-
- private readonly RegisterController registerController = new RegisterController();
-
-
-
- private int serverReturnCode = 0;
- public DataTable data = new DataTable();
- public DataTable DirectorList = new DataTable();
- internal LoginPageData pageData = new LoginPageData();
-
-
-
- private int lsbids = 0;
-
-
-
- private int directorids = 0;
- #endregion 字段&属性
-
- #region 初始化
-
-
-
- public LoginWindow()
- {
- InitializeComponent();
-
-
- CameraWindow cameraWindow = new CameraWindow();
- cameraWindow.Topmost = true;
- cameraWindow.Show();
-
-
-
-
- WindowStartupLocation = WindowStartupLocation.CenterScreen;
-
- string typestr = APP.isDebug ? "测试版" : "正式版";
- bool isAdmin = IsAdministrator();
- string stradmin = isAdmin ? "管理员" : "普通用户";
-
- version_tb.Text = $"{typestr} v{FileToolsCommon.GetConfigValue("VersionName")}(Build{FileToolsCommon.GetConfigValue("VersionCode")}) [{stradmin}]";
-
- if (File.Exists(APP.dataPath + "interfaceAddress.txt"))
- {
- APP.apiUrl = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default);
- }
- if (File.Exists(APP.dataPath + "imageUploadAddress.txt"))
- {
- APP.uploadUrl = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default);
- }
- if (File.Exists(APP.dataPath + "pictureShowsAddress.txt"))
- {
- APP.showImageUrl = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default);
- }
- if (File.Exists(APP.dataPath + "fileStorageAddress.txt"))
- {
- APP.fileStorageAddress = System.IO.File.ReadAllText(APP.dataPath + "fileStorageAddress.txt", Encoding.Default);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public bool IsAdministrator()
- {
- WindowsIdentity current = WindowsIdentity.GetCurrent();
- WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current);
- return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
- }
-
-
-
-
-
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- WindowStartupLocation = WindowStartupLocation.CenterScreen;
-
- btnLogin.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1D8AF4"));
-
-
- if (GetSettingString("isRemind").Equals("True"))
- {
- ckSaveName.IsChecked = true;
- txbAccountNumber.Text = GetSettingString("userName");
- }
-
-
-
-
-
- getNewApp();
- }
- #endregion 初始化
-
- #region 事件
-
-
-
-
-
- private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
-
-
-
-
-
- private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- System.Windows.Rect r = new System.Windows.Rect(e.NewSize);
- RectangleGeometry gm = new RectangleGeometry(r, 1, 1);
- ((UIElement)sender).Clip = gm;
- }
-
-
-
-
-
- private void btnLogin_Click(object sender, RoutedEventArgs e)
- {
-
-
-
-
-
-
- if (string.IsNullOrEmpty(txbAccountNumber.Text))
- {
- MessageWindow.Show("账号未输入");
- return;
- }
- if (string.IsNullOrEmpty(pobPassword.Password))
- {
- MessageWindow.Show("密码未输入");
- return;
- }
- APP.myloading.Show();
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
- }
-
-
-
-
-
- private void btnClassesBegin_Click(object sender, RoutedEventArgs e)
- {
- if (string.IsNullOrWhiteSpace(cmbClass.Text))
- {
- MessageWindow.Show("尚未选择班级");
- return;
- }
- if (string.IsNullOrEmpty(cmbTeachingMaterial.Text))
- {
- MessageWindow.Show("尚未选择章节");
- return;
- }
- APP.myloading.Show();
- APP.classid = Convert.ToInt32(cmbClass.SelectedValue.ToString());
-
- for (int i = 0; i < APP.ClassList.Count; i++)
- {
- if (APP.classid == APP.ClassList[i].classid)
- {
- APP.REQStartClass.classnum = APP.ClassList[i].classnum;
- }
- }
-
- APP.REQStartClass.roomname = DateTime.Now.ToString() + cmbClass.Text;
- APP.REQStartClass.directorid = Convert.ToInt32(cmbTeachingMaterial.SelectedValue.ToString());
- APP.REQStartClass.roomid = TimestampAddRandomNumber();
- APP.roomid = APP.REQStartClass.roomid;
-
- try
- {
-
- string ApplicationData = APP.dataPath + "loginUserid.txt";
- string temp = APP.LoginUser.userid.ToString();
- System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- ApplicationData = APP.dataPath + "loginLsbid.txt";
- temp = APP.lsbid.ToString();
- System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- ApplicationData = APP.dataPath + "loginDirectorid.txt";
- temp = APP.REQStartClass.directorid.ToString();
- System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【登陆(LoginWindow)" + ex.Message, ex);
- }
-
-
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeClassStudentListServering, InvokeServerClassStudentListCompate);
- }
-
-
-
-
- public long TimestampAddRandomNumber()
- {
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- long tick = DateTime.Now.Ticks;
- Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
- int random = ran.Next(100, 999);
- return Convert.ToInt64(timestr + random.ToString());
- }
-
-
-
-
-
- private void btnDown_Click(object sender, RoutedEventArgs e)
- {
- Close();
- Application.Current.Shutdown();
- System.Environment.Exit(0);
- }
- #endregion 事件
-
- #region 方法
-
-
-
-
-
- public static string GetSettingString(string settingName)
- {
- try
- {
- string settingString = FileToolsCommon.GetConfigValue(settingName);
- return settingString;
- }
- catch (Exception)
- {
- return null;
- }
- }
-
-
-
-
-
- public static void UpdateSettingString(string settingName, string valueName)
- {
-
-
-
-
-
-
-
-
-
- }
-
-
-
- private void getNewApp()
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- private object InvokeServering()
- {
- string accountNumber = string.Empty;
- string password = string.Empty;
- Dispatcher.Invoke(new Action(() =>
- {
- accountNumber = txbAccountNumber.Text.Replace(" ", "").Trim();
- password = pobPassword.Password.Replace(" ", "").Trim();
- }));
- serverReturnCode = registerController.Login(accountNumber, password);
- return APP.ErrorMessage;
- }
-
-
-
-
- public void InvokeServerCompate(object obj)
- {
- APP.myloading.Hide();
- if (serverReturnCode == APP.ServerScuessCode)
- {
- grLogin.Visibility = Visibility.Collapsed;
- grLoginTwo.Visibility = Visibility.Visible;
- imgBrush.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Login/login2_1.png"));
- txbHeader.Text = APP.LoginUser.username + "老师,您好!";
- version_tb.Visibility = Visibility.Collapsed;
- btnSetUp.Visibility = Visibility.Collapsed;
- UpdateSettingString("userName", txbAccountNumber.Text);
-
- new Thread(o =>
- {
- InvokeClassListServering();
- Dispatcher.Invoke(new Action(() =>
- {
- InvokeServerClassListCompate();
- }));
-
- }).Start();
- new Thread(o =>
- {
- InvokeTsubjectbookListServering();
- Dispatcher.Invoke(new Action(() =>
- {
- InvokeServerTsubjectbookListCompate();
- }));
-
- }).Start();
- }
- else
- {
- MessageWindow.Show(APP.ErrorMessage);
- }
- }
-
-
-
-
- private object InvokeClassListServering()
- {
- serverReturnCode = registerController.ClassList();
- return APP.ErrorMessage;
- }
-
-
-
-
- public void InvokeServerClassListCompate()
- {
- if (serverReturnCode == APP.ServerScuessCode)
- {
- data.Columns.Add("Value");
- data.Columns.Add("Key");
- for (int i = 0; i < APP.ClassList.Count; i++)
- {
-
- DataRow row = data.NewRow();
-
- data.Rows.Add(row);
- if (APP.ClassList[i].gradeid != null)
- {
- switch (APP.ClassList[i].gradeid)
- {
- case 1:
- data.Rows[i]["Value"] = "一年级" + APP.ClassList[i].classname;
- break;
- case 2:
- data.Rows[i]["Value"] = "二年级" + APP.ClassList[i].classname;
- break;
- case 3:
- data.Rows[i]["Value"] = "三年级" + APP.ClassList[i].classname;
- break;
- case 4:
- data.Rows[i]["Value"] = "四年级" + APP.ClassList[i].classname;
- break;
- case 5:
- data.Rows[i]["Value"] = "五年级" + APP.ClassList[i].classname;
- break;
- case 6:
- data.Rows[i]["Value"] = "六年级" + APP.ClassList[i].classname;
- break;
- case 7:
- data.Rows[i]["Value"] = "七年级" + APP.ClassList[i].classname;
- break;
- case 8:
- data.Rows[i]["Value"] = "八年级" + APP.ClassList[i].classname;
- break;
- case 9:
- data.Rows[i]["Value"] = "九年级" + APP.ClassList[i].classname;
- break;
- case 10:
- data.Rows[i]["Value"] = "高一" + APP.ClassList[i].classname;
- break;
- case 11:
- data.Rows[i]["Value"] = "高二" + APP.ClassList[i].classname;
- break;
- case 12:
- data.Rows[i]["Value"] = "高三" + APP.ClassList[i].classname;
- break;
- default:
- data.Rows[i]["Value"] = APP.ClassList[i].classname;
- break;
- }
- }
- else
- {
- data.Rows[i]["Value"] = APP.ClassList[i].classname;
- }
-
- data.Rows[i]["Key"] = APP.ClassList[i].classid;
- }
- dtComponentsUniqueNo = data.DefaultView.ToTable();
- cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
- cmbClass.SelectedIndex = 0;
-
- }
- else
- {
- MessageWindow.Show(APP.ErrorMessage);
- }
- }
-
-
-
-
- private object InvokeTsubjectbookListServering()
- {
- serverReturnCode = registerController.TsubjectbookList();
- return APP.ErrorMessage;
- }
-
-
-
-
- public void InvokeServerTsubjectbookListCompate()
- {
- if (serverReturnCode == APP.ServerScuessCode)
- {
- try
- {
- if (File.Exists(APP.dataPath + "loginUserid.txt"))
- {
- string userid = System.IO.File.ReadAllText(APP.dataPath + "loginUserid.txt", Encoding.Default);
- if (userid.Equals(APP.LoginUser.userid.ToString()))
- {
- if (File.Exists(APP.dataPath + "loginLsbid.txt"))
- {
- string lsbid = System.IO.File.ReadAllText(APP.dataPath + "loginLsbid.txt", Encoding.Default);
- lsbids = Convert.ToInt32(lsbid);
- if (File.Exists(APP.dataPath + "loginDirectorid.txt"))
- {
- string directorid = System.IO.File.ReadAllText(APP.dataPath + "loginDirectorid.txt", Encoding.Default);
- directorids = Convert.ToInt32(directorid);
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【登陆(LoginWindow)" + ex.Message, ex);
- }
- int iTemp = 0;
- for (int i = 0; i < APP.TsubjectbookList.Count; i++)
- {
- if (lsbids != 0 && lsbids == APP.TsubjectbookList[i].lsbid)
- {
- iTemp = i;
- }
- pageData.bookList.Add(new ComboBoxBeanModel()
- {
- Key = APP.TsubjectbookList[i].lsbid,
- Value = $"{APP.TsubjectbookList[i].subjectname} {APP.TsubjectbookList[i].bookname}"
- });
- }
- book_list.SelectedIndex = iTemp;
- DataContext = pageData;
- }
- else
- {
- MessageWindow.Show(APP.ErrorMessage);
- }
- }
-
-
-
-
- private string InvokeDirectorListServering(int index)
- {
- int selectIndex = index;
- if (selectIndex != -1)
- {
- APP.lsbid = APP.TsubjectbookList[selectIndex].lsbid;
- APP.REQStartClass.subjectid = APP.TsubjectbookList[selectIndex].subjectid;
- APP.REQStartClass.subjectname = APP.TsubjectbookList[selectIndex].subjectname;
- APP.DirectorList = null;
- serverReturnCode = registerController.DirectorList(APP.TsubjectbookList[selectIndex].lsbid,2,APP.LoginUser.userid);
- }
- return APP.ErrorMessage;
- }
-
-
-
-
- public void InvokeServerDirectorListCompate()
- {
- if (serverReturnCode == APP.ServerScuessCode)
- {
- pageData.zhangjieList.Clear();
- for (int i = 0; i < APP.DirectorList.Count; i++)
- {
- DirectorListModel item = APP.DirectorList[i];
- pageData.zhangjieList.Add(new ComboBoxBeanModel()
- {
- Key = item.directorid,
- Value = item.directorname
- });
- addChild(item);
- }
- cmbTeachingMaterial.SelectedIndex = 0;
- for (int i = 0; i < pageData.zhangjieList.Count; i++)
- {
- if (pageData.zhangjieList[i].Key == directorids)
- {
- cmbTeachingMaterial.SelectedIndex = i;
- }
- }
- }
- else
- {
- MessageWindow.Show(APP.ErrorMessage);
- }
- }
-
-
-
-
- private void addChild(DirectorListModel directorList)
- {
- if (directorList.children != null && directorList.children.Count > 0)
- {
- foreach (DirectorListModel child in directorList.children)
- {
- pageData.zhangjieList.Add(new ComboBoxBeanModel()
- {
- Key = child.directorid,
- Value = getSpace(child.directorlevel) + child.directorname
- });
- if (child.children != null && child.children.Count > 0)
- {
- addChild(child);
- }
- }
- }
- }
-
-
-
-
-
- private string getSpace(int num)
- {
- string str = "";
- for (int i = 0; i < num; i++)
- {
- str += " ";
- }
- return str;
- }
-
-
-
-
- private object InvokeStartClassServering()
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return APP.ErrorMessage;
- }
-
-
-
-
- public void InvokeStartClassCompate(object obj)
- {
- try
- {
- APP.myloading.Hide();
- string imagepath = APP.classRoomImagePath();
- if (!Directory.Exists(imagepath))
- {
- Directory.CreateDirectory(imagepath);
- }
-
- ToolbarWindow win = new ToolbarWindow();
-
- Close();
- win.ShowDialog();
- }
- catch (Exception ex)
- {
-
- LogHelper.WriteErrLog("【LoginWindow】(InvokeStartClassCompate)" + ex.Message, ex);
- }
-
- }
-
-
-
-
- private object InvokeClassStudentListServering()
- {
-
- return APP.ErrorMessage;
- }
-
-
-
-
- public void InvokeServerClassStudentListCompate(object obj)
- {
-
- if (serverReturnCode == APP.ServerScuessCode)
- {
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeStartClassServering, InvokeStartClassCompate);
- }
- else
- {
- APP.myloading.Hide();
- MessageWindow.Show(APP.ErrorMessage);
- }
- }
- #endregion 方法
-
- private DataTable dtComponentsUniqueNo;
- public DataTable DtComponentsUniqueNo
- {
- get => dtComponentsUniqueNo;
- set => dtComponentsUniqueNo = value;
- }
- private void txbAccountNumber_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- txbAccountNumber.Text = "";
- txbAccountNumber.Tag = "";
- }
-
-
-
-
-
-
-
- private void ckSaveName_Click(object sender, RoutedEventArgs e)
- {
- if (ckSaveName.IsChecked == false)
- {
- UpdateSettingString("isRemind", ckSaveName.IsChecked.ToString());
- }
- else
- {
- UpdateSettingString("isRemind", ckSaveName.IsChecked.ToString());
- }
- }
-
- public void downloadBegin(int position)
- {
- }
-
- public void downloadProgress(int position, int progress)
- {
- }
-
- public void downloadEnd(int position, string filepath)
- {
- Console.WriteLine("下载完成" + filepath + " position:" + position);
- }
-
-
-
-
-
-
- private void toolbar_list_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- int SelectedIndex = book_list.SelectedIndex;
- new Thread(o =>
- {
- InvokeDirectorListServering(SelectedIndex);
- Dispatcher.Invoke(new Action(() =>
- {
- InvokeServerDirectorListCompate();
- }));
- }).Start();
- }
-
-
-
-
-
-
- private void btnSetUp_Click(object sender, RoutedEventArgs e)
- {
-
-
-
-
-
- }
-
- public void downloadError(int position, string msg)
- {
- MessageWindow.Show(msg);
- }
- }
-
- public class LoginPageData : NotifyModel
- {
- public ObservableCollection<ComboBoxBeanModel> bookList { get; set; }
-
- public ObservableCollection<ComboBoxBeanModel> zhangjieList { get; set; }
-
- public LoginPageData()
- {
- bookList = new ObservableCollection<ComboBoxBeanModel>();
- zhangjieList = new ObservableCollection<ComboBoxBeanModel>();
- }
- }
- }
|