public byte[] ClntBufPrep() { byte[] outBuf; switch (mState) { case NetPhase.Submiting: mExaminee.ToByte(out outBuf, (int)mState); break; default: outBuf = null; break; } return(outBuf); }
public bool SrvrBufHndl(byte[] buf, out byte[] outMsg) { outMsg = null; int offs = 0; NetCode c = (NetCode)BitConverter.ToInt32(buf, offs); offs += 4; QuestSheet qs; int lvid; ExamineeA e; DateTime dt; switch (c) { case NetCode.Dating: outMsg = new byte[DT.BYTE_COUNT]; offs = 0; DT.ToByte(outMsg, ref offs, mBrd.mDt); return(true); case NetCode.Authenticating: e = new ExamineeS1(); e.bFromC = true; e.ReadByte(buf, ref offs); bool lck = true; bool found = false; foreach (SortedList <int, bool> l in vfbLock) { if (l.TryGetValue(e.LvId, out lck)) { found = true; break; } } if (!found) { lck = false; } if (!lck) { ExamineeA o = null; dt = DateTime.Now; foreach (ExamSlot sl in mBrd.Slots.Values) { if ((o = sl.Signin(e)) != null) { dt = sl.Dt; break; } } if (o != null) { if (o.dtTim1.Hour == DT.INV) { o.dtTim1 = DateTime.Now; } Dispatcher.InvokeAsync(() => { foreach (Op1SlotView vw in tbcSl.Items.OfType <Op1SlotView>()) { TextBlock t; lvid = o.LvId; if (vw.vComp.TryGetValue(lvid, out t)) { t.Text = o.tComp; } if (vw.vDt1.TryGetValue(lvid, out t)) { t.Text = o.dtTim1.ToString("HH:mm"); } CheckBox cbx; if (vw.vLock.TryGetValue(lvid, out cbx)) { cbx.IsChecked = true; cbx.IsEnabled = true; } if (vw.vbLock.Keys.Contains(lvid)) { vw.vbLock[lvid] = true; } } }); byte[] a; o.bFromC = true; o.ToByte(out a); outMsg = new byte[4 + a.Length]; Buffer.BlockCopy(BitConverter.GetBytes(0), 0, outMsg, 0, 4); Buffer.BlockCopy(a, 0, outMsg, 4, a.Length); } else { outMsg = new byte[4]; Buffer.BlockCopy(BitConverter.GetBytes((int)TxI.SIGNIN_NOK), 0, outMsg, 0, 4); return(false); //close } } else { ExamineeA o = null; foreach (ExamSlot sl in mBrd.Slots.Values) { if ((o = sl.Find(e.LvId)) != null) { break; } } if (o == null) { o = new ExamineeC(e.tId); } if (o.tComp == null) { outMsg = new byte[16]; } else { outMsg = new byte[16 + o.tComp.Length]; } Buffer.BlockCopy(BitConverter.GetBytes((int)TxI.SIGNIN_AL), 0, outMsg, 0, 4); if (o.tComp == null) { Buffer.BlockCopy(BitConverter.GetBytes(0), 0, outMsg, 4, 4); offs = 8; } else { byte[] comp = Encoding.UTF8.GetBytes(o.tComp); Buffer.BlockCopy(BitConverter.GetBytes(comp.Length), 0, outMsg, 4, 4); offs = 8; Buffer.BlockCopy(comp, 0, outMsg, offs, o.tComp.Length); offs += comp.Length; } Buffer.BlockCopy(BitConverter.GetBytes(o.dtTim1.Hour), 0, outMsg, offs, 4); offs += 4; Buffer.BlockCopy(BitConverter.GetBytes(o.dtTim1.Minute), 0, outMsg, offs, 4); break; } return(true); case NetCode.ExamRetrieving: outMsg = null; lvid = BitConverter.ToInt32(buf, offs); ExamSlot slo = null; foreach (ExamSlot s in mBrd.Slots.Values) { foreach (ExamRoom r in s.Rooms.Values) { if (r.vExaminee.ContainsKey(lvid)) { slo = s; break; } } } if (slo == null) { outMsg = new byte[4]; Array.Copy(BitConverter.GetBytes((int)TxI.NEEID_NF), 0, outMsg, 0, 4); break; } Level lv = (lvid < (int)Level.MAX_COUNT_EACH_LEVEL) ? Level.A : Level.B; offs += 4; int qsid = BitConverter.ToInt32(buf, offs); if (qsid == (int)Level.MAX_COUNT_EACH_LEVEL) { byte[] a = slo.ToByteNextQS(lv); if (a != null) { outMsg = new byte[a.Length + 4]; Array.Copy(BitConverter.GetBytes(0), outMsg, 4); Array.Copy(a, 0, outMsg, 4, a.Length); } } else if (slo.MainPacks[lv].Sheets.TryGetValue(qsid, out qs)) { outMsg = new byte[qs.ItemsInBytes.Length + 4]; Array.Copy(BitConverter.GetBytes(0), outMsg, 4); Array.Copy(qs.ItemsInBytes, 0, outMsg, 4, qs.ItemsInBytes.Length); } if (outMsg == null) { mCbMsg += Txt.s._[(int)TxI.QS_NFOUND] + (qsid); outMsg = new byte[8]; Array.Copy(BitConverter.GetBytes((int)TxI.QS_NFOUND), 0, outMsg, 0, 4); Array.Copy(BitConverter.GetBytes(qsid), 0, outMsg, 4, 4); } break; case NetCode.Submiting: e = new ExamineeS1(); e.bFromC = true; if (!e.ReadByte(buf, ref offs)) { AnsSheet keySh = null; found = false; foreach (ExamSlot sl in mBrd.Slots.Values) { if (sl.mKeyPack.Sheets.TryGetValue(e.mAnsSh.uQSLvId, out keySh)) { found = true; break; } } if (!found) { outMsg = BitConverter.GetBytes(101); //todo break; } ExamineeA o = null; lvid = e.LvId; found = false; foreach (ExamSlot sl in mBrd.Slots.Values) { if ((o = sl.Find(lvid)) != null) { break; } } if (o != null) { o.eStt = NeeStt.Finished; o.mAnsSh = e.mAnsSh; o.uGrade = keySh.Grade(e.mAnsSh.aAns); o.dtTim2 = DateTime.Now; foreach (SortedList <int, bool> sl in vfbLock) { if (sl.ContainsKey(lvid)) { sl[lvid] = true; } } Dispatcher.InvokeAsync(() => { bool toSubm = true; foreach (Op1SlotView vw in tbcSl.Items.OfType <Op1SlotView>()) { TextBlock t = null; if (vw.vDt2.TryGetValue(lvid, out t)) { t.Text = o.dtTim2.ToString("HH:mm"); } if (vw.vMark.TryGetValue(lvid, out t)) { t.Text = o.Grade.ToString(); } CheckBox cbx; if (vw.vLock.TryGetValue(lvid, out cbx)) { cbx.IsChecked = true; cbx.IsEnabled = false; } if (vw.vAbsen.TryGetValue(lvid, out cbx)) { cbx.IsChecked = cbx.IsEnabled = false; } if (!vw.ToSubmit()) { toSubm = false; } } if (toSubm) { ToSubmit(true); } }); o.ToByte(out outMsg, 0); } else { mCbMsg += Txt.s._[(int)TxI.NEEID_NF] + ' ' + lvid; outMsg = BitConverter.GetBytes((int)TxI.NEEID_NF); } } else { mCbMsg += Txt.s._[(int)TxI.RECV_DAT_ER]; outMsg = BitConverter.GetBytes((int)TxI.RECV_DAT_ER); } break; default: outMsg = null; break; } return(false); }