Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net中从arraylist中移动元素_C#_Asp.net_Arrays_Sorting_Arraylist - Fatal编程技术网

C# 在asp.net中从arraylist中移动元素

C# 在asp.net中从arraylist中移动元素,c#,asp.net,arrays,sorting,arraylist,C#,Asp.net,Arrays,Sorting,Arraylist,我有一个项目,我坚持这件事。我想在html表格中只显示三行页面上的报警。目前我有三个表格,但我想显示多个表4、表5、表6等 这是我的项目代码: public ArrayList myArr = new ArrayList(); public static string alarma_valoare { get; set; } public static string alarma_denumire_punct { get; set; } public static string alarma_

我有一个项目,我坚持这件事。我想在html表格中只显示三行页面上的报警。目前我有三个表格,但我想显示多个表4、表5、表6等

这是我的项目代码:

public ArrayList myArr = new ArrayList();

public static string alarma_valoare { get; set; }
public static string alarma_denumire_punct { get; set; }
public static string alarma_timp  { get; set; }
public static string alarma_mesaj { get; set; }


protected void Page_Load(object sender, EventArgs e)
{
    PresSelect();
    TempSelect();
    DebSelect();
    DataDisplay();
}

public void PresSelect()
{

    string query = "String table1";

    dt = GetData(query);

    if (dt.Rows.Count > 0)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            alarm_value = dt.Rows[i]["value"].ToString();
            alarm_n = dt.Rows[i]["value1"].ToString();
            alarma_date = dt.Rows[i]["value2"].ToString();
            alarma_text = dt.Rows[i]["value3"].ToString();



           if (float.Parse(alarm_value) > 11)
            {

                myAr.Add(float.Parse(alarm_value));
                myAr.Add(alarm_n.ToString());
                myAr.Add(alarma_date.ToString());
                myAr.Add(alarma_text.ToString());



            }
            else if (float.Parse(alarm_value) < 11)
            {

                myAr.Add(float.Parse(alarm_value));
                myAr.Add(alarm_n.ToString());
                myAr.Add(alarma_date.ToString());
                myAr.Add(alarma_text.ToString());
            }
         }
    }
}

public void TempSelect()
{

    string query = "string  table2";

    dt = GetData(query);

    if (dt.Rows.Count > 0)
    {
        for (int j = 0; j < dt.Rows.Count; j++)
        {

            alarm_value = dt.Rows[j]["value"].ToString();             
            alarm_n = dt.Rows[j]["value1"].ToString();
            alarma_date = dt.Rows[j]["value2"].ToString();
            alarma_text = dt.Rows[j]["value3"].ToString();

             if (float.Parse(alarm_value) > 22)
            {

                myAr.Add(float.Parse(alarm_value));
                myAr.Add(alarm_n.ToString());
                myAr.Add(alarma_date.ToString());
                myAr.Add(alarma_text.ToString());
            }
            else if (float.Parse(alarm_value) < 22)
           {
                myAr.Add(float.Parse(alarm_value));
                myAr.Add(alarm_n.ToString());
                myAr.Add(alarma_date.ToString());
                myAr.Add(alarma_text.ToString());
            }
        }
    }

}

public void DebSelect()
{

    string query = "String table3";

    dt = GetData(query);

    if (dt.Rows.Count > 0)
    {
        for (int y = 0; y < dt.Rows.Count; y++)
        {


             alarm_n = dt.Rows[y]["value1"].ToString();
             alarma_date = dt.Rows[y]["value2"].ToString();
             alarma_text = dt.Rows[y]["value3"].ToString();

            if (float.Parse(alarm_value) >33)
            {

                    myAr.Add(float.Parse(alarm_value));
                    myAr.Add(alarm_n.ToString());
                    myAr.Add(alarma_date.ToString());
                    myAr.Add(alarma_text.ToString());
            }
            else if (float.Parse(alarm_value) < 33 )
            {

                myAr.Add(float.Parse(alarm_value));
                myAr.Add(alarm_n.ToString());
                myAr.Add(alarma_date.ToString());
                myAr.Add(alarma_text.ToString());
            }
        }
    }

}

