示例#1
0
        private async void BtnDeleteFile_Click(object sender, EventArgs e)
        {
            //using (var db = new ICMDBContext())
            {
                foreach (DataGridViewRow row in upgradeDataGridView.SelectedRows)
                {
                    upgrade upgradeInfo = (upgrade)row.DataBoundItem;

                    // delete file and directory
                    string filepath = Config.Instance.FTPServerRootDir
                                      + @"\" + upgradeInfo.filepath;
                    try
                    {
                        System.IO.File.Delete(filepath);
                        string dirpath = System.IO.Path.GetDirectoryName(filepath);
                        System.IO.Directory.Delete(dirpath);
                    }
                    catch (Exception) { }
                    db.Upgrades.Remove(upgradeInfo);
                }
                await db.SaveChangesAsync();

                RefreshUgradeFileList();
            }
        }
示例#2
0
        private async void BtnResetToDefault_Click(object sender, EventArgs e)
        {
            if (upgradeDataGridView.SelectedRows.Count == 0)
            {
                MessageBox.Show("请选择一個項目");
                return;
            }
            if (upgradeDataGridView.SelectedRows.Count > 1)
            {
                MessageBox.Show("一次只能选一項");
                return;
            }

            upgrade selectedUpgradeInfo = (upgrade)upgradeDataGridView.SelectedRows[0].DataBoundItem;
            var     upgradeInfos        = from file in db.Upgrades
                                          where file.filetype == selectedUpgradeInfo.filetype &&
                                          file.Device_type == selectedUpgradeInfo.Device_type
                                          select file;

            foreach (upgrade upgradeInfo in upgradeInfos)
            {
                upgradeInfo.is_default = 0;
            }
            selectedUpgradeInfo.is_default = 1;
            await db.SaveChangesAsync();

            RefreshUgradeFileList();
        }
示例#3
0
    void initialize()
    {
        StreamReader stream = new StreamReader(Directory.GetCurrentDirectory() + @"\Assets\Upgrades\Station\Station.txt");

        Debug.Log(Directory.GetCurrentDirectory());
        int amt = Int32.Parse(stream.ReadLine());
        int i   = 0;

        while (i++ < amt)
        {
            upgrades.Add(stream.ReadLine());
            description.Add(stream.ReadLine());
            costH.Add(Int32.Parse(stream.ReadLine()));
            image.Add(stream.ReadLine());
        }
        i = 0;
        stationUpgrades = new upgrade[amt];
        for (int a = 0; a < amt; a++)
        {
            stationUpgrades[a]             = new upgrade();
            stationUpgrades[a].cost        = costH[a];
            stationUpgrades[a].description = description[a];
            stationUpgrades[a].Img         = image[a];
            stationUpgrades[a].upgradeName = upgrades[a];
        }
    }
