mercredi 1 avril 2020

Toggle Functionality WPF Sliding Panel

I am developing a WPF application and have developed a sliding navigation panel. I currently have it set up to two different buttons; one to open the navbar and one to close. However I am trying to implement a toggle so that when a single button is clicked the navbar opens and then when it is clicked again the navbar closes.

I have this all developed asides from the toggle functionality, in that I have a button, the functionality to trigger the opening and closing but not the toggling. So far I have the following code. As commented the first part opens the navbar and the second closes it.

WPF XAML

<Button x:Name="ToggleNavBtn" Click="ToggleNavBtn_Click" ToolTip="Toggle navigation" Height="50" Width="20" Content="|||" Background="#C20114" Foreground="#fff" ></Button>

C# Code

//Either 1 (Open) or 0 (Closed)
            int state = 0;

            if (state == 0)
            {
                //Open navigation
                Storyboard sbOpen = Resources["OpenNavMenu"] as Storyboard;
                sbOpen.Begin(NavMenu);

                state = 1;
            }
            else if (state == 1)
            {
                // Closes navigation
                Storyboard sb = Resources["CloseNavMenu"] as Storyboard;
                sb.Begin(NavMenu);

                state = 0;
            }

I had planned to use a variable and change this after each part of the code is executed but obviously the variable state is local in the if statement so while this represents the functionality I desire, results in the navbar only ever opening.

My question is how would I ensure, as the navbar starts off closed, that when the button is pressed the navbar opens and then one its is pressed again is closes, repeating continuously no matter the amount I press the button.

Hopefully this make sense, thanks in advance.

local variable initialization problem in if-else (Java)

This is my code.