public void DataDisplay()
{


    //in this function I want to display data in my html table

 }



private static DataTable GetData(string query)
{
    DataTable dt = new DataTable();
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {

        using (SqlCommand cmd = new SqlCommand(query))
        {
            cmd.CommandTimeout = 0;
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.CommandType = CommandType.Text;
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                sda.Fill(dt);

            }
        }

        return dt;
    }
    SqlConnection.ClearAllPools();
}               
结束我想在html表格中显示如下内容:

[0]  value - from table1
[1]  value1 - from table1
[2]  value2 - from table1
[3]  value3 - from table1

[4]  value - from table2
[5]  value1 - from table2
[6]  value2 - from table2
[7]  value3 - from table2

[8]  value - from table3
[9]  value1 - from table3
[10] value2 - from table3
[11] value3 - from table3
Value/name                Date                           Message   
value/value1(T1)        value2(T1)                       value3(T1)
value/value1(T2)        value2(T2)                       value3(T2)
value/value1(T3)        value2(T3)                       value3(T3)
 [0]  value - from table3
 [1]  value - from table3
 [2]  value - from table3
 [3]  value - from table3

 [4]  value - from table1
 [5]  value - from table1
 [6]  value - from table1
 [7]  value - from table1

 [8]  value - from table2
 [9]  value - from table2
 [10] value - from table2
 [11] value - from table2

 Value/name                Date                           Message   
 value/value1(T3)        value2(T3)                       value3(T3)
 value/value1(T1)        value2(T1)                       value3(T1)
 value/value1(T2)        value2(T2)                       value3(T2)
  [11]  value - from table3
  [10]  value - from table3
  [9]  value - from table3
  [8]  value - from table3

  [7]  value - from table2
  [6]  value - from table2
  [5]  value - from table2
  [4]  value - from table2

  [3]  value - from table1
  [2]  value - from table1
  [1] value - from table1
  [0] value - from table1
//First element
  [11]  value - from table4
  [10]  value - from table4
  [9]  value - from table4
  [8]  value - from table4

  [7]  value - from table3
  [6]  value - from table3
  [5]  value - from table3
  [4]  value - from table3

  [3]  value - from table2
  [2]  value - from table2
  [1] value - from table2
  [0] value - from table2
    //First element
当数据库中出现table3 my array的新值时,我希望如下所示:

[0]  value - from table1
[1]  value1 - from table1
[2]  value2 - from table1
[3]  value3 - from table1

[4]  value - from table2
[5]  value1 - from table2
[6]  value2 - from table2
[7]  value3 - from table2

[8]  value - from table3
[9]  value1 - from table3
[10] value2 - from table3
[11] value3 - from table3
Value/name                Date                           Message   
value/value1(T1)        value2(T1)                       value3(T1)
value/value1(T2)        value2(T2)                       value3(T2)
value/value1(T3)        value2(T3)                       value3(T3)
 [0]  value - from table3
 [1]  value - from table3
 [2]  value - from table3
 [3]  value - from table3

 [4]  value - from table1
 [5]  value - from table1
 [6]  value - from table1
 [7]  value - from table1

 [8]  value - from table2
 [9]  value - from table2
 [10] value - from table2
 [11] value - from table2

 Value/name                Date                           Message   
 value/value1(T3)        value2(T3)                       value3(T3)
 value/value1(T1)        value2(T1)                       value3(T1)
 value/value1(T2)        value2(T2)                       value3(T2)
  [11]  value - from table3
  [10]  value - from table3
  [9]  value - from table3
  [8]  value - from table3

  [7]  value - from table2
  [6]  value - from table2
  [5]  value - from table2
  [4]  value - from table2

  [3]  value - from table1
  [2]  value - from table1
  [1] value - from table1
  [0] value - from table1
//First element
  [11]  value - from table4
  [10]  value - from table4
  [9]  value - from table4
  [8]  value - from table4

  [7]  value - from table3
  [6]  value - from table3
  [5]  value - from table3
  [4]  value - from table3

  [3]  value - from table2
  [2]  value - from table2
  [1] value - from table2
  [0] value - from table2
    //First element
