Exemple #1
0
 public static void Run(ComputerModel model, bool editing)
 {
     Instance.model = model;
     Instance.setDetails();
     Instance.setButtons(editing);
     Instance.ShowDialog();
 }
 internal async static Task <string> PutComputerModelAsync(ComputerModel computerModel)
 {
     return(await insertOrUpdateAsync <ComputerModel>(computerModel, constructServiceURI("PutComputerModel", new Dictionary <string, object>()
     {
         { "computerModel", computerModel }
     }), "PUT"));
 }
 private void editComputerModel(ComputerModel model)
 {
     if (model != null)
     {
         model.editDetails();
         setDetails(manufacturer.code);
     }
 }
        private void setComputerDetails()
        {
            ComputerModel model = (ComputerModel)lbModels.SelectedItem;
            bool          b     = (model != null);

            gbComputerDetails.Text = b ? model.name : "";
            lblComputerType.Text   = $"Type: {(b ? model.type : "")}";
            lblComputerSystem.Text = $" System: {(b ? model.operatingSystem: "")}";
        }
        protected virtual async Task setDetails()
        {
            newModel = String.IsNullOrEmpty(model.name);
            Console.WriteLine("Model name: " + model.name + newModel.ToString());
            tbName.Enabled = newModel;
            try
            {
                // Ensure information presented is the most recent version
                bool loadedModelIsCurrent = model.modifiedDate == (await ServiceClient.GetModifiedDateAsync(model.name));
                if (!loadedModelIsCurrent)
                {
                    Console.WriteLine("Refreshing model.");
                    ComputerModel retrievedModel = await ServiceClient.GetComputerModelAsync(model.name);

                    if (retrievedModel != null)
                    {
                        model = retrievedModel;
                    }
                }

                // Load preexisting field data from database
                prexistingFieldData = await ServiceClient.GetModelDetailPrexistingFieldDataAsync();

                this.Text = $"{(newModel ? "New " : "")}{model.manufacturer} {model.type}";

                tbName.Text                  = model.name;
                nudPrice.Value               = model.price;
                nudQuantity.Value            = model.quantity;
                cbOperatingSystem.DataSource = prexistingFieldData.OperatingSystems;
                cbOperatingSystem.Text       = model.operatingSystem;
                nudMemory.Value              = model.memory;
                cbProcessorFamily.DataSource = prexistingFieldData.ProcessorFamilies;
                cbProcessorFamily.Text       = model.processorFamily;
                nudStorage.Value             = model.storage;
                cbGraphicsFamily.DataSource  = prexistingFieldData.GraphicsFamilies;
                cbGraphicsFamily.Text        = model.graphicsFamily;
                lblModification.Text         = $"Modified: {model.modifiedDate.ToLocalTime().ToLongDateString()} {model.modifiedDate.ToLocalTime().ToLongTimeString()}";
            }
            catch (HttpRequestException ex)
            {
                showConnectionError();
                DialogResult = DialogResult.Abort;
            }
        }
        private async void btnRemoveComputer_Click(object sender, EventArgs e)
        {
            btnRemoveComputer.Enabled = false;
            ComputerModel model = (ComputerModel)lbModels.SelectedItem;

            if (model != null)
            {
                // get confirmation from user
                if (MessageBox.Show($"Do you really want to delete model: {model.name}?", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    try
                    {
                        // Notify server of deletion.
                        string result = await ServiceClient.DeleteComputerModelAsync(model.name);

                        switch (result.ToString())
                        {
                        case "SUCCESS":
                            MessageBox.Show($"The model: {model.name} was removed.");
                            break;

                        case "COUNT ERROR":
                            MessageBox.Show("Many rows were removed.");
                            break;

                        default:
                            MessageBox.Show("An unexpected behaviour was encountered.");
                            break;
                        }
                    }
                    catch (HttpRequestException) { }
                    setDetails(manufacturer.code);
                }
            }
            btnRemoveComputer.Enabled = true;
        }