예제 #1
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            ToggleButton b  = sender as ToggleButton;
            int          id = Convert.ToInt32(b.CommandParameter);

            for (int i = WhiteListView.Items.Count - 1; i >= 0; i--)
            {
                if (whiteList[i].ID == id)
                {
                    if (!whiteList[i].ReadOnly)
                    {
                        ListViewItem lvi = this.WhiteListView.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem;
                        TextBox      tb  = FindVisualChild <TextBox>(lvi);
                        tb.Focus();
                        tb.SelectionStart = tb.Text.Length;
                    }
                    else
                    {
                        if (String.IsNullOrWhiteSpace(whiteList[i].Number))
                        {
                            MessageBoxX.Show("提示", "船舷号不能为空!");
                            whiteList[i].ReadOnly = !whiteList[i].ReadOnly;
                        }
                        else
                        {
                            try
                            {
                                WhiteShip ship = new WhiteShip();
                                ship.CallID = whiteList[i].CallSign;
                                if (!String.IsNullOrWhiteSpace(whiteList[i].IMO))
                                {
                                    ship.IMO = uint.Parse(whiteList[i].IMO);
                                }
                                ship.MMSI           = int.Parse(whiteList[i].MMSI);
                                ship.ShipDepartment = whiteList[i].Department;
                                ship.ShipName       = whiteList[i].Name;
                                ship.ShipUsage      = whiteList[i].Usage;
                                ship.ShipNumber     = whiteList[i].Number;
                                white.UpdateWhiteShip(ship);
                                dataAna.WhiteListSync();
                            }
                            catch (Exception ex)
                            {
                                MessageBoxX.Show("警告", "存在非法的数据!");
                                whiteList[i].ReadOnly = !whiteList[i].ReadOnly;
                            }
                        }
                    }
                }
            }
        }
        private void comfirmClick(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(mmsi.Text) || String.IsNullOrWhiteSpace(number.Text))
            {
                MessageBoxX.Show("提示", "MMSI、船舷号不能为空!");
            }
            else
            {
                WhiteListSetting.whiteList.Clear();

                List <WhiteShip> whiteListStr = new List <WhiteShip>();
                whiteListStr = white.GetAllWhiteShip();//初始化白名单列表

                for (int i = 0; i < whiteListStr.Count(); i++)
                {
                    WhiteTarget wt = new WhiteTarget
                    {
                        ID         = i,
                        MMSI       = whiteListStr[i].MMSI.ToString(),
                        Number     = whiteListStr[i].ShipNumber,
                        IMO        = whiteListStr[i].IMO.ToString(),
                        CallSign   = whiteListStr[i].CallID,
                        Name       = whiteListStr[i].ShipName,
                        Department = whiteListStr[i].ShipDepartment,
                        Usage      = whiteListStr[i].ShipUsage,
                        ReadOnly   = true,
                    };
                    WhiteListSetting.whiteList.Add(wt);
                }

                int count;
                for (count = 0; count < WhiteListSetting.whiteList.Count; count++)
                {
                    if (WhiteListSetting.whiteList[count].MMSI == mmsi.Text)
                    {
                        MessageBoxX.Show("提示", "已存在具有相同MMSI的船只!");
                        break;
                    }
                }

                if (count == WhiteListSetting.whiteList.Count)
                {
                    try
                    {
                        WhiteShip ship = new WhiteShip();
                        ship.CallID = callSign.Text;
                        if (!String.IsNullOrWhiteSpace(imo.Text))
                        {
                            ship.IMO = uint.Parse(imo.Text);
                        }
                        ship.MMSI           = int.Parse(mmsi.Text);;
                        ship.ShipDepartment = department.Text;
                        ship.ShipName       = name.Text;
                        ship.ShipUsage      = usage.Text;
                        ship.ShipNumber     = number.Text;
                        white.AddWhiteShip(ship);                 //添加白名单入库

                        dataAna.WhiteListSync();                  //白名单同步

                        MainWindow.opeation.OptionName = "添加白名单"; //日志入库
                        MainWindow.opeation.LogType    = 2;
                        MainWindow.opeation.OptionTime = WhiteListSetting.GetTime(WhiteListSetting.GetTimeStampS().ToString());
                        MainWindow.OperationLogData.WriteOperationLog(MainWindow.opeation);

                        whiteListStr = white.GetAllWhiteShip();
                        WhiteTarget wt = new WhiteTarget
                        {
                            ID         = WhiteListSetting.whiteList.Count,
                            MMSI       = whiteListStr[whiteListStr.Count - 1].MMSI.ToString(),
                            Number     = whiteListStr[whiteListStr.Count - 1].ShipNumber,
                            IMO        = whiteListStr[whiteListStr.Count - 1].IMO.ToString(),
                            CallSign   = whiteListStr[whiteListStr.Count - 1].CallID,
                            Name       = whiteListStr[whiteListStr.Count - 1].ShipName,
                            Department = whiteListStr[whiteListStr.Count - 1].ShipDepartment,
                            Usage      = whiteListStr[whiteListStr.Count - 1].ShipUsage,
                            ReadOnly   = true,
                        };
                        WhiteListSetting.whiteList.Add(wt);
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBoxX.Show("警告", "MMSI、IMO应为整数!");
                    }
                }
            }
        }