和表2中的另一个值

  [0]  value - from table2
  [1]  value - from table2
  [2]  value - from table2
  [3]  value - from table2

  [4]  value - from table3
  [5]  value - from table3
  [6]  value - from table3
  [7]  value - from table3

  [8]  value - from table1
  [9]  value - from table1
  [10] value - from table1
  [11] value - from table1

  Value/name                Date                           Message   
 value/value1(T2)        value2(T2)                       value3(T2)
 value/value1(T3)        value2(T3)                       value3(T3)
 value/value1(T1)        value2(T1)                       value3(T1)
我想移动myarraylist中的元素并显示在html表中,这是我现在想从数据库中为三个表做的事情,但将来我会有多个表


对不起,我的英语不好,如果我不懂,我会尽量解释得更好。

我想你可以排队

让我解释一下。如果您有一个队列(您可以进行一些检查,以确保始终有12个元素),并且您开始对值进行排队,您将得到如下结果:

[0]  value - from table1
[1]  value1 - from table1
[2]  value2 - from table1
[3]  value3 - from table1

[4]  value - from table2
[5]  value1 - from table2
[6]  value2 - from table2
[7]  value3 - from table2

[8]  value - from table3
[9]  value1 - from table3
[10] value2 - from table3
[11] value3 - from table3
Value/name                Date                           Message   
value/value1(T1)        value2(T1)                       value3(T1)
value/value1(T2)        value2(T2)                       value3(T2)
value/value1(T3)        value2(T3)                       value3(T3)
 [0]  value - from table3
 [1]  value - from table3
 [2]  value - from table3
 [3]  value - from table3

 [4]  value - from table1
 [5]  value - from table1
 [6]  value - from table1
 [7]  value - from table1

 [8]  value - from table2
 [9]  value - from table2
 [10] value - from table2
 [11] value - from table2

 Value/name                Date                           Message   
 value/value1(T3)        value2(T3)                       value3(T3)
 value/value1(T1)        value2(T1)                       value3(T1)
 value/value1(T2)        value2(T2)                       value3(T2)
  [11]  value - from table3
  [10]  value - from table3
  [9]  value - from table3
  [8]  value - from table3

  [7]  value - from table2
  [6]  value - from table2
  [5]  value - from table2
  [4]  value - from table2

  [3]  value - from table1
  [2]  value - from table1
  [1] value - from table1
  [0] value - from table1
//First element
  [11]  value - from table4
  [10]  value - from table4
  [9]  value - from table4
  [8]  value - from table4

  [7]  value - from table3
  [6]  value - from table3
  [5]  value - from table3
  [4]  value - from table3

  [3]  value - from table2
  [2]  value - from table2
  [1] value - from table2
  [0] value - from table2
    //First element
然后,如果您得到一个新值:

使用Dequeue()4次,您将得到以下结果:

  [7]  value - from table3
  [6]  value - from table3
  [5]  value - from table3
  [4]  value - from table3

  [3]  value - from table2
  [2]  value - from table2
  [1]  value - from table2
  [0]  value - from table2
//First element
然后对四个新值使用Enqueue(),您将得到如下结果:

[0]  value - from table1
[1]  value1 - from table1
[2]  value2 - from table1
[3]  value3 - from table1

[4]  value - from table2
[5]  value1 - from table2
[6]  value2 - from table2
[7]  value3 - from table2

[8]  value - from table3
[9]  value1 - from table3
[10] value2 - from table3
[11] value3 - from table3
Value/name                Date                           Message   
value/value1(T1)        value2(T1)                       value3(T1)
value/value1(T2)        value2(T2)                       value3(T2)
value/value1(T3)        value2(T3)                       value3(T3)
 [0]  value - from table3
 [1]  value - from table3
 [2]  value - from table3
 [3]  value - from table3

 [4]  value - from table1
 [5]  value - from table1
 [6]  value - from table1
 [7]  value - from table1

 [8]  value - from table2
 [9]  value - from table2
 [10] value - from table2
 [11] value - from table2

 Value/name                Date                           Message   
 value/value1(T3)        value2(T3)                       value3(T3)
 value/value1(T1)        value2(T1)                       value3(T1)
 value/value1(T2)        value2(T2)                       value3(T2)
  [11]  value - from table3
  [10]  value - from table3
  [9]  value - from table3
  [8]  value - from table3

  [7]  value - from table2
  [6]  value - from table2
  [5]  value - from table2
  [4]  value - from table2

  [3]  value - from table1
  [2]  value - from table1
  [1] value - from table1
  [0] value - from table1