示例#4
0
 public void displayDialogue(upgrade id)
 {
     if (id == upgrade.SmartHomeUpgrade)
     {
         SmartHomeDialogue.SetActive(true);
     }
     else if (id == upgrade.SmartWatchUpgrade)
     {
         SmartWatchDialogue.SetActive(true);
     }
     else if (id == upgrade.EnergyConsumptionTrackerUpgrade)
     {
         EnergyConsumptionTrackerDialogue.SetActive(true);
     }
     else if (id == upgrade.SolarPowerUpgrade)
     {
         SolarPowerDialogue.SetActive(true);
     }
     else if (id == upgrade.SmartWasteRecycleUpgrade)
     {
         SmartWasteDialogue.SetActive(true);
     }
     else if (id == upgrade.CameraUpgrade)
     {
         CameraDialogue.SetActive(true);
     }
     else if (id == upgrade.SmartStreetLightsUpgrade)
     {
         StreetLightDialogue.SetActive(true);
     }
     else if (id == upgrade.SmartCrimeDetectionUpgrade)
     {
         CrimeDetectDialogue.SetActive(true);
     }
     else if (id == upgrade.WindEnergyUpgrade)
     {
         WindEnergyDialogue.SetActive(true);
     }
     else if (id == upgrade.ParkingIndicatorUpgrade)
     {
         ParkingDialogue.SetActive(true);
     }
     else if (id == upgrade.SmartTrafficLightsUpgrade)
     {
         TrafficLightDialogue.SetActive(true);
     }
     else if (id == upgrade.NuclearEnergyUpgrade)
     {
         NuclearDialogue.SetActive(true);
     }
     else if (id == upgrade.SelfDrivingCarsUpgrade)
     {
         SelfDrivingDialogue.SetActive(true);
     }
     else
     {
         FlyingCarDialogue.SetActive(true);
     }
 }
        public DialogSelectDevicesToBeUpgradedViewModel(
            ICollectionModel <Device> deviceDataModel,
            IUpgradeTasksModel upgradeTaskDataModel,
            IDialogService dialogService,
            upgrade upgradeFile)
        {
            this._deviceDataModel      = deviceDataModel;
            this._upgradeTaskDataModel = upgradeTaskDataModel;
            this._dialogService        = dialogService;
            this._upgradeFile          = upgradeFile;
            if (upgradeFile.filetype.HasValue)
            {
                if (upgradeFile.filetype == (int)UpgradeFileType.SoftwareUpgrade)
                {
                    _deviceType = (DeviceType?)upgradeFile.device_type;
                }
            }

            Devices = (ListCollectionView) new ListCollectionView((IList)_deviceDataModel.Data);
            using (Devices.DeferRefresh())
            {
                Devices.Filter = delegate(object obj)
                {
                    Device device = obj as Device;
                    if (device != null && device.type.HasValue)
                    {
                        if (_deviceType.HasValue)
                        {
                            if (device.type == (int)_deviceType)
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            switch (device.type)
                            {
                            // case (int)DeviceType.Control_Server:
                            case (int)DeviceType.Door_Camera:
                            case (int)DeviceType.Lobby_Phone_Unit:
                            case (int)DeviceType.Lobby_Phone_Building:
                            case (int)DeviceType.Lobby_Phone_Area:
                            case (int)DeviceType.Indoor_Phone:
                            case (int)DeviceType.Administrator_Unit:
                            case (int)DeviceType.Indoor_Phone_SD:
                            // case (int)DeviceType.Mobile_Phone:
                            case (int)DeviceType.Emergency_Intercom_Unit:
                                // case (int)DeviceType.IPCAM:
                                return(true);
                            }
                        }
                    }
                    return(false);
                };
                Devices.SortDescriptions.Add(new SortDescription("ip", ListSortDirection.Ascending));
            }
        }
 public DialogSelectDevicesToBeUpgraded(upgrade upgradeFile)
 {
     InitializeComponent();
     this._viewModel = new DialogSelectDevicesToBeUpgradedViewModel(
         ServiceLocator.Current.GetInstance <ICollectionModel <Device> >(),
         ServiceLocator.Current.GetInstance <IUpgradeTasksModel>(),
         ServiceLocator.Current.GetInstance <IDialogService>(),
         upgradeFile);
     //this._viewModel.OkClicked += _viewModel_OkClicked;
     this.DataContext = this._viewModel;
 }
示例#7
0
        public void upgradeShip()
        {
            //assume each upgrade costs 2500 and will add 5 more capacity unit
            upgrade sys       = new upgrade();//defult top level is 4
            int     money     = 3000;
            int     level     = 1;
            int     compacity = 5;

            sys.upgradeship(money, level, compacity);
            Assert.AreNotEqual(3000, sys.upgradeship(money, level, compacity));//test if the balances are the same after the test
            Assert.AreEqual(3000, money);
        }
示例#8
0
    public bool purchase(upgrade id)
    {
        if (isPurchaseable(id))
        {
            upgrades[(int)id].setisActive(true);
            money -= upgrades[(int)id].cost;
            updateAvailabilities(id);
            displayDialogue(id);

            return(true);
        }

        return(false);
    }
 void Start()
 {
     farm = 0;
     damage = 0.3f;
     for (int i = 0; i < bonus.Length; i++)
     {
         bonus[i] = new upgrade();
         bonus[i].level = 1;
     }
     bonus[0].price = 100;
     bonus[0].ratio = 7;
     bonus[1].price = 50;
     bonus[1].ratio = 6;
     bonus[2].price = 50;
     bonus[2].ratio = 5;
     bonus[3].price = 70;
     bonus[3].ratio = 3;
     money = 0;
     StartCoroutine(Money());
 }
        private void BtnConfirm_Click(object sender, EventArgs e)
        {
            if (this.textBoxPath.Text.Length == 0)
            {
                MessageBox.Show("请添加升级文件", "提示", MessageBoxButtons.OK);
                return;
            }

            // TODO:
            // 先读取目前时间
            string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
            string typename  = "";

            switch (this.ComboBoxUpgradeType.SelectedIndex)
            {
            case 0: // software upgrade
                switch (this.ComboBoxDevType.SelectedIndex)
                {
                case 0: // "别墅门口机"
                case 1: // "单元门口机"
                case 2: // "楼栋门口机"
                case 3: // "小区门口机"
                case 4: // "室内机"
                case 5: // "室内机(SD)"
                case 6: // "管理机"
                case 7: // "公共门鈴机"
                    typename = m_DeviceFileType[this.ComboBoxDevType.SelectedIndex];
                    break;
                }
                break;

            case 1: // addressbook
            case 2: // screen saver
            case 3: // card list
                typename = m_ResourceFileType[this.ComboBoxUpgradeType.SelectedIndex];
                break;
            }
            // 根據 file type | Device type 決定 file name

            string filename = string.Format(@"{0}\data\firmware\{1}_{2}_{3}\{4}",
                                            Config.Instance.FTPServerRootDir, timeStamp, this.textBoxVersion.Text, typename,
                                            this.textBoxFileName.Text);

            if (!Directory.Exists(System.IO.Path.GetDirectoryName(filename)))
            {
                Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filename));
            }
            File.Copy(this.textBoxPath.Text, filename);

            using (var db = new ICMDBContext())
            {
                int DeviceType;
                if (this.ComboBoxUpgradeType.SelectedIndex != 0)
                {
                    DeviceType = -1;
                }
                else
                {
                    DeviceType = m_DeviceType[this.ComboBoxDevType.SelectedIndex];
                }
                int fileType = this.ComboBoxUpgradeType.SelectedIndex + 1;
                var file     = (from f in db.Upgrades
                                where f.filetype == fileType &&
                                f.Device_type == DeviceType
                                select f).FirstOrDefault();
                upgrade upgradeInfo = new upgrade();
                upgradeInfo.Device_type = DeviceType;
                upgradeInfo.filetype    = fileType;
                upgradeInfo.filepath    = filename.Substring(Config.Instance.FTPServerRootDir.Length + 1, filename.Length - Config.Instance.FTPServerRootDir.Length - 1);
                upgradeInfo.is_default  = (file == null) ? 1 : 0;
                upgradeInfo.version     = this.textBoxVersion.Text;
                upgradeInfo.time        = DateTime.Now;
                db.Upgrades.Add(upgradeInfo);
                db.SaveChanges();
                this.DialogResult = DialogResult.OK;
            }
        }
示例#11
0
    public void updateAvailabilities(upgrade id)
    {
        if (id == upgrade.SmartHomeUpgrade)
        {
            upgrades[(int)upgrade.SmartWatchUpgrade].setAvailable(true);
            upgrades[(int)upgrade.EnergyConsumptionTrackerUpgrade].setAvailable(true);
            upgrades[(int)upgrade.CameraUpgrade].setAvailable(true);
        }

        if (id == upgrade.EnergyConsumptionTrackerUpgrade)
        {
            upgrades[(int)upgrade.SolarPowerUpgrade].setAvailable(true);
            upgrades[(int)upgrade.SmartWasteRecycleUpgrade].setAvailable(true);
        }

        if (id == upgrade.SolarPowerUpgrade)
        {
            upgrades[(int)upgrade.SmartStreetLightsUpgrade].setAvailable(true);
            upgrades[(int)upgrade.WindEnergyUpgrade].setAvailable(true);
        }

        if (id == upgrade.SmartStreetLightsUpgrade)
        {
            if (upgrades[(int)upgrade.CameraUpgrade].isActivated())
            {
                upgrades[(int)upgrade.SmartCrimeDetectionUpgrade].setAvailable(true);
            }
        }

        if (id == upgrade.CameraUpgrade)
        {
            if (upgrades[(int)upgrade.SmartStreetLightsUpgrade].isActivated())
            {
                upgrades[(int)upgrade.SmartCrimeDetectionUpgrade].setAvailable(true);
            }
        }

        if (id == upgrade.SmartStreetLightsUpgrade)
        {
            upgrades[(int)upgrade.ParkingIndicatorUpgrade].setAvailable(true);
            upgrades[(int)upgrade.SmartTrafficLightsUpgrade].setAvailable(true);
        }

        if (id == upgrade.WindEnergyUpgrade)
        {
            upgrades[(int)upgrade.NuclearEnergyUpgrade].setAvailable(true);
        }

        if (id == upgrade.ParkingIndicatorUpgrade)
        {
            if (upgrades[(int)upgrade.SmartTrafficLightsUpgrade].isActivated())
            {
                upgrades[(int)upgrade.SelfDrivingCarsUpgrade].setAvailable(true);
            }
        }

        if (id == upgrade.SmartTrafficLightsUpgrade)
        {
            if (upgrades[(int)upgrade.ParkingIndicatorUpgrade].isActivated())
            {
                upgrades[(int)upgrade.SelfDrivingCarsUpgrade].setAvailable(true);
            }
        }

        if (id == upgrade.SelfDrivingCarsUpgrade)
        {
            upgrades[(int)upgrade.FlyingCarsUpgrade].setAvailable(true);
        }
    }
示例#12
0
 public bool isPurchaseable(upgrade id)
 {
     return(upgrades[(int)id].isAvailable() && money >= upgrades[(int)id].cost && !upgrades[(int)id].isActivated());
 }
示例#13
0
        [TestMethod]//build the function
        public void upgradeConstruct()
        {
            upgrade sys = new upgrade();

            Assert.IsNotNull(sys);
        }
示例#14
0
 public void ShowSelectDevicesToBeUpgraded(upgrade upgradeFile)
 {
     new DialogSelectDevicesToBeUpgraded(upgradeFile).ShowDialog();
 }