public class Test {
    public void main (String[] args) {

        int a;
        String b = "11343468/32145";

        String c[] = b.split("");

        for(int i=0; i<c.length; i++) {
            if(c[i].equals("/")) {
                a = i;
            } else {a = 0;}
        }
        System.out.println(a);
    }

I'm trying to find the index of / in String[] c.

But when printing a, eclipse said The local variable a may not have been initialized.

I know I can print a if I put System.out.println(a); in if-else {}, but I have more works to do on this code so I must use printing code outside if-else.

I used else code but still have an error. What's the problem?

If condition in power bi

Greeting.i have a list on Sharepoint that have product column and quantity and percentage of delivery. I want to use these information in power bi.i want to show that if percentage from 0-50 then delivered and if not then demanded.i tried to add a conditional column but i don’t know how to write the condition.could you help me please.

SSRS Switch statements for multiple conditions

I'm attempting to use a SWITCH statement in order for Report Builder to tell me the premium depending on the level of cover that's selected for this particular part of a policy.

The statement I'm using:

=SWITCH(Fields!Salon_Stock_Equipment_Cover.Value="NOTREQ", "Not Required", 
Fields!Salon_Stock_Equipment_Cover.Value="1500", "22.40", 
Fields!Salon_Stock_Equipment_Cover.Value="2500", "33.60", 
Fields!Salon_Stock_Equipment_Cover.Value="5000", "39.20")

I'm using this in Report Builder.

How to use if statments to run second function Google script

I am trying to speed up my script, right now I currently have it set up so that on a button click a custom dialog (HTML) appears asking some questions. On submit, it calls out a gs function to pull the info back as variables. Depending on the first answer I have a series of If statments that trigger. Each of them pull up a different template, make a copy, populate some cells, emails it to you, and then dumps the data into a tracker. Each of them are different so the script is rather long - is there a way to have each if statment its own function? Would this even help the speed? I am new to scripting so any feedback is appreciated. Below is the Code and HTML

{
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Create Doc.')
      .addItem('Create Tracked Document', 'addItem')
      .addToUi();
}

function addItem()//starts the initiation process
{
  var html = HtmlService.createTemplateFromFile('form')
   .evaluate()
  .setWidth(300)
  .setHeight(550);
  SpreadsheetApp.getUi()  
  .showModalDialog(html, 'Create New Document');
}


function addNewItem(form_data)//pulls data from form
{
  var ui = SpreadsheetApp.getUi();
  var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
  var n = new Date();
  var now = ((n.getMonth()+1) + "/" + n.getDate() + "/" + n.getFullYear());
  var doctyp = form_data.Document_Type;
  var name = form_data.Name;
  var title = form_data.Title;
  var platform = form_data.Platform;
  var area = form_data.Area;
  var rota = form_data.Rotation;
  var works = form_data.WorkSt;
  var recipient = Session.getEffectiveUser().getEmail();


  if (form_data.Document_Type == "Text2"){

     var dumpfolder = DriveApp.getFolderById("12345")
    var templateSheet =  DriveApp.getFileById("67890");
    var Newform2= templateSheet.makeCopy(title+ " "+now,dumpfolder);
    var qs = SpreadsheetApp.open(Newform2);
    var dropSheet = qs.getSheetByName("blank");
    var URL3 = Newform2.getUrl();
      dropSheet.getRange("i8").setValue(title);
      dropSheet.getRange("bc5").setValue(now);
      dropSheet.getRange("b5").setValue(platform);
      dropSheet.getRange("p5").setValue(area);
      dropSheet.getRange("x5").setValue(rota);
      dropSheet.getRange("al5").setValue(works);
      dropSheet.getRange("at6").setValue(name);
      NewOPLPOA.setSharing(DriveApp.Access.DOMAIN,DriveApp.Permission.COMMENT);
      NewOPLPOA.setOwner("ME");

      sheet.appendRow([now,doctyp,name,title,platform,area,rota,works,URL3]); 

    GmailApp.sendEmail(recipient, title+ " has been created.", "Your document has been created." +'\n'+ "Here is the link to your copy! Link: " + URL3);

   ui.alert("Email Sent", "An email has been sent with your documents link. You can also use the below link to view the document now, click ctrl C to copy. \
    " +  URL3, ui.ButtonSet.OK);
     }


else if (form_data.Document_Type == "Text1"){

    var dumpfolder = DriveApp.getFolderById("abcd")
    var templateSheet =  DriveApp.getFileById("bgtrd");
    var Newform1 = templateSheet.makeCopy(title+ " "+now,dumpfolder);
    var qs = SpreadsheetApp.open(Newform1);
    var dropSheet = qs.getSheetByName("DOC1");
    var URL4 = Newform1.getUrl();
      dropSheet.getRange("aa3").setValue(platform);
      dropSheet.getRange("ah3").setValue(area);
      dropSheet.getRange("ao3").setValue(works);
      NewSEWO.setSharing(DriveApp.Access.DOMAIN, DriveApp.Permission.COMMENT);
      NewSEWO.setOwner("Me");

    sheet.appendRow([now,doctyp,name,title,platform,area,rota,works,URL4]); 

    GmailApp.sendEmail(recipient, title+ " has been created.", "Your document has been created." +'\n'+ "Here is the link to your copy! Link: " + URL4);

   ui.alert("Email Sent", "An email has been sent with your documents link. You can also use the below link to view the document now, click ctrl C to copy. \
    " +  URL4, ui.ButtonSet.OK);

  } 
  else{
    ui.alert("Error, Please try again, make sure you are listing all required information.");
  }
}




--HTML--

<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
  </head>
  <body>
  <form id="myform">

    <div class="form-group">
    <label for="Document_Type">Document Type</label>
     <select class="form-control" id="Document_Type" name = "Document_Type" required="required">
  <?
 var SS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Set Up");
var Avals = SS.getRange("A2:A").getValues();
var numberOfValues = Avals.filter(String).length;
var RangeVals = SS.getRange(2,1,numberOfValues).getValues();
  ?>
    <option disabled selected value> -- select an option -- </option>
    <? for (var i = 0; i < RangeVals.length; ++i) { ?>

      <option><?!= RangeVals[i] ?></option>
    <? } ?>
  </select>
  </div>

    <div class="form-group">
    <label for ="Name">Your Name</label>
    <select class="form-control" name='Name' id="Name" required="required">
       <?
var AvalN = SS.getRange("E2:E").getValues();
var numberOfValuesN = AvalN.filter(String).length;
var RangeValsN = SS.getRange(2,5,numberOfValuesN).getValues();
  ?>

    <option disabled selected value> -- select an option -- </option>
    <? for (var i = 0; i < RangeValsN.length; ++i) { ?>

      <option><?!= RangeValsN[i] ?></option>
    <? } ?>   
    </select>
    </div>


    <div class="form-group">
    <label for="Platform">Platform</label>
    <select class="form-control" id="Platform" name = "Platform" required="required">
             <?
var AvalP = SS.getRange("C2:C").getValues();
var numberOfValuesP = AvalP.filter(String).length;
var RangeValsP = SS.getRange(2,3,numberOfValuesP).getValues();
  ?>
        <option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsP.length; ++i) { ?>

      <option><?!= RangeValsP[i] ?></option>
    <? } ?>   
    </select>
    </div>

     <div class="form-group">
    <label for="Area">Area</label>
    <select class="form-control" id="Area" name = "Area" required="required">
             <?
var AvalA = SS.getRange("D2:D").getValues();
var numberOfValuesA = AvalA.filter(String).length;
var RangeValsA = SS.getRange(2,4,numberOfValuesA).getValues();
  ?>
       <option disabled selected value> -- select an option -- </option>
 <? for (var i = 0; i < RangeValsA.length; ++i) { ?>

      <option><?!= RangeValsA[i] ?></option>
    <? } ?>   
    </select>
    </div>

    <div class="block form-group">
    <label for="Rotation">Rotation</label>
    <select class="form-control" name='Rotation' id="Rotation">
          <?
var AvalR = SS.getRange("F2:F").getValues();
var numberOfValuesR = AvalR.filter(String).length;
var RangeValsR = SS.getRange(2,6,numberOfValuesR).getValues();
  ?>
    <option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsR.length; ++i) { ?>

      <option><?!= RangeValsR[i] ?></option>
    <? } ?>   
   </select>
   </div>


    <div class="block form-group">
    <label for="WorkSt">Work Station</label>
    <input type='text' name='WorkSt' id="WorkSt" />
    </div>

    <div class="block form-group">
    <label for="Title">Title</label>
    <input type='text' name='Title' id="Title" required="required"/>
    </div>


    <div class="block">
    <button type="submit" class="action">Submit</button>

    </div>
    </form>
    <script>
    document.querySelector("#myform").addEventListener("submit", 
    function(e)
    {
    e.preventDefault();    //stop form from submitting
    google.script.run.addNewItem(this);
     google.script.host.close();//close this dialogbox
    }
    );
    </script>
  </body>
</html>

Find the number of observations since the opposite event occured in R using datatables

I am hoping to create a new variable in datatable that adds a column telling me the number of days since the opposite (or other event occured).

The dataset I have looks like the following:

  date     event  id obs_since_event_1 obs_since_event_2
2000-07-06     2  1        NA                 NA
2000-07-07     1  1        NA                 1
2000-07-09     0  1        1                  2
2000-07-10     0  1        2                  3
2000-07-15     2  1        3                  4
2000-07-16     1  1        4                  1
2000-07-20     0  1        1                  2
2000-07-21     1  1        2                  3
2000-07-06     1  2        NA                 NA
2000-07-07     2  2        1                  NA
2000-07-15     0  2        2                  1
2000-07-16     0  2        3                  2
2000-07-17     2  2        4                  3
2000-07-18     1  2        5                  1

And I am hoping to add a column called days_since_opposite. which records number of days since the opposite event occurred (the opposite events being 1 and 2). I already have the number of days since either an event 1 or 2 occurred. Now I need to work out an if statement that works in datatables that will provide me with the corresponding values in the final column.

  date     event  id obs_since_event_1 obs_since_event_2 days_since_opposite
2000-07-06     2  1        NA                 NA                  NA
2000-07-07     1  1        NA                 1                   NA
2000-07-09     0  1        1                  2                   NA
2000-07-10     0  1        2                  3                   NA
2000-07-15     2  1        3                  4                   3
2000-07-16     1  1        4                  1                   1
2000-07-20     0  1        1                  2                   NA
2000-07-21     1  1        2                  3                   3

I hope this is clear. I also have different ids to reckon with but not sure if it impacts the results.

I tried something along the following lines but it did not work:

data[,days_since_opposite:=ifelse(event==1,obs_since_event_2,ifelse(event==2,obs_since_event_1,0)),]

Thanks in advance

Add multiple statements to IF/OR

I am looking to add a formula which states multiple ifs into one equation (not the best at this) The equations are below, which are in cell H2

DES = EQ
DSW = OTC
DRS = OTC
342 = FX
HFX = FX
0C8 = ETD
109 = SS

Wanted to simply as much as possible so that it starts off similar to the below, just wasn't sure how to add the rest.

Started with

=IF(H2="DES","EQ"