コード例 #1
0
 /// <summary>
 /// Add a new variable to the server
 /// </summary>
 /// <param name="req"></param>
 /// <returns></returns>
 public static ServiceOutput AddVariable(AddVariableRequest req)
 {
     using (WebClient client = new WebClient())
     {
         client.Headers.Add("Content-Type", "application/json; charset=utf-8");
         String uri = Properties.Settings.Default.adaptiveUri + "/WebServices/geostat/Portal.asmx/AddVariable";
         byte[] responsebytes = client.UploadData(uri, "POST", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(req)));
         var json = Encoding.UTF8.GetString(responsebytes);
         //DebugToFile.Log(json);
         return JsonConvert.DeserializeObject<ServiceOutput>(json);
     }
 }
コード例 #2
0
        /// <summary>
        /// Create a new tree node
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateNew_Click(object sender, EventArgs e)
        {
            if (!isValid())
            {
                this.Log("Ugyldige verdiar, kontroller skjema");
                return;
            }

            var req = new AddVariableRequest();

            int level;
            int.TryParse(tbVarLevel.Text, out level);

            if (level == 5)
            {
                req.data.var5 = cbVarName.Text.emptyIfNull();
                req.data.var4 = selectedParentTreeNode.Text.emptyIfNull();
                req.data.var3 = selectedParentTreeNode.Parent.Text.emptyIfNull();
                req.data.var2 = selectedParentTreeNode.Parent.Parent.Text.emptyIfNull();
                req.data.var1 = selectedParentTreeNode.Parent.Parent.Parent.Text.emptyIfNull();
            }
            else if (level == 4)
            {
                req.data.var4 = cbVarName.Text.emptyIfNull();
                req.data.var3 = selectedParentTreeNode.Text.emptyIfNull();
                req.data.var2 = selectedParentTreeNode.Parent.Text.emptyIfNull();
                req.data.var1 = selectedParentTreeNode.Parent.Parent.Text.emptyIfNull();
            }
            else if (level == 3)
            {
                req.data.var3 = cbVarName.Text.emptyIfNull();
                req.data.var2 = selectedParentTreeNode.Text.emptyIfNull();
                req.data.var1 = selectedParentTreeNode.Parent.Text.emptyIfNull();
            }
            else if (level == 2)
            {
                req.data.var2 = cbVarName.Text.emptyIfNull();
                req.data.var1 = selectedParentTreeNode.Text.emptyIfNull();
            }
            else if (level == 1)
            {
                req.data.var1 = cbVarName.Text.emptyIfNull();
            }

            req.data.description = tbDescription.Text;
            req.data.name = cbVarName.Text.nullIfEmpty();
            req.data.unit = (string)cbUnit.SelectedValue;
            req.data.showunit = chkbShowUnit.Checked;
            req.data.time_unit = (string)cbTimeUnit.SelectedValue;
            req.data.fk_kretstyper = (string)cbKretstyper.SelectedValue;
            req.data.parent_id = selectedParentVariable == null ? null : (int?)selectedParentVariable.id;

            try
            {
                var res = PortalClient.AddVariable(req);
                if (!res.d.success)
                {
                    this.Log("Kunne ikkje legge til variabel: " +  req.data.getNameAtLevel(level));
                }
                else
                {
                    this.Log("La til ny variabel: " + req.data.getNameAtLevel(level));
                    var scrollOffset = svTree.AutoScrollOffset;
                    ReloadTree(selectedParentTreeNode.id);
                }
            }
            catch (Exception ex)
            {
                this.Log(ex.Message);
            }
        }