schangxiang@126.com
2024-12-16 06d6ba0da4d9036bf3eeab8a7cbef8df89565606
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
 
using iWareCommon.Utils;
using iWareSql.DBModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareUnitTest
{
    [TestClass]
    public class CSharpTest
    {
        [TestMethod]
        public void Test_String()
        {
            //var bb = "缺料原因:失败了啊|DDDADA";
            var bb = "DDDADA";
            //var bb = "";
            //var bb = "缺料原因:失败了啊|";
            var queliaoReason = "堆垛机故障";
 
            char splitStr = '|';
            var updateRemark = "缺料原因:" + queliaoReason;
            if (string.IsNullOrEmpty(bb))
            {
                bb = updateRemark + splitStr;
            }
            else
            {
                //解析字符串
                var arr = bb.Split(splitStr);
                bb = updateRemark + splitStr + arr.Last();
            }
 
            var zz = bb;
        }
 
        [TestMethod]
        public void Test_EF_OrderBy()
        {
            Task_Main a1 = new Task_Main();
            a1.Id = 1;
            a1.CreateTime = Convert.ToDateTime("2022-05-21 08:55:01.000");
            a1.TaskSequence = 55;
 
            Task_Main a2 = new Task_Main();
            a2.Id = 2;
            a2.CreateTime = Convert.ToDateTime("2022-05-21 08:55:02.000");
            a2.TaskSequence = 55;
 
            Task_Main a3 = new Task_Main();
            a3.Id = 3;
            a3.CreateTime = Convert.ToDateTime("2022-05-21 08:56:01.000");
            a3.TaskSequence = 55;
 
 
            Task_Main a4 = new Task_Main();
            a4.Id = 4;
            a4.CreateTime = Convert.ToDateTime("2022-05-21 08:56:00.000");
            a4.TaskSequence = 51;
 
            Task_Main a5 = new Task_Main();
            a5.Id = 5;
            a5.CreateTime = Convert.ToDateTime("2022-05-21 08:56:01.000");
            a5.TaskSequence = 57;
 
            List<Task_Main> mainList = new List<Task_Main>();
            mainList.Add(a1);
            mainList.Add(a2);
            mainList.Add(a3);
            mainList.Add(a4);
            mainList.Add(a5);
 
            var bb = mainList.OrderBy(x => x.TaskSequence).ThenBy(x => x.CreateTime).ToList();
            /*
             *  证明排序是 先按照TaskSequence排序,如果TaskSequence相等,就按照CreateTime内部小排序。
             */
            string zz = JsonConvert.SerializeObject(bb);
            Assert.IsFalse(false);
 
        }
 
        [TestMethod]
        public void Test_ExecPercentRetInt()
        {
            int i = CSharpHelper.ExecPercentRetInt(22, 24);
 
            Assert.IsFalse(false);
        }
        [TestMethod]
        public void TestDictionary()
        {
            //C#求获取一个Dictionary中value最小的key
            Dictionary<string, int> dict = new Dictionary<string, int>();
            dict.Add("1", 1);
            dict.Add("2", 2);
            dict.Add("3", 3);
            dict.Add("4", 4);
            dict.Add("5", 1);
 
            var minKey = (from d in dict orderby d.Value ascending select d.Key).First();
            //考虑到不止一条的情况,分两步查询最小值的所有Key,这样的写法可能更好看懂
            var allMinKeys = (from d in dict where d.Value == dict[minKey] select d.Key).ToArray();
 
            var minkey = dict.Keys.Select(x => new { x, y = dict[x] }).OrderBy(x => x.y).First().x;
 
 
            var bb = dict.OrderBy(d => d.Value).Select(d => d.Key).FirstOrDefault();
 
 
            Assert.IsFalse(false);
        }
 
 
        [TestMethod]
        public void TestNull()
        {
            int? aa = null;
            int b = 1 + (int)aa;
            Assert.IsFalse(false);
        }
 
        [TestMethod]
        public void TestList()
        {
            List<string> sList = new List<string>();
            sList.Add("zzz");
            sList.Add("888");
            string cc = JsonConvert.SerializeObject(sList);
        }
    }
}