private void search_Click(object sender, EventArgs e) { string uid = IDtxt.Text; if (uid != "") { User utemp = new User(); try { for (int i = 0; ; i++) { utemp = FileDate.ReadOne <User>(i); if (utemp.ID == uid) { v = utemp.Valid; alteredOne = i; state.Text = v ? "正常" : "被冻结"; opt.Text = v ? "冻结账号" : "解除冻结"; FreezeShow(); break; } } } catch (ArgumentOutOfRangeException) { state.Text = "未找到账号相关信息"; } } }
private void opt_Click(object sender, EventArgs e) { if (!Check()) { return; } if (!utemp.Valid) { //如果操作者权限大于被操作者,操作有效 if (Main.priorityOver(utemp.Pri)) { if (utemp.Balance < 0) { MessageBox.Show("请帮TA充值后再尝试解冻", "账户余额不足", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { utemp.Valid = true; FileDate.AlterInfo(utemp); FileDate.MatchRecord(OptType.冻结, "123456", utemp.ID); MessageBox.Show("账户解冻成功.", "通知"); } } } else { //如果账号正常那么就无需解冻 MessageBox.Show("无效的操作!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); }
private void confirm_Click(object sender, EventArgs e) { if (Check()) { uint sum = Convert.ToUInt32(NUMtxt.Text); Book book = new Book(bknametxt.Text, isbntxt.Text, presstxt.Text, authortxt.Text, (BookType)bkTypebox.SelectedIndex); BookMaster master = new BookMaster(sum, book); if (FileDate.Exist <BookMaster>(master)) { DialogResult dr = MessageBox.Show("此书已经存在,要直接添加吗(将会增加总数量)?", "重要提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { master.Total_num += sum; FileDate.AlterInfo <BookMaster>(master); } else { return; } } else { FileDate.WriteInfo(master); MessageBox.Show("书籍添加成功!", "通知"); } } }
private void opt_Click(object sender, EventArgs e) { //--------------------- User utemp = FileDate.ReadOne <User>(alteredOne); string tip = utemp.Valid ? "被冻结" : "解除冻结"; DialogResult dr = MessageBox.Show(utemp.ID + "即将" + tip, "重要提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { if (utemp.Pri > Main.user.Pri || (int)utemp.Pri == 3) { MessageBox.Show("你没有足够的权限执行此操作", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (utemp.Valid) { int dur = Convert.ToInt32(Days.Text); FileDate.WriteInfo <Record>(new Record(OptType.冻结, Main.user.ID, utemp.ID, dur)); } utemp.Valid = !utemp.Valid; FileDate.WriteInfo <User>(utemp, alteredOne); MessageBox.Show("操作成功!"); this.Close(); } } }
private void confirmbtn_Click(object sender, EventArgs e) { if (found) { Book book = master.Info; if (nameAlter.Checked) { book.Name = alteredInfotxt.Text; } else if (authAlter.Checked) { book.Author = alteredInfotxt.Text; } else if (isbnAlter.Checked) { book.ISBN = alteredInfotxt.Text; } else if (pressAlter.Checked) { book.Press = alteredInfotxt.Text; } else { tipslb.Text = "请选择要修改哪一项"; return; } master = new BookMaster(master.Total_num, book); MessageBox.Show("修改成功", "通知", MessageBoxButtons.OK, MessageBoxIcon.Information); FileDate.AlterInfo <BookMaster>(master); } }
private void searchbtn_Click(object sender, EventArgs e) { string isbn = isbntxt.Text; //重复点击直接跳过 if (master.Info.ISBN == isbn || "" == isbn) { if (isbn != "") { display(); } else { tipslb.Text = "ISBN不能为空"; } return; } List <BookMaster> list = FileDate.SearchByISBN(isbn); if (list.Count > 0) { master = list[0]; found = true; display(); } else { showInfotxt.Text = "未找到相关信息,确认ISBN输入是否正确"; } }
private void button1_Click(object sender, EventArgs e) { if (AccountIDtxt.Text == "" || Passwordtxt.Text == "" || nametxt.Text == "") { MessageBox.Show("信息填写不能为空,请完善信息!", "温馨提示"); return; } if (checkPwdtxt.Text != Passwordtxt.Text) { MessageBox.Show("两次密码输入不一致!", "温馨提示"); return; } if (stu.Checked || worker.Checked) { Privilege pri = Privilege.学生; if (worker.Checked) { pri = Privilege.职工; } bool ismale = Convert.ToBoolean(gender.SelectedIndex); User user = new User(ismale, pri, AccountIDtxt.Text, nametxt.Text, Passwordtxt.Text); if (FileDate.Exist <User>(user)) { MessageBox.Show("该用户已经存在!", "通知", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } FileDate.WriteInfo(user); tipslb.Text = "用户信息添加成功!"; AccountIDtxt.Text = nametxt.Text = Passwordtxt.Text = checkPwdtxt.Text = ""; } else { MessageBox.Show("请选择用户身份!", "提示"); } }
private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e) { uint size = FileDate.CountOf <Record>(); for (int i = 0; i < size; i++) { FileDate.ReadOne <Record>(i).debug(); } }
private void update() { Statelb.Text = Main.user.Valid ? "正常" : "被冻结"; bor_numlb.Text = Main.user.BorrowBook.Count.ToString(); balancelb.Text = Main.user.Balance.ToString(); table.Clear(); foreach (uint bkid in Main.user.BorrowBook) { Book book = FileDate.FindObjByID <BookMaster>(bkid.ToString()).Info; table.Rows.Add(book.Name, book.Author, book.ISBN, book.Press, book.Type, "已借阅"); table.AcceptChanges(); } }
private void dataGridView1_DoubleClick(object sender, EventArgs e) { if (dataGridView1.SelectedRows[0].IsNewRow) { return; } DialogResult dr = MessageBox.Show("确定要归还这本书吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { string isbn = dataGridView1.SelectedRows[0].Cells[2].Value.ToString(); Main.user.givebackTo(FileDate.SearchByISBN(isbn)[0]); } }
private void search_Click(object sender, EventArgs e) { string uid = IDtxt.Text; FindUser = FileDate.Exist <User>(new User(uid)); if (FindUser) { utemp = FileDate.FindObjByID <User>(uid); state.Text = utemp.Valid ? "正常" : "被冻结"; } else { state.Text = "未找到账号相关信息"; } }
private List <BookMaster> SearchByKeyword(Book book) { List <BookMaster> bklist = new List <BookMaster>(); BookMaster master = new BookMaster(); uint size = FileDate.CountOf <BookMaster>(); for (int i = 0; i < size; i++) { master = FileDate.ReadOne <BookMaster>(i); if (master.SimiliarTo(book)) { bklist.Add(master); } } return(bklist); }
private void Confirmbtn_Click(object sender, EventArgs e) { bool done = false; if (AccountIDtxt.Text == "" || OriPwdtxt.Text == "" || NewPwdtxt.Text == "") { Tipslb.Text = "信息不能为空!请首先完善信息"; } else if (RepeatPwdtxt.Text != NewPwdtxt.Text) { Tipslb.Text = "两次输入新密码不一致!请确认密码一致"; } else { User utemp = new User(OriPwdtxt.Text.Trim()); if (FileDate.Exist <User>(utemp)) { if (utemp.Valid) { utemp.Pwd = NewPwdtxt.Text; FileDate.AlterInfo(utemp); done = true; } else { Tipslb.Text = "账号已被冻结!请首先联系管理员解除冻结状态!"; } } else { Tipslb.Text = "未找到用户信息!请确认是否输入了正确的信息"; } } if (done) { DialogResult dr = MessageBox.Show("修改密码成功!需要重新登录你的账号,是否愿意?", "提示信息:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); this.Close(); if (dr == DialogResult.OK) { relog.ShowDialog(); } else { Main.user = new User("匿名游客"); } } }
private void delbtn_Click(object sender, EventArgs e) { if (found) { DialogResult dr = MessageBox.Show("确定要删除这类书吗?", "重要提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { FileDate.Delete <BookMaster>(master); master = new BookMaster(); showInfotxt.Text = ""; } } else { tipslb.Text = "请先确认书籍信息再进行操作"; } }
//根据ID找到对象 public static T FindObjByID <T>(string id) where T : IGet, new() { try { for (int i = 0; ; i++) { if (FileDate.ReadOne <T>(i).GetID() == id) { return(FileDate.ReadOne <T>(i)); } } } catch (ArgumentOutOfRangeException) { MessageBox.Show("未找到用户信息!", "提示"); } return(new T()); }
//对象是否已经存在 public static bool Exist <T>(T t) where T : IGet, new() { try { T t2 = new T(); for (int i = 0; ; i++) { t2 = FileDate.ReadOne <T>(i); if (t.GetID().ToLower() == t2.GetID().ToLower() || t.GetName().ToLower() == t2.GetName().ToLower()) { return(true); } } } catch (ArgumentOutOfRangeException) { } return(false); }
private void confirm_Click(object sender, EventArgs e) { if (Vis.Checked) { Main.user = new User("Visitor"); qual = true; } else if (!(Stu.Checked || Worker.Checked || Admin.Checked)) { MessageBox.Show("请选择你的登录身份!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { User utemp = new User(); uint size = FileDate.CountOf <User>(); for (int i = 0; i < size; i++) { utemp = FileDate.ReadOne <User>(i); if (utemp.ID == IDtxt.Text && utemp.Pwd == PWDtxt.Text) { if ((Stu.Checked && utemp.Pri == Privilege.学生) || (Worker.Checked && utemp.Pri == Privilege.职工) || (Admin.Checked && utemp.Pri == Privilege.管理员)) { qual = true; Main.user = new User(utemp); main.updateStatus(); break; } } } } if (qual) { this.Close(); } else { MessageBox.Show("未找到用户信息,用户名或密码或者登录身份错误.", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
//通过ISBN来找到书籍(书籍ISBN是唯一的,可以当做一个标识) public static List <BookMaster> SearchByISBN(string isbn) { BookMaster master = new BookMaster(); uint count = FileDate.CountOf <BookMaster>(); List <BookMaster> bklist = new List <BookMaster>(1); for (int i = 0; i < count; i++) { master = FileDate.ReadOne <BookMaster>(i); if (master.Info.ISBN.Contains(isbn)) { bklist.Add(master); break; } } if (bklist.Count == 0) { MessageBox.Show("未找到该ISBN编号的书", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(bklist); }
private List <Record> RecordWithinSpan(int span) { List <Record> reclist = new List <Record>(); int len = (int)FileDate.CountOf <Record>(); int size = Marshal.SizeOf(typeof(Record)); Record rec = new Record(); for (int i = 1; i <= len; i++) { rec = FileDate.ReadOne <Record>(len - i); if (rec.spanDaysToPresent() <= span) { reclist.Add(rec); } else { break; } } return(reclist); }
public Main() { InitializeComponent(); if (File.Exists("Lib_Mana_Sys.User.dat")) { File.Delete("Lib_Mana_Sys.User.dat"); } if (File.Exists("Lib_Mana_Sys.BookMaster.dat")) { File.Delete("Lib_Mana_Sys.BookMaster.dat"); } if (File.Exists("Lib_Mana_Sys.Record.dat")) { File.Delete("Lib_Mana_Sys.Record.dat"); } User u1 = new User(true, Privilege.学生, "16020031111", "OUCer", "123456"); User u2 = new User(false, Privilege.职工, "16020031231", "玉良红", "987452"); User u3 = new User(true, Privilege.学生, "16020031561", "梁园", "654123"); User u4 = new User(true, Privilege.管理员, "123456", "Master", "123456"); Book b1 = new Book("Java从入门到放弃", "123456", "人民教育出版社", "Master", BookType.数理科学与化学); BookMaster master = new BookMaster(10, b1); FileDate.WriteInfo(master); Book b2 = new Book("C Plus从入门到入土", "1156416454652", "仁爱教育出版社", "Oh Yes", BookType.哲学宗教); for (uint i = 100; i < 200; i++) { string ment = i.ToString(); Book b = new Book("英雄联盟" + ment, ment, "大魔王出版社", "Faker" + ment, BookType.综合性图书); BookMaster m = new BookMaster(2, b); FileDate.WriteInfo(m); } master = new BookMaster(6, b2); FileDate.WriteInfo(master); FileDate.WriteInfo(u2); FileDate.WriteInfo(u3); FileDate.WriteInfo(u4); FileDate.WriteInfo(u1); login = new Login(this); }
private void opt_Click(object sender, EventArgs e) { if (!Check()) { return; } bool firm = false; if (utemp.Valid) { //冻结自身账号 if (Main.user.ID == utemp.ID) { DialogResult dr = MessageBox.Show("确定要冻结自身账号?", "重要提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); firm = dr == DialogResult.Yes; } else { //如果操作者权限高于被操作者,操作有效 //if (Main.priorityOver(utemp.Pri)) firm = true; //如果是管理员,操作有效 firm = Main.user.Pri == Privilege.管理员; } if (firm) { int dur = Convert.ToInt32(Days.Text); utemp.Valid = false; FileDate.AlterInfo <User>(utemp); FileDate.WriteInfo <Record>(new Record(OptType.冻结, "123456", utemp.ID, dur)); MessageBox.Show("冻结账户成功.", "通知"); } } else { //账号已经被冻结 MessageBox.Show("无效的操作!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); }
//与以前的记录匹配,成为历史记录 public static void MatchRecord(OptType tp, string opt, string obj) { if (!File.Exists("Lib_Mana_Sys.User.dat")) { return; } int len = 0; using (FileStream fs = new FileStream("Lib_Mana_Sys.Record.dat", FileMode.Open)) { len = (int)fs.Length / Marshal.SizeOf(typeof(Record)); } Record rec = new Record(); for (int i = 1; i <= len; i++) { rec = FileDate.ReadOne <Record>(len - i); if (rec.Unmatch && rec.Type == tp && rec.Optor == opt && rec.Objer == obj) { FileDate.AlterInfo(rec.findMatch()); break; } } }
//删除对象(相当于将对象变为默认值) public static void Delete <T>(T t) where T : IGet, new() { int structsize = Marshal.SizeOf(typeof(T)); uint count = FileDate.CountOf <T>(); using (FileStream fs = new FileStream(t.ToString() + ".dat", FileMode.Open)) { using (BinaryReader br = new BinaryReader(fs)) { for (uint i = 0; i < count; i++) { if (Byte2Struct <T>(br.ReadBytes(structsize)).GetID() == t.GetID()) { using (BinaryWriter bw = new BinaryWriter(fs)) { fs.Position -= structsize; bw.Write(Struct2Byte <T>(new T())); } return; } } } } }
//更新当前用户数据 public static void update() { FileDate.AlterInfo(Main.user); }