XPO随写

来源:互联网 发布:新网已备案域名 编辑:程序博客网 时间:2024/06/08 13:33
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using ABDoor.Module;
using InformationDisplay.Infrastructure;
using InformationDisplay;
using DevExpress.ExpressApp.Scheduler;
using ABDoor.Module.Helper;
namespace InformationDisplayForm
{
  
    public partial class InformationForm : Form
    {
        private int y = 50;//定义GruopBox的初始纵坐标
        private GroupBox groupBox;
        private Policemen currentUser;
        
        public InformationForm()
        {
            InitializeComponent();
        }
        public InformationForm(Policemen currentUser)
        {
            InitializeComponent();
            this.currentUser = currentUser;
        }
        delegate void ForHelpChange(string s, string z);
        private DataTable dtTable = new DataTable();
        private ConfirmationForm cf;
        private bool isShowing;
        RALIDHelper ralidHelper;
        string doorAdds = System.Configuration.ConfigurationManager.AppSettings["inDoorAddress"].ToString();
        private void InformationForm_Load(object sender, EventArgs e)
        {
            //设置窗体允许滚动条
            this.AutoScroll = true;


            //启用监听
             ralidHelper = new RALIDHelper(this);
            ralidHelper.Connect();
            ralidHelper.SendSystemType();


            //设置窗体皮肤
            //skinEngine1.SkinFile = Application.StartupPath + @"\MSN.ssk";


            //创建表头
            DataColumn dtColumn1 = new DataColumn("卡号", typeof(string));
            DataColumn dtColumn2 = new DataColumn("姓名", typeof(string));
            DataColumn dtColumn3 = new DataColumn("性别", typeof(string));
            DataColumn dtColumn4 = new DataColumn("人员类型", typeof(string));
            DataColumn dtColumn5 = new DataColumn("开门记录", typeof(string));
            DataColumn dtColumn6 = new DataColumn("方向", typeof(string));
            dtTable.Columns.Add(dtColumn1);
            dtTable.Columns.Add(dtColumn2);
            dtTable.Columns.Add(dtColumn3);
            dtTable.Columns.Add(dtColumn4);
            dtTable.Columns.Add(dtColumn5);
            dtTable.Columns.Add(dtColumn6);
        }
        private static Session DefaultSession = AppContext.Current.DefaultSession;
        private ABDoor.Module.AccessCard accessCard;
        Person person;