//First element
  [11]  value - from table4
  [10]  value - from table4
  [9]  value - from table4
  [8]  value - from table4

  [7]  value - from table3
  [6]  value - from table3
  [5]  value - from table3
  [4]  value - from table3

  [3]  value - from table2
  [2]  value - from table2
  [1] value - from table2
  [0] value - from table2
    //First element
明白了吗?;) 我想这可能是解决你问题的办法

以下是想法:

Queue<string> queue = new Queue<string>();

            queue.Enqueue("prueba1");
            queue.Enqueue("prueba2");
            queue.Enqueue("prueba3");
            queue.Enqueue("prueba4");

            queue.Enqueue("prueba5");
            queue.Enqueue("prueba6");
            queue.Enqueue("prueba7");
            queue.Enqueue("prueba8");

            queue.Enqueue("prueba9");
            queue.Enqueue("prueba10");
            queue.Enqueue("prueba11");
            queue.Enqueue("prueba12");

            if (queue.Count == 12)
            {
                queue.Dequeue();
                queue.Dequeue();
                queue.Dequeue();
                queue.Dequeue();
                queue.Enqueue("prueba13");
                queue.Enqueue("prueba14");
                queue.Enqueue("prueba15");
                queue.Enqueue("prueba16");
            }
Queue Queue=new Queue();
排队。排队(“prueba1”);
排队。排队(“prueba2”);
排队。排队(“prueba3”);
排队。排队(“prueba4”);
排队。排队(“prueba5”);
排队。排队(“prueba6”);
排队。排队(“prueba7”);
排队。排队(“prueba8”);
排队。排队(“prueba9”);
排队。排队(“prueba10”);
排队。排队(“prueba11”);
排队。排队(“prueba12”);
如果(queue.Count==12)
{
queue.Dequeue();
queue.Dequeue();
queue.Dequeue();
queue.Dequeue();
排队。排队(“prueba13”);
排队。排队(“prueba14”);
排队。排队(“prueba15”);
排队。排队(“prueba16”);
}

我不会为此使用ArrayList。创建一个类来保存数据,并为其提供有意义的属性名称。然后,您可以更改GetData方法以提供这些类的集合,您可以在表示逻辑中使用这些类来填充HTML表

也许像下面这样

class AlarmData {

    public float AlarmValue { get; set; }
    public string AlarmN { get; set; }
    public string AlarmDate { get; set; } // Could even be of type DateTime
    public string AlarmText { get; set; }

}
在您的
DebSelect
TempSelect
按select
方法中,有大量重复的代码。可能会将其中的大部分移动到GetData方法中,而不是填充arraylist,创建
AlarmData
对象的集合并返回这些对象

然后,您的
DebSelect
TempSelect
PresSelect
方法只需对返回的数据执行条件逻辑即可

对于您的
DataDisplay
方法,我将研究构建ASP.NET表或div的方法,或者您选择的任何布局内容的方法。如果您真的想这样做,您可以查看自定义业务对象(
AlarmData
)的数据绑定,以进一步简化操作


这与您最初的示例有相当大的偏差,但我建议这可能是一个值得的示例。

如果您为我的问题发布一个示例(一个ideea),使用队列和出列来理解这个概念。我认为这很容易。创建队列。然后,在您实际向列表中“添加”元素的行中,检查您的队列是否包含12个元素,如果是,则先将4个元素出列,然后将新元素入列,如果没有足够的空间,则只将新元素入列。我在谷歌上搜索,对这个概念有所了解。现在的问题是我不知道如何在html表中显示这个东西。很抱歉我的新手问题,但我不是程序员,但我必须完成这个项目。对不起,我不知道如何帮助您使用web部件。我不是一个网络开发者。很抱歉,在这个问题上,我只能帮你。