예제 #1
0
        private void SelectCallDev_Load(object sender, EventArgs e)
        {
            string room;
            int    DevType = m_pass.ComboBoxDev.SelectedIndex + 2;

            if (DevType == (int)DeviceType.Indoor_Phone)
            {
                var query = from target in m_db.Devices
                            where (target.type == (int)DeviceType.Indoor_Phone || target.type == (int)DeviceType.Indoor_Phone_SD) &&
                            (target.online == 1)
                            select target;
                foreach (var dev in query)
                {
                    room = DevicesAddressConverter.RoToChStr(dev.roomid);
                    listBoxCallDev.Items.Add(room);
                }
            }
            else
            {
                var query = from target in m_db.Devices
                            where target.type == DevType &&
                            (target.online == 1)
                            select target;
                foreach (var dev in query)
                {
                    room = DevicesAddressConverter.RoToChStr(dev.roomid);
                    listBoxCallDev.Items.Add(room);
                }
            }
        }
예제 #2
0
        private void DataGridViewDevDataTable_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.Value == null)
            {
                return;
            }

            if (e.ColumnIndex == dgvTxtBoxColOnlineStatus.Index)
            {
                bool online = ((int)e.Value) != 0;
                e.Value = (!online) ? strings.offline : strings.online;
                e.CellStyle.BackColor = (!online) ? Color.Red : Color.LimeGreen;
            }
            else if (e.ColumnIndex == dgvTxtBoxColDeviceId.Index)
            {
                string DeviceId = (string)e.Value;
                e.Value = DevicesAddressConverter.RoToChStr(DeviceId);
            }
            else if (e.ColumnIndex == dgvComboBoxColDeviceType.Index)
            {
                int DeviceType = (int)e.Value;
                if (DeviceType < m_DeviceTypes.Count())
                {
                    e.Value = m_DeviceTypes[DeviceType];
                }
            }
        }
예제 #3
0
 private void eventwarnDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == dgvTextBoxAlarmSrc.Index)
     {
         string DeviceId = e.Value as string;
         e.Value = DevicesAddressConverter.RoToChStr(DeviceId);
     }
     else if (e.ColumnIndex == dgvTextBoxAlarmAction.Index)
     {
         string action = e.Value as string;
         if (action != null)
         {
             if (action == "trig")
             {
                 e.Value = "事件觸发";
             }
             else if (action == "unalarm")
             {
                 e.Value = "事件解除";
             }
             else if (action == "enable")
             {
                 e.Value = "佈防";
             }
             else if (action == "disable")
             {
                 e.Value = "撤防";
             }
             else
             {
                 e.Value = "";
             }
         }
     }
 }
예제 #4
0
        // 云服務管理 - 查询
        // 查询该房号下的 SIP Accounts
        private void BtnQuery_Click(object sender, EventArgs e)
        {
            listViewSIPAccount.Items.Clear();

            using (var db = new ICMDBContext())
            {
                string Address = "";
                string room    = "";
                {
                    Address = DevicesAddressConverter.ChStrToRo(maskedTextBoxRoom.Text);
                    if (Address == "")
                    {
                        return;
                    }
                    var SIPQuery = from sip in db.Sipaccounts
                                   where sip.C_room == Address
                                   select sip;
                    foreach (var sip in SIPQuery)
                    {
                        room = sip.C_room;//DevicesAddressConverter.RoToChStr(sip.C_room);//sip.room;
                        List <string> sublist = new List <string>();
                        sublist.Add(sip.C_user);
                        sublist.Add(DevicesAddressConverter.RoToChStr(room));
                        sublist.Add(sip.C_usergroup);
                        listViewSIPAccount.Items.Add(new ListViewItem(sublist.ToArray()));
                    }
                }
            }
        }
예제 #5
0
 private void BtnOK_Click(object sender, EventArgs e)
 {
     if (textBoxAccount.Text == "")
     {
         MessageBox.Show(strings.UserCannotBeNull);//"用户名不得为空");
         return;
     }
     using (var db = new ICMDBContext())
     {
         sipaccount SIP            = new sipaccount();
         string     account        = textBoxAccount.Text;
         var        checkNameExist = (from check in db.Sipaccounts
                                      where check.C_user == account
                                      select check).FirstOrDefault();
         if (checkNameExist != null)
         {
             MessageBox.Show("Account already exitst!\nPlease choose another name.");
             return;
         }
         SIP.C_user           = textBoxAccount.Text;
         SIP.C_password       = textBoxPasswd.Text;
         SIP.C_room           = DevicesAddressConverter.ChStrToRo(textBoxRoomID.Text);
         SIP.C_usergroup      = textBoxGroup.Text;
         SIP.C_updatetime     = DateTime.Now;
         SIP.C_sync           = 0;
         SIP.C_registerstatus = 0;
         SIP.C_randomcode     = randomcode.ToString();
         db.Sipaccounts.Add(SIP);
         db.SaveChanges();
     }
     this.Close();
 }
예제 #6
0
        private void RefreshSIPAccountsList()// async void RefreshSIPAccountsList()
        {
            listViewSIPAccount.Items.Clear();

            using (var db = new ICMDBContext())
            {
                foreach (var dev in db.Sipaccounts)
                {
                    string        room    = DevicesAddressConverter.RoToChStr(dev.C_room);
                    List <string> sublist = new List <string>();
                    int           online  = (int)(dev.C_registerstatus ?? 0);
                    if (online == 0)
                    {
                        sublist.Add(strings.offline);//"離線");
                    }
                    else
                    {
                        sublist.Add(strings.online);//"在線");
                    }
                    sublist.Add(dev.C_user);
                    sublist.Add(room);
                    sublist.Add(dev.C_usergroup);
                    listViewSIPAccount.Items.Add(new ListViewItem(sublist.ToArray()));
                }
            }
            //bindingSourceSIPAccounts.DataSource = await GetSIPAccountsAsync();
            //this.dataGridViewSIPAccounts.Invalidate();
        }
예제 #7
0
        private void MessageView_Load(object sender, EventArgs e)
        {
            using (var db = new ICMServer.Models.ICMDBContext())
            {
                /**
                 * Query modify item
                 **/
                var query = from zz in db.Publishinfoes
                            where zz.id == m_MsgId
                            select zz;
                foreach (var Msg in query)
                {
                    textBox.Visible    = false;
                    pictureBox.Visible = true;
                    textBoxTitle.Text  = Msg.title;
                    textBoxTime.Text   = Msg.time.ToString();
                    if (Msg.type == 1)
                    {
                        textBoxType.Text = "Image";
                    }
                    else
                    {
                        textBoxType.Text = "Text";
                    }
                    textBoxAddress.Text = DevicesAddressConverter.RoToChStr(Msg.dstaddr);

                    string picPath = Path.GetAppExeFolderPath() + @"\" + Msg.filepath;
                    pictureBox.Image = new Bitmap(picPath);
                }
            }
        }
예제 #8
0
 private void DataGridViewSIPAccounts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == dgvTxtBoxColSIPAccountStatus.Index)
     {
         e.Value = "離線";
     }
     else if (e.ColumnIndex == dgvTxtBoxColSIPAccountDeviceId.Index)
     {
         string DeviceId = (string)e.Value;
         DevicesAddressConverter.RoToChStr(DeviceId);
     }
 }
 private void DeviceDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == dgvTextBoxDeviceId.Index)
     {
         string DeviceId = e.Value as string;
         e.Value = DevicesAddressConverter.RoToChStr(DeviceId);
     }
     else if (e.ColumnIndex == dgvTextBoxDeviceType.Index)
     {
         int DeviceType = (int)e.Value;
         if (DeviceType < m_DeviceTypes.Count())
         {
             e.Value = m_DeviceTypes[DeviceType];
         }
     }
 }
예제 #10
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            string GroupID, RoomID = "";

            RoomID  = maskedTextBoxRoom.Text;
            GroupID = DevicesAddressConverter.ChStrToRo(RoomID);
            GroupID = GroupID.Replace("-", "");
            if (GroupID == "")
            {
                return;
            }
            DialogSIPAdd addsip = new DialogSIPAdd(RoomID, GroupID);

            addsip.ShowDialog();
            BtnQuery_Click(this, e);
        }
예제 #11
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            string addr = "";

            addr = DevicesAddressConverter.ChStrToRo(textBoxDeviceAddr.Text);
            string AddrIP = ipAddressControlDevIP.Text;
            string gate   = AddrIP;
            int    index  = gate.LastIndexOf(".");

            if (index > 0)
            {
                gate = gate.Substring(0, index + 1) + 1;
            }

            /**
             * Start fetch user input and save
             **/
            using (var db = new ICMDBContext())
            {
                Device dev = new Device();
                dev.ip     = AddrIP;
                dev.roomid = addr;
                dev.Alias  = textBoxAlias.Text;
                try { dev.group = ComboBoxGroupIp.SelectedItem.ToString(); }
                catch { dev.group = ""; }
                if (textBoxDeviceMac.Text == "  :  :  :  :  :")
                {
                    dev.mac = "";
                }
                //try { dev.mac = textBoxDeviceMac.Text; }
                //catch { dev.mac = ""; }
                dev.type = ComboBoxDeviceType.SelectedIndex;
                dev.sm   = "255.255.255.0";
                dev.gw   = gate;
                db.Devices.Add(dev);
                try
                {
                    db.SaveChanges();
                    DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.InnerException.Message);
                }
            }
            this.Close();
        }
예제 #12
0
 private void dataGridViewPublishInfo_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == dstaddrDataGridViewTextBoxColumn.Index)
     {
         string IndoorID = (string)e.Value;
         e.Value = DevicesAddressConverter.RoToChStr(IndoorID);
     }
     else if (e.ColumnIndex == typeDataGridViewTextBoxColumn.Index)
     {
         bool type = Convert.ToBoolean(e.Value);
         e.Value = (type) ? "Image" : "Text";
     }
     else if (e.ColumnIndex == isreadDataGridViewTextBoxColumn.Index)
     {
         bool Read = Convert.ToBoolean(e.Value);
         e.Value = (Read) ? strings.hasRead : strings.notRead;
     }
 }
예제 #13
0
 private void DataGridViewLeaveMsgs_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == srcaddrDataGridViewTextBoxColumn.Index)
     {
         string DoorID = (string)e.Value;
         e.Value = DevicesAddressConverter.RoToChStr(DoorID);
     }
     else if (e.ColumnIndex == dstaddrDataGridViewTextBoxColumn.Index)
     {
         string IndoorID = (string)e.Value;
         e.Value = DevicesAddressConverter.RoToChStr(IndoorID);
     }
     else if (e.ColumnIndex == readflagDataGridViewTextBoxColumn.Index)
     {
         bool Read = Convert.ToBoolean(e.Value);
         e.Value = (Read) ? strings.hasRead : strings.notRead;
     }
 }
예제 #14
0
 private void EventwarnDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == dgvTextBoxAlarmSrc.Index)
     {
         string DeviceId = e.Value as string;
         e.Value = DevicesAddressConverter.RoToChStr(DeviceId);
     }
     else if (e.ColumnIndex == dgvTextBoxAlarmHandleStatus.Index)
     {
         int status = e.Value != null ? (int)e.Value : 0;
         if (status < m_HandleStatus.Count())
         {
             e.Value = m_HandleStatus[status];
         }
     }
     else if (e.ColumnIndex == dgvTextBoxAlarmAction.Index)
     {
         if (e.Value is string action)
         {
             if (action == "trig")
             {
                 e.CellStyle.BackColor = Color.Red;
                 e.Value = "事件觸发";
             }
             else if (action == "unalarm")
             {
                 e.CellStyle.BackColor = Color.LimeGreen;
                 e.Value = "事件解除";
             }
             else if (action == "enable")
             {
                 e.Value = "佈防";
             }
             else if (action == "disable")
             {
                 e.Value = "撤防";
             }
             else
             {
                 e.Value = "";
             }
         }
     }
 }
예제 #15
0
 private void BtnRefreshDial_Click(object sender, EventArgs e)
 {
     listViewSessionLog.Items.Clear();
     foreach (var call in m_db.Eventcallouts.OrderBy(t => t.time))
     {
         List <string> sublist = new List <string>
         {
             DevicesAddressConverter.RoToChStr(call.from),
             DevicesAddressConverter.RoToChStr(call.to),
             call.time.ToString(),
             call.time.ToString(),
             call.action,
             call.type.ToString(),
             call.owner
         };
         listViewSessionLog.Items.Add(new ListViewItem(sublist.ToArray()));
         checkBoxAllSession.Checked = false;
     }
 }
예제 #16
0
        private void DialogHandleAlarm_Load(object sender, EventArgs e)
        {
            srcaddrTextBox.Text      = DevicesAddressConverter.RoToChStr(m_Alarm.srcaddr);
            channelTextBox.Text      = m_Alarm.channel.ToString();
            timeDateTimePicker.Value = m_Alarm.time;
            typeTextBox.Text         = m_Alarm.type;
            actionTextBox.Text       = ActionToString(m_Alarm.Action);
            handlerTextBox.Text      = m_Alarm.handler;
            int handleStatus = m_Alarm.handlestatus ?? 0;

            handlestatusListBox.SelectedIndex = handleStatus;
            if (m_Alarm.handletime != null)
            {
                handletimeDateTimePicker.Value = (DateTime)m_Alarm.handletime;
            }
            else
            {
                handletimeDateTimePicker.Value = DateTime.Now;
            }
        }
예제 #17
0
        private void InitAddNewCard()
        {
            string room = "";

            textBoxICCard.ReadOnly      = false;
            dateTimePickerStart.Enabled = dateTimePickerEnd.Enabled = false;
            //using (ICMDBContext db = new ICMDBContext())
            {
                var queryEntrance = from foo in db.Devices
                                    where foo.type < 5 && foo.type > 0
                                    select foo;
                foreach (var dev in queryEntrance)
                {
                    List <string> sublist = new List <string>();
                    room = DevicesAddressConverter.RoToChStr(dev.roomid);
                    sublist.Add(room);
                    sublist.Add(dev.id.ToString());
                    listViewUnRelate.Items.Add(new ListViewItem(sublist.ToArray()));
                }
            }
        }
예제 #18
0
 private void EventopendoordataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == dgvTextBoxOpenDoorOpenObject.Index)
     {
         string OpenId = (string)e.Value;
         if (OpenId[2] == '-')
         {
             e.Value = DevicesAddressConverter.RoToChStr(OpenId);
         }
     }
     else if (e.ColumnIndex == dgvTextBoxOpenDoorFrom.Index)
     {
         string FromId = (string)e.Value;
         e.Value = DevicesAddressConverter.RoToChStr(FromId);
     }
     else if (e.ColumnIndex == dgvTextBoxOpenDoorStatus.Index)
     {
         bool suc = Convert.ToBoolean(e.Value);
         e.Value = (suc) ? "成功" : "失敗";
     }
 }
예제 #19
0
 private void BtnQueryDial_Click(object sender, EventArgs e)
 {
     listViewSessionLog.Items.Clear();
     if (m_db != null)
     {
         var Query = from aa in m_db.Eventcallouts
                     where ((aa.time >= dateTimePickerCallStart.Value && aa.time <= dateTimePickerCallEnd.Value) || (aa.time >= dateTimePickerCallStart.Value && aa.time <= dateTimePickerCallEnd.Value))
                     orderby aa.time
                     select aa;
         foreach (var calllog in Query)
         {
             List <string> sublist = new List <string>
             {
                 DevicesAddressConverter.RoToChStr(calllog.from),
                 DevicesAddressConverter.RoToChStr(calllog.to),
                 calllog.time.ToString(),
                 calllog.time.ToString()
             };
             listViewSessionLog.Items.Add(new ListViewItem(sublist.ToArray()));
         }
     }
 }
 private void DeviceDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == dgvTxtBoxColDeviceId.Index)
     {
         string DeviceId = (string)e.Value;
         e.Value = DevicesAddressConverter.RoToChStr(DeviceId);
     }
     else if (e.ColumnIndex == dgvTxtBoxColDeviceType.Index)
     {
         int DeviceType = (int)e.Value;
         if (DeviceType < m_DeviceTypes.Count())
         {
             e.Value = m_DeviceTypes[DeviceType];
         }
     }
     else if (e.ColumnIndex == dgvTxtBoxColUpdateStatus.Index)
     {
         string status = e.Value as string;
         if (status == null || status == "")
         {
             e.Value = "ready";
         }
     }
 }
예제 #21
0
        //呼叫
        private void BtnCall_Click(object sender, EventArgs e)
        {
            Device Device;

            if (OnCall) // 通话中
            {
                return;
            }
            if (textBox.Text == "") // 未输入欲通话设备的地址
            {
                MessageBox.Show(strings.CantBeNull);
                return;
            }
            Address = DevicesAddressConverter.ChStrToRo(textBox.Text);
            Device  = ICMDBContext.GetDeviceByAddress(Address);
            if (Device == null)
            {
                MessageBox.Show(strings.RoNotExist);    // 房号不存在
                return;
            }

            StringBuilder ip      = new StringBuilder(Device.ip.ToString());
            StringBuilder address = new StringBuilder(Device.roomid.Replace("-", ""));

            try
            {
                NativeMethods.Dll_DataOut(1, ip, address);
                OnCall     = true;
                CurIpAddr  = ip.ToString();
                CurAddress = address.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #22
0
 private void IccardDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == dgvTextBoxCardType.Index)
     {
         if (e.Value != null)
         {
             int cardType = (int)e.Value;
             if (cardType < CardType.Count())
             {
                 e.Value = CardType[cardType];
             }
         }
     }
     else if (e.ColumnIndex == dgvTextBoxRoomId.Index)
     {
         string roomId = e.Value as string;
         e.Value = DevicesAddressConverter.RoToChStr(roomId);
     }
     else if (e.ColumnIndex == dgvTextBoxEnabled.Index)
     {
         int enabled = (e.Value == null) ? 0 : (int)e.Value;
         e.Value = (enabled != 0) ? strings.IsWorking : strings.NotWorking;
     }
 }
예제 #23
0
        //VAL状态改变时处理
        private void Method(object sender, ValueChangedEventArgs e)
        {
            ICMDBContext db = new ICMDBContext();

            switch (e.NewValue)
            {
            case (int)VideoTalkOperation.emMEET_REQUEST:
                OnCall = true;
                string showAddr = "";
                //将控件移到 Z 顺序的前面==显示控件。
                this.BringToFront();
                var Device = (from a in db.Devices
                              where a.ip == IP
                              select a).FirstOrDefault();
                if (Device != null)
                {
                    showAddr = DevicesAddressConverter.RoToChStr(Device.roomid);

                    if (1 <= Device.type && Device.type <= 4)
                    {
                        if (Config.Instance.IsMulticastEnabled && !string.IsNullOrEmpty(Device.group))
                        {
                            StringBuilder MultiIP = new StringBuilder();
                            MultiIP.Append(Device.group);
                            NativeMethods.Dll_ConfigMulticastIP(MultiIP);
                        }
                    }
                    if ((4 <= Device.type && Device.type <= 7) || Device.type == 2)
                    {
                        NativeMethods.Dll_OpenCamera();
                    }
                    // Timer start
                    CallingTimerStart();
                    // Timer start
                    PicBoxSwitch("bmp4.bmp", true);
                    labelCallingInfo.Text = "From:" + showAddr;
                }
                break;

            case (int)VideoTalkOperation.emMEET_ACCEPT:
                OnCall = true;
                var queryType = (from a in db.Devices
                                 where a.ip == IP
                                 select a).FirstOrDefault();
                if (queryType.type >= 2 && queryType.type <= 4)
                {
                    break;
                }
                NativeMethods.Dll_OpenCamera();
                PicBoxSwitch("bmp2.bmp", true);
                TimeOutInterval = -1;
                PickUp          = true;
                break;

            case (int)VideoTalkOperation.emMEET_STOP:
                if (OnCall)
                {
                    PicBoxSwitch("bmp5.bmp", true);
                    labelCallingInfo.Text = "";
                    NativeMethods.Dll_CloseCamera();
                    CurIpAddr  = "";
                    CurAddress = "";
                    //将控件移到Z顺序后面
                    //this.SendToBack();

                    System.Threading.Thread.Sleep(1000);
                    PicBoxSwitch("bmp1.bmp", true);
                    OnCall = false;
                }
                break;

            case (int)VideoTalkOperation.emWATCH_REQUEST:
                NativeMethods.Dll_OpenCamera();
                OnCall  = true;
                OnWatch = true;
                PicBoxSwitch("bmp2.bmp", true);
                labelCallingInfo.Text = "From:" + ADDR;
                break;

            case (int)VideoTalkOperation.emWATCH_STOP:
                NativeMethods.Dll_CloseCamera();
                break;

            case (int)VideoTalkOperation.emLW_REQUEST:
                string    sIndoorAddress = lParam;
                leaveword lw             = new leaveword
                {
                    filenames = wParam,
                    readflag  = 0
                };
                try
                {
                    var query = from a in db.Devices
                                where a.ip == IP
                                select a;
                    foreach (var dev in query)
                    {
                        lw.src_addr = dev.roomid;
                    }
                }
                catch
                {
                    lw.src_addr = "Unknow";
                }
                lw.dst_addr = sIndoorAddress;

                lw.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");    //tm.ToString();
                db.Leavewords.Add(lw);
                db.SaveChanges();
                break;

            case (int)VideoTalkOperation.emLW_DOWNLOAD_REQUEST:
                // Query Video msgs file path from database
                int id = int.Parse(lParam);
                try
                {
                    var query = from a in db.Leavewords
                                where a.id == id
                                select a;
                    foreach (var msgs in query)
                    {
                        filepath      = msgs.filenames;
                        msgs.readflag = 1;
                    }
                    db.SaveChanges();
                }
                catch
                {
                    filepath = "";
                }
                break;

            // Query Video msgs file path from database
            case (int)VideoTalkOperation.emPHONERECORDS_FROM:
                if (OnCall)
                {
                    break;
                }
                CurIpAddr  = IP;
                CurAddress = ADDR;
                break;

            case (int)VideoTalkOperation.emPHONERECORDS_TO:
                PicBoxSwitch("bmp3.bmp", true);
                // Timer start
                CallingTimerStart();
                // Timer start
                break;

            default:
                break;
            }
        }
예제 #24
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (m_Card != null)// Moding mode
            {
                if ((textBoxRo.Text != "") && (textBoxResidentName.Text != ""))
                {
                    //using (ICMDBContext db = new ICMDBContext())
                    {
                        int lastMap = 0;
                        try
                        {
                            lastMap = db.Icmaps.OrderByDescending(p => p.C_id).Select(r => r.C_id).First();
                        }
                        catch { }
                        var card = (from c in db.Iccards
                                    where c.C_icno == m_Card.C_icno
                                    select c).FirstOrDefault();
                        if (card != null)
                        {
                            db.Iccards.Remove(card);
                            db.SaveChanges();
                            card.C_icno      = textBoxICCard.Text;
                            card.C_roomid    = textBoxRo.Text;
                            card.C_available = ComboBoxOnUse.SelectedIndex;
                            card.C_ictype    = ComboBoxIsResident.SelectedIndex;
                            card.C_username  = textBoxResidentName.Text;
                            if (checkBoxStartDate.Checked)
                            {
                                card.C_uptime = dateTimePickerStart.Value;
                            }
                            else
                            {
                                card.C_uptime = null;
                            }
                            if (checkBoxEndDate.Checked)
                            {
                                card.C_downtime = dateTimePickerEnd.Value;
                            }
                            else
                            {
                                card.C_downtime = null;
                            }
                            card.C_icid = id;

                            db.Iccards.Add(card);
                            db.SaveChanges();
                        }
                        // delete map
                        var map = from foo in db.Icmaps
                                  where foo.C_icno == card.C_icno
                                  select foo;
                        db.Icmaps.RemoveRange(map);
                        db.SaveChanges();
                        // del end

                        foreach (ListViewItem tmp in listViewRelate.Items)
                        {
                            string ro = tmp.SubItems[0].Text;

                            icmap MapSave = new icmap
                            {
                                C_icno         = textBoxICCard.Text,
                                C_entrancedoor = DevicesAddressConverter.ChStrToRo(ro),
                                C_id           = lastMap + 1
                            };
                            db.Icmaps.Add(MapSave);
                        }
                        db.SaveChanges();

                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show(strings.CardRoNameCannotBeNull);//"卡号、房号、姓名不得为空!");
                }
            }
            else// Adding mode
            {
                if (Check())
                {
                    //using (ICMDBContext db = new ICMDBContext())
                    {
                        int last    = 0;
                        int lastMap = 0;
                        try
                        {
                            last = db.Iccards.OrderByDescending(p => p.C_icid).Select(r => r.C_icid).First();
                        }
                        catch { }
                        try
                        {
                            lastMap = db.Icmaps.OrderByDescending(p => p.C_id).Select(r => r.C_id).First();
                        }
                        catch {}
                        Iccard CardSave = new Iccard
                        {
                            C_icno      = textBoxICCard.Text,
                            C_roomid    = textBoxRo.Text,
                            C_available = ComboBoxOnUse.SelectedIndex,
                            C_ictype    = ComboBoxIsResident.SelectedIndex,
                            C_username  = textBoxResidentName.Text,
                            C_uptime    = dateTimePickerStart.Value,
                            C_downtime  = dateTimePickerEnd.Value,
                            C_icid      = last + 1
                        };
                        foreach (ListViewItem tmp in listViewRelate.Items)
                        {
                            string ro = tmp.SubItems[0].Text;

                            icmap MapSave = new icmap
                            {
                                C_icno         = textBoxICCard.Text,
                                C_entrancedoor = DevicesAddressConverter.ChStrToRo(ro),
                                C_id           = lastMap + 1
                            };
                            db.Icmaps.Add(MapSave);
                        }
                        db.Iccards.Add(CardSave);
                        db.SaveChanges();
                        this.Close();
                    }
                }
            }
        }
예제 #25
0
        private void IcmapDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            string DeviceId = e.Value as string;

            e.Value = DevicesAddressConverter.RoToChStr(DeviceId);
        }
예제 #26
0
        private void AddCard_Load(object sender, EventArgs e)
        {
            ComboBoxOnUse.SelectedIndex      = 1;                    //默认有效
            ComboBoxIsResident.SelectedIndex = 0;
            listViewUnRelate.Columns.Add(strings.UnrelatedDev, 189); //"未开聯设备", 189);
            listViewRelate.Columns.Add(strings.RelatedDev, 206);     //"开聯设备", 206);

            // Moding mode
            if (m_Card != null)
            {
                //using (ICMDBContext db = new ICMDBContext())
                {
                    List <string> IdPool = new List <string>();

                    var card = (from c in db.Iccards
                                where c.C_icno == m_Card.C_icno
                                select c).FirstOrDefault();

                    m_Card = card;

                    id = card.C_icid;
                    textBoxICCard.Text               = card.C_icno;
                    textBoxRo.Text                   = card.C_roomid;
                    textBoxResidentName.Text         = card.C_username;
                    ComboBoxIsResident.SelectedIndex = (int)(card.C_ictype ?? 0);
                    ComboBoxOnUse.SelectedIndex      = (int)(card.C_available ?? 0);
                    checkBoxStartDate.Checked        = (card.C_uptime != null);
                    checkBoxEndDate.Checked          = (card.C_downtime != null);
                    dateTimePickerStart.Value        = (card.C_uptime != null) ? card.C_uptime.Value : DateTime.Now;
                    dateTimePickerEnd.Value          = (card.C_downtime != null) ? card.C_downtime.Value : DateTime.Now;

                    var relatedDevices = (from icno in db.Icmaps
                                          where icno.C_icno == m_Card.C_icno
                                          select icno).ToArray();
                    foreach (var dev in relatedDevices)
                    {
                        List <string> sublist = new List <string>();
                        string        room    = DevicesAddressConverter.RoToChStr(dev.C_entrancedoor);
                        sublist.Add(room);
                        sublist.Add(dev.C_id.ToString());
                        // 开聯设备
                        listViewRelate.Items.Add(new ListViewItem(sublist.ToArray()));

                        IdPool.Add(dev.C_entrancedoor);
                    }

                    var queryEntrance = from foo in db.Devices
                                        where foo.type <(int)DeviceType.Indoor_Phone && foo.type> (int) DeviceType.Control_Server
                                        select foo;
                    foreach (var dev in queryEntrance)
                    {
                        bool equal = false;
                        foreach (var a in IdPool)
                        {
                            if (a == dev.roomid)
                            {
                                equal = true;
                                break;
                            }
                        }
                        if (equal)
                        {
                            continue;
                        }
                        List <string> sublist = new List <string>();
                        string        room    = DevicesAddressConverter.RoToChStr(dev.roomid);
                        sublist.Add(room);
                        sublist.Add(dev.id.ToString());
                        listViewUnRelate.Items.Add(new ListViewItem(sublist.ToArray()));
                    }
                }
                // Moding mode
            }
            else
            {
                InitAddNewCard();
            }
        }