        /// <summary>
        /// 获取信息及判断,显示到dataGridView1中
        /// </summary>
        /// <param name="Direction">进出方向</param>
        /// <param name="CardId">卡号ID</param>
        public void ReadData(string CardId, string Direction)
        {


            if (!InvokeRequired)
            {
                Display(CardId);


                //创建行记录
                DataRow dr = dtTable.NewRow();
                dr["卡号"] = accessCard.CardId;
                dr["姓名"] = person.FullName;
                dr["性别"] = person.Gender;
                dr["人员类型"] = person.PersonType;


                if (person.PersonType.ToString() == "")
                {
                    dr["开门记录"] = "开门";
                    isShowing = false;
                    ralidHelper.OpenDoor(doorAdds,currentUser.FullName);
                }
                else
                {
                    cf = new ConfirmationForm();
                    cf.ShowDialog();
                    string operateResult=cf.DialogResult == DialogResult.OK ? "开门" : "关门";
                    if(operateResult=="开门")
                    {
                        ralidHelper.OpenDoor(doorAdds, currentUser.FullName);
                    }
                    dr["开门记录"] = operateResult;
                    isShowing = false;


                }
                dr["方向"] = Direction;
                dtTable.Rows.Add(dr);
                dataGridView1.DataSource = dtTable;
                if (accessCard != null)
                {
                    try
                    {
                        AccessLog accessLog = new AccessLog(DefaultSession);
                        accessLog.CardId = accessCard.CardId;
                        if (Direction == "A门进")
                        {
                            accessLog.ReaderId = System.Configuration.ConfigurationManager.AppSettings["inReaderID"].ToString();
                            accessLog.Direction = ABDoor.Module.Direction.进;
                        }
                        else
                        {
                            accessLog.ReaderId = System.Configuration.ConfigurationManager.AppSettings["outReaderID"].ToString();
                            accessLog.Direction = ABDoor.Module.Direction.出;
                        }


                        accessLog.EnterDate = DateTimeHelper.GetServerTime(DefaultSession);
                        accessLog.AccessCard = accessCard;
                        accessLog.IssuePolice = currentUser;
                        accessLog.Save();
                        accessCard.Save();
                    }
                    catch (Exception ex)
                    {
                                           }
                }
            }
            else
            {
                ForHelpChange fhc = new ForHelpChange(ReadData);
                Invoke(fhc, new object[] { CardId, Direction });
            }


        }


        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="CardId">卡号ID</param>
        public void Display(string CardId)
        {
            if (isShowing == true)
            {
                return;
            }


            accessCard = DefaultSession.FindObject<AccessCard>(CriteriaOperator.Parse("CardId=?", CardId));


            if (accessCard == null)
            {
                
                MessageBox.Show("系统无该卡记录");
            }
            else
            {
                //tb_CardId.Text = accessCard.CardId;
                ////通过accessCard表和Person中的一对一关系获取到Person对象
                //person = accessCard.Person;
                //Picture.Image = person.Picture;
                //tb_PersonType.Text = person.PersonType.ToString();
                //tb_IDNumber.Text = person.IDNumber;
                //tb_FullName.Text = person.FullName;
                //tb_Gender.Text = person.Gender.ToString();
                //tb_Mobile.Text = person.Mobile;
                //tb_HomePhone.Text = person.HomePhone;
                //tb_HomeAddress.Text = person.HomeAddress;
                //tb_Email.Text = person.Email;
                //tb_Mobile.Text = person.Mobile;
                //tb_OfficePhone.Text = person.OfficePhone;
                isShowing = true;
            }


        }




        /// <summary>
        /// 新建一个GroupBox
        /// </summary>
        public void GetGroupBox()
        {
            groupBox = new GroupBox();
            groupBox.Width = 550;
            groupBox.Height = 300;
            groupBox.Location = new Point(450, y);
            this.Controls.Add(groupBox);
            GetLabel(groupBox);
            GetText(groupBox);
            GetPictureBox(groupBox);
        }
        /// <summary>
        /// 新建label标签
        /// </summary>
        /// <param name="gb"></param>
        public void GetLabel(GroupBox gb)
        {
            string[] str = new string[] { "用户名", "部门", "卡号", "刷卡时间", "事件说明" };


            for (int i = 0; i < 5; i++)
            {
                Label label = new Label();
                label.Text = str[i];
                label.Font = new Font("宋体", 14);
                label.Location = new Point(250, 40 + i * 50);
                gb.Controls.Add(label);


            }




        }
        /// <summary>
        /// 新建文本框
        /// </summary>
        /// <param name="gb"></pararm>
        public void GetText(GroupBox gb)
        {
            string[] str;


            for (int i = 0; i < 5; i++)
            {
                TextBox textBox = new TextBox();
                textBox.Width = 250;
                textBox.Height = 50;
                textBox.Location = new Point(280, 40 + i * 50);
                gb.Controls.Add(textBox);


            }


        }
        /// <summary>
        /// 新建图片
        /// </summary>
        /// <param name="gb"></param>
        public void GetPictureBox(GroupBox gb)
        {
            PictureBox picture = new PictureBox();
            picture.BorderStyle = BorderStyle.FixedSingle;
            picture.Width = 200;
            picture.Height = 250;
            picture.Location = new Point(30, 30);
            gb.Controls.Add(picture);






        }


        private void InformationForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            System.Environment.Exit(0);
        }


        
      
        //当接收到数据时,改变下一个group的纵坐标
        private void InformationForm_ControlAdded(object sender, ControlEventArgs e)
        {
            y += 350;
        
        } 
    }
}
原创粉丝点击