-2

TWA の値に基づいてテキストの色を変更するこの c# スクリプトがあります。ほとんどの場合は機能しますが、

TWA value is >=85 (where it should be yellow) and >= 90 (where it should be red).

これを修正する方法は?

スクリプトは次のとおりです。

protected System.Drawing.Color GetColorForLabel(string text)
{
    int theTWAValue;
    if (text != null && int.TryParse(text, out theTWAValue) && theTWAValue >= 0)
    {
        return (theTWAValue < 90) ? System.Drawing.Color.Yellow : System.Drawing.Color.Red;
    }

    return System.Drawing.Color.Green;
}

追加情報:

ユーザーがドロップダウン リストから特定のジョブ コードを選択し、すべてのデータ値がaccess database

Edit2:debuggingまだ解決策が見つからなかった後でも、if ステートメントが失敗する理由についていくつかの支援があれば素晴らしいでしょう

編集 3: 残りのコードは次のとおりです。

<asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:2007 SoundAssist VER 1.0.5  05-12-2011 ( 2013-06-24)ConnectionString %>" ProviderName="<%$ ConnectionStrings:2007  SoundAssist VER 1.0.5  05-12-2011 ( 2013-06-24)ConnectionString.ProviderName %>" SelectCommand="SELECT [Plant] FROM [PLANT]">
  </asp:SqlDataSource>
  <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Plant" DataValueField="Plant" Height="85px" Width="393px">
  </asp:DropDownList>
  <asp:SqlDataSource id="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:2007  SoundAssist VER 1.0.5  05-12-2011 ( 2013-06-24)ConnectionString %>" ProviderName="<%$ ConnectionStrings:2007  SoundAssist VER 1.0.5  05-12-2011 ( 2013-06-24)ConnectionString.ProviderName %>" SelectCommand="SELECT [Plant], [Group No#] AS column1, [Group] FROM [Temp Table that contains TWA values] WHERE ([Plant] = ?)">
      <SelectParameters>
          <asp:ControlParameter ControlID="DropDownList1" Name="Plant" PropertyName="SelectedValue" Type="String" />
      </SelectParameters>
  </asp:SqlDataSource>
  <asp:DropDownList id="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Group" DataValueField="column1" Height="30px" Width="394px">
  </asp:DropDownList>
  <asp:SqlDataSource id="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:2007  SoundAssist VER 1.0.5  05-12-2011 ( 2013-06-24)ConnectionString %>" ProviderName="<%$ ConnectionStrings:2007  SoundAssist VER 1.0.5  05-12-2011 (2013-06-24)ConnectionString.ProviderName %>" SelectCommand="SELECT [Plant], [Group No#] AS column1, [Group], [Job Code] AS Job_Code, [Job Function] AS Job_Function, [Job Classification] AS Job_Classification FROM [Temp Table that contains TWA values] WHERE (([Plant] = ?) AND ([Group No#] = ?))">
      <SelectParameters>
          <asp:ControlParameter ControlID="DropDownList1" Name="Plant" PropertyName="SelectedValue" Type="String" />
          <asp:ControlParameter ControlID="DropDownList2" Name="column1" PropertyName="SelectedValue" Type="String" />
      </SelectParameters>
  </asp:SqlDataSource>
  <asp:DropDownList id="DropDownList3" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="Job_Classification" DataValueField="Job_Classification" Height="17px" Width="384px">
  </asp:DropDownList>
  <asp:ListView id="YourListView" OnLoad="YourListView_Load" runat="server"  DataSourceID="SqlDataSource4">
      <ItemTemplate>
          <span style="">Plant:
          <asp:Label id="PlantLabel" runat="server" Text='<%# Eval("Plant") %>' />
          <br />
          column1:
          <asp:Label id="column1Label" runat="server" Text='<%# Eval("column1") %>' />
          <br />
          Group:
          <asp:Label id="GroupLabel" runat="server" Text='<%# Eval("Group") %>' />
          <br />
          Job_Code:
          <asp:Label id="Job_CodeLabel" runat="server" Text='<%# Eval("Job_Code") %>' />
          <br />
          Job_Classification:
          <asp:Label id="Job_ClassificationLabel" runat="server" Text='<%# Eval("Job_Classification") %>' />
          <br />
          Job_Function:
          <asp:Label id="Job_FunctionLabel" runat="server" Text='<%# Eval("Job_Function") %>' />
          <br />
          Job_Description:
          <asp:Label id="Job_DescriptionLabel" runat="server" Text='<%# Eval("Job_Description") %>' />
          <br />
          TWA:
          <asp:Label id="TWALabel" runat="server" Text='<%# Eval("TWA") %>'  ForeColor='<%# GetColorForLabel( Eval("TWA") as string ) %>'/>
          <br />
          <br />
          </span>
      </ItemTemplate>

      </asp:ListView>
  <asp:SqlDataSource id="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:2007  SoundAssist VER 1.0.5  05-12-2011 ( 2013-06-24)ConnectionString %>" ProviderName="<%$ ConnectionStrings:2007  SoundAssist VER 1.0.5  05-12-2011 ( 2013-06-24)ConnectionString.ProviderName %>" SelectCommand="SELECT [Plant], [Group No#] AS column1, [Group], [Job Code] AS Job_Code, [Job Classification] AS Job_Classification, [Job Function] AS Job_Function, [Job Description] AS Job_Description, [TWA] FROM [Temp Table that contains TWA values] WHERE (([Plant] = ?) AND ([Group No#] = ?) AND ([Job Classification] = ?))">
      <SelectParameters>
          <asp:ControlParameter ControlID="DropDownList1" Name="Plant" PropertyName="SelectedValue" Type="String" />
          <asp:ControlParameter ControlID="DropDownList2" Name="column1" PropertyName="SelectedValue" Type="String" />
          <asp:ControlParameter ControlID="DropDownList3" Name="Job_Classification" PropertyName="SelectedValue" Type="String" />
      </SelectParameters>
  </asp:SqlDataSource>

私はまだエラーを修正できていないので、入力は依然として非常に貴重です

4

4 に答える 4

1

textnullまたはint.TryParseのいずれかです。変換できない入力が原因で失敗します。

int theTWAValue;
string text = "95";
if (text != null && int.TryParse(text, out theTWAValue) && theTWAValue >= 0)
{
    Console.WriteLine((theTWAValue < 90) ? "System.Drawing.Color.Yellow" : "System.Drawing.Color.Red");
}

プリント: System.Drawing.Color.Red

于 2013-07-17T19:19:43.380 に答える
0

あなたの問題は

if (text != null && int.TryParse(text, out theTWAValue) && theTWAValue >= 0)

デバッグしてステップ実行し、失敗の理由を見つける必要があります。これを if ステートメントの前に追加し、コンソールを確認します。

if(text == null) 
     Console.WriteLine("Text is null");
if(!int.TryParse(text, out theTWAValue)) 
     Console.WriteLine("Parse Failed");
Console.WriteLine("TWA Value: " + theTWAValue);
于 2013-07-17T19:22:33.127 に答える