Fuction.cs 63.5 KB
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data;
using System.IO;
using ZedGraph;
using System.Drawing;
using Comm;

namespace Dal
{
    public class Fuction
    {
        #region 使用者习惯定义
        public static string m_CurrentDirectory = "";
        public static string m_UserName; //姓名
        public static string m_UserLogin; //帐号
        public static string m_UserComp; //公司
        public static string m_UserDep; //部门
        public static string m_UserPWD; //密码
        public static string m_UserAuth; //权限
        public static string m_Language; //语言选择
        #endregion
        #region 参数定义

        public static string m_UserResult; //测试结果显示
        public static string m_UserLengthUnit; //长度单位
        public static string m_UserCleanUnit; //清洁度单位
        public static string m_UserTempUnit; //温度单位
        public static string m_UserTimeUnit; //时间单位

        public string m_ParaCleanTroughL; //清洗槽长度
        public string m_ParaCleanTroughW; //清洗槽宽度
        public string m_ParaPrecision; //传感器精度
        public static string m_ParaPort; //通讯端口
        public string m_ParaConnection; //通讯方式

        public static string m_ParaAdjustQuotiety; //校准系数
        public static string m_ParaWashTime; //清洗时长
        public static string m_ParaWashUpperLimit; //清洗上限
        public static string m_ParaLong; //长
        public static string m_ParaWidth; //宽
        public static string m_ParaHeight; //高

        public static string m_ParaKValue; //K值
        public static string m_ParaK75; //K75
        public static string m_ParaK50; //K50

        public string m_ParaTestMode; //测试模式
        public string m_ParaIsHeat; //是否加热
        public string m_ParaTempStandart; //温度标准
        public string m_ParaFiltrateLimit; //过滤极限
        public string m_ParaInfallMaxLimit; //进水上限
        public string m_ParaInfallMinLimit; //进水下限
        public string m_ParaDensityStandard; //密度标准

        public string m_ParaUserLimit; //用户极限
        public string m_ParaIPC;//IPC
        public static string m_ParaTestTime; //测试时间
        public string m_ParaInfallHeigth; //进水高度
        public static string m_ParaTestSolvent; //测试溶剂

        public string m_ParaReviseType; //修正方式
        public string m_ParaMIL; //MIL修正值
        public string m_ParaDEF; //DEF修正值

        public string m_ParaProductRoot; //产品路径
        public string m_ParaProduct; //产品
        public string m_ParaProductL; //产品长度
        public string m_ParaProductW; //产品宽度
        public static string m_ParaProductArea; //产品面积
        public string m_ParaSuggest; //建议进水高度
        public string m_ParaNotes;//产品备注
        public static string m_ParaInvertal;//判定无数据读入间隔时间
        public static string m_ParaIsCalibration;//是否为校准
        public static string m_ParaReadDataType;//读取数据方式
        public static string m_ParaDynamicArea1;//动态校准面积1
        public static string m_ParaDynamicArea2;
        public static string m_ParaDynamicArea3;
        public static string m_ParaDynamicArea4;
        #endregion

        #region 登录,权限
        /// <summary>
        /// 判断是否有权限
        /// </summary>
        /// <param name="auth"></param>
        /// <returns></returns>
        public bool HaveAuth(string auth)
        {
            string[] allAuth = m_UserAuth.Split(',');
            for (int i = 0; i < allAuth.Length; i++)
            {
                if (allAuth[i] == auth)
                    return true;
            }
            return false;
        }
        /// <summary>
        /// 获取帐号信息
        /// </summary>
        /// <param name="LoginName"></param>
        /// <returns></returns>
        public DataTable GetLoginInfoByLoginName(string LoginName)
        {
            DataTable table1 = new DataTable(Const.USER_LOGIN);
            DataColumnCollection columns = table1.Columns;
            columns.Add(Const.USER_LOGIN, typeof(System.String));
            columns.Add(Const.USER_NAME, typeof(System.String));
            columns.Add(Const.USER_PWD, typeof(System.String));
            columns.Add(Const.USER_COMP, typeof(System.String));
            columns.Add(Const.USER_DEP, typeof(System.String));
            columns.Add(Const.USER_AUTH, typeof(System.String));
            DataRow dr;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                if (m_CurrentDirectory == "")
                    m_CurrentDirectory = System.Environment.CurrentDirectory;
                xmlDoc.Load(m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME);
                XmlNode node = xmlDoc.FirstChild;
                if (LoginName != "")
                {
                    string xpath = "descendant::" + LoginName;
                    node = node.SelectSingleNode(xpath);
                    if (node != null)
                    {
                        dr = table1.NewRow();
                        dr[Const.USER_LOGIN] = node.Name;
                        dr[Const.USER_NAME] = GetAttributes(node, Const.USER_NAME);
                        dr[Const.USER_PWD] = GetAttributes(node, Const.USER_PWD);
                        dr[Const.USER_COMP] = GetAttributes(node, Const.USER_COMP);
                        dr[Const.USER_DEP] = GetAttributes(node, Const.USER_DEP);
                        dr[Const.USER_AUTH] = GetAttributes(node, Const.USER_AUTH);

                        m_UserName = dr[Const.USER_NAME].ToString();
                        m_UserPWD = dr[Const.USER_PWD].ToString(); //密码
                        m_UserComp = dr[Const.USER_COMP].ToString(); //公司
                        m_UserDep = dr[Const.USER_DEP].ToString(); //部门
                        m_UserAuth = dr[Const.USER_AUTH].ToString(); //权限
                        table1.Rows.Add(dr);
                    }
                }
                else
                {
                    foreach (XmlNode nc in node.ChildNodes)
                    {
                        dr = table1.NewRow();
                        dr[Const.USER_LOGIN] = nc.Name;
                        dr[Const.USER_NAME] = GetAttributes(nc, Const.USER_NAME);
                        dr[Const.USER_PWD] = GetAttributes(nc, Const.USER_PWD);
                        dr[Const.USER_COMP] = GetAttributes(nc, Const.USER_COMP);
                        dr[Const.USER_DEP] = GetAttributes(nc, Const.USER_DEP);
                        dr[Const.USER_AUTH] = GetAttributes(nc, Const.USER_AUTH);
                        table1.Rows.Add(dr);
                    }
                }
            }
            catch { }
            return table1;
        }

        /// <summary>
        /// 判断登录是否成功
        /// </summary>
        /// <param name="LoginName"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public int GetEmployeeByLoginNameAndPassword(string LoginName, string Password)
        {
            int Login = 0;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME);
                XmlNode node = xmlDoc.FirstChild;

                string xpath = "descendant::" + LoginName;
                node = node.SelectSingleNode(xpath);
                if (node != null)
                {
                    node = node.SelectSingleNode(Const.USER_PWD);
                    if (node != null)
                    {
                        if (node.Attributes["Value"].Value == Password)
                            Login = 1;
                    }
                }
                return Login;
            }
            catch
            {
                return -1;
            }
        }
        /// <summary>
        /// 提取公共方法,通过节点取值
        /// </summary>
        /// <param name="root"></param>
        /// <param name="nodeName"></param>
        /// <returns></returns>
        private string GetAttributes(XmlNode root, string nodeName)
        {
            string returnValue = "";
            XmlNode node = root.SelectSingleNode(nodeName);
            if (node != null)
                returnValue = node.Attributes["Value"].Value;
            return returnValue;
        }
        /// <summary>
        /// 获取登录人信息
        /// </summary>
        /// <param name="LoginName"></param>
        public void LoadXML(string LoginName)
        {
            try
            {
                m_UserLogin = LoginName;
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME);
                XmlNode node = xmlDoc.FirstChild;

                string xpath = "descendant::" + "currency";
                XmlNode root = node.SelectSingleNode(xpath);
                if (root != null)
                {
                    m_UserResult = GetAttributes(root, Const.USER_RESULT);//测试结果显示
                    m_UserLengthUnit = GetAttributes(root, Const.USER_LENGTHUNIT);//长度单位
                    m_UserCleanUnit = GetAttributes(root, Const.USER_CLEANUNIT);//清洁度单位
                    m_UserTempUnit = GetAttributes(root, Const.USER_TEMPUNIT);//温度单位
                    m_UserTimeUnit = GetAttributes(root, Const.USER_TIMEUNIT);//时间单位
                    m_ParaCleanTroughL = GetAttributes(root, Const.PARA_CLEANTROUGHL); //清洗槽长度
                    m_ParaCleanTroughW = GetAttributes(root, Const.PARA_CLEANTROUGHW);//清洗槽宽度
                    m_ParaPrecision = GetAttributes(root, Const.PARA_PRECISION);//传感器精度
                    m_ParaPort = GetAttributes(root, Const.PARA_PORT);//通讯端口
                    m_ParaConnection = GetAttributes(root, Const.PARA_CONNECTION); //通讯方式
                    m_ParaAdjustQuotiety = GetAttributes(root, Const.PARA_ADJUSTQUOTIETY);//校准系数
                    m_ParaWashTime = GetAttributes(root, Const.PARA_WASHTIME);//清洗时长
                    m_ParaWashUpperLimit = GetAttributes(root, Const.PARA_WASHUPPERLIMIT);//清洗上限
                    m_ParaLong = GetAttributes(root, Const.PARA_Long); //长
                    m_ParaWidth = GetAttributes(root, Const.PARA_Width); //宽
                    m_ParaHeight = GetAttributes(root, Const.PARA_Height); //高

                    m_ParaKValue = GetAttributes(root, Const.PARA_KVALUE); //K值
                    m_ParaK75 = GetAttributes(root, Const.PARA_K75);//K75
                    m_ParaK50 = GetAttributes(root, Const.PARA_K50); //K50
                    m_ParaTestMode = GetAttributes(root, Const.PARA_TESTMODE); //测试模式
                    m_ParaIsHeat = GetAttributes(root, Const.PARA_ISHEAT); //是否加热
                    m_ParaTempStandart = GetAttributes(root, Const.PARA_TEMPSTANDART);//温度标准
                    m_ParaFiltrateLimit = GetAttributes(root, Const.PARA_FILTRATELIMIT); //过滤极限
                    m_ParaInfallMaxLimit = GetAttributes(root, Const.PARA_INFALLMAXLIMIT);//进水上限
                    m_ParaInfallMinLimit = GetAttributes(root, Const.PARA_INFALLMINLIMIT);//进水下限
                    m_ParaDensityStandard = GetAttributes(root, Const.PARA_DENSITYSTANDARD); //密度标准
                    m_ParaUserLimit = GetAttributes(root, Const.PARA_USERLIMIT);//用户极限
                    m_ParaIPC = GetAttributes(root, Const.PARA_IPC);//IPC
                    m_ParaTestTime = GetAttributes(root, Const.PARA_TESTTIME);//测试时间
                    m_ParaInfallHeigth = GetAttributes(root, Const.PARA_INFALLHEIGTH); //进水高度
                    m_ParaTestSolvent = GetAttributes(root, Const.PARA_TESTSOLVENT);//测试溶剂
                    m_ParaReviseType = GetAttributes(root, Const.PARA_REVISETYPE); //修正方式
                    m_ParaMIL = GetAttributes(root, Const.PARA_MIL); //MIL修正值
                    m_ParaDEF = GetAttributes(root, Const.PARA_DEF);//DEF修正值
                    //m_ParaProductRoot = GetAttributes(root, Const.PARA_PRODUCTROOT); //产品路径
                    m_ParaProduct = GetAttributes(root, Const.PARA_PRODUCT); //产品
                    m_ParaProductL = GetAttributes(root, Const.PARA_PRODUCTL); //产品长度
                    m_ParaProductW = GetAttributes(root, Const.PARA_PRODUCTW);//产品宽度
                    m_ParaProductArea = GetAttributes(root, Const.PARA_PRODUCTAREA);//产品面积
                    m_ParaSuggest = GetAttributes(root, Const.PARA_SUGGEST);//建议进水高度
                    m_ParaNotes = GetAttributes(root, Const.PARA_NOTES);//产品备注
                    m_ParaInvertal = GetAttributes(root, Const.PARA_INVERTAL);//判断无数据读入时间间隔
                    m_ParaIsCalibration = GetAttributes(root, Const.PARA_ISCALIBRATION);//是否为自动校准版本
                    m_ParaReadDataType = GetAttributes(root, Const.PARA_CALIBRATIONDATA);
                }
            }
            catch
            {
            }
        }

        /// <summary>
        /// 获取登录人某一信息
        /// </summary>
        /// <param name="Parameter"></param>
        /// <returns></returns>
        public string GetParameterByParaName(string Parameter, string LoginName)
        {
            //string LoginName = Fuction.m_UserLogin;
            string Value = "0";
            XmlDocument doc = new XmlDocument();
            if (m_CurrentDirectory == "")
                m_CurrentDirectory = System.Environment.CurrentDirectory;
            doc.Load(m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME);
            XmlNode node = doc.FirstChild;
            XmlNode root = doc.FirstChild;

            string xpath = "descendant::" + LoginName;
            node = node.SelectSingleNode(xpath);
            if (node != null)
            {
                xpath = "descendant::" + Parameter;
                node = node.SelectSingleNode(xpath);
                if (node != null)
                {
                    Value = node.Attributes["Value"].Value;
                    switch (Parameter)
                    {
                        case Const.PARA_CLEANTROUGHL://清洗槽长度
                        case Const.PARA_CLEANTROUGHW://清洗槽宽度
                        case Const.PARA_INFALLHEIGTH: //进水高度
                        case Const.PARA_PRODUCTL://产品长度
                        case Const.PARA_PRODUCTW: //产品宽度
                        case Const.PARA_SUGGEST://建议进水高度
                        case Const.PARA_Long://长
                        case Const.PARA_Width://宽
                        case Const.PARA_Height://高
                            Value = ReChangeLUnit(Value);
                            break;
                        case Const.PARA_WASHTIME://清洗时长 
                        case Const.PARA_TESTTIME: //测试时间
                            Value = ReChangeTimeUnit(Value);
                            break;
                        case Const.PARA_IPC: //用户极限  /cm2
                        case Const.PARA_USERLIMIT: //用户极限  /cm2
                            Value = ChangeAreaUnit(Value);
                            break;
                        case Const.PARA_MIL://MIL修正值
                        case Const.PARA_PRODUCTAREA://产品面积
                            Value = ReChangeAreaUnit(Value);
                            break;
                    }
                }
            }
            
            return Value;
        }
        #endregion
        #region 帐号,产品管理
        /// <summary>
        /// 检查产品,帐号是否同名
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool CheckSameName(string root, string fileName, string name)
        {
            XmlDocument xmlDoc = new XmlDocument();
            string path = "";
            if (fileName == Const.PARAMETERCONFIGNAME)
                path = m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME;
            if (fileName == Const.PRODUCTCONFIGNAME)
                path = root + Const.PRODUCTCONFIGNAME;
            xmlDoc.Load(path);
            XmlNode node = xmlDoc.FirstChild;

            foreach (XmlNode nc in node.ChildNodes)
            {
                if (name == nc.Name)
                    return true;
            }
            return false;
        }

        /// <summary>
        /// 查找所有帐号
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public List<string[]> GetAllLoginName(string fileName)
        {
            List<string[]> loginNameList = new List<string[]>();
            string[] accountInfo;
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                string path;
                path = m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME;
                xmlDoc.Load(path);
            }
            catch
            {
                return loginNameList;
            }
            XmlNode node = xmlDoc.FirstChild;
            foreach (XmlNode nc in node.ChildNodes)
            {
                accountInfo = new string[4];
                accountInfo[0] = nc.Name;
                accountInfo[1] = GetAttributes(nc, Const.USER_NAME);//账户名称
                accountInfo[2] = GetAttributes(nc, Const.USER_COMP);//公司
                accountInfo[3] = GetAttributes(nc, Const.USER_DEP);//部门
                loginNameList.Add(accountInfo);
            }
            return loginNameList;
        }
        /// <summary>
        /// 创建,添加,修改某参数(包括创建,删除用户)
        /// </summary>
        /// <returns></returns>
        public bool CreateParaConfig(string operation, string login, string Parameter, string Value)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME);
                XmlNode node = doc.FirstChild;
                XmlNode root = doc.FirstChild;
                XmlElement elem;
                string xpath = "descendant::" + login;
                node = root.SelectSingleNode(xpath);

                if (operation == Const.OPERATION_DELETE)
                {
                    if (node == null)
                    {
                        return false;
                    }
                    else
                    {
                        node.RemoveAll();
                        root.RemoveChild(node);
                        doc.Save(m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME);
                        return true;
                    }
                }
                if (operation == "")
                {
                    if (Parameter == Const.USER_LANGUAGE)
                        m_Language = Value;
                    if (Parameter == Const.USER_RESULT)
                        m_UserResult = Value;
                    if (Parameter == Const.USER_LENGTHUNIT)
                        m_UserLengthUnit = Value;
                    if (Parameter == Const.USER_CLEANUNIT)
                        m_UserCleanUnit = Value;
                    if (Parameter == Const.USER_TEMPUNIT)
                        m_UserTempUnit = Value;
                    if (Parameter == Const.USER_TIMEUNIT)
                        m_UserTimeUnit = Value;
                }
                if (node == null)
                {
                    node = doc.FirstChild;
                    node = node.SelectSingleNode("descendant::" + Const.LOGIN_ADMIN);
                    elem = doc.CreateElement(login);
                    root = node.ParentNode;
                    root.InsertAfter(elem, node);
                }
                node = doc.FirstChild;
                root = node.SelectSingleNode(xpath);

                //添加.修改参数节点
                xpath = "descendant::" + Parameter;
                node = root.SelectSingleNode(xpath);
                if (node == null)
                {
                    elem = doc.CreateElement(Parameter);
                    elem.SetAttribute("Value", Value);
                    root.AppendChild(elem);
                }
                else
                {
                    //修改用户的参数属性
                    node.Attributes["Value"].Value = Value;
                }

                doc.Save(m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME);
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region ChangeUnit
        /// <summary>
        /// 界面储存数据时,转化长度,统一成厘米,1 inch 英寸=2.54 millimetres 厘米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ChangeLUnit(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || value.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                if (m_UserLengthUnit == Const.LENGTHUNIT_IN)
                    returnValue = String.Format("{0:F3}", (2.54 * convertValue));
            }
            return returnValue;
        }
        /// <summary>
        /// 界面读取数据时,根据单位转化长度,1 inch 英寸=2.54 millimetres 厘米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ReChangeLUnit(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || returnValue.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                if (m_UserLengthUnit == Const.LENGTHUNIT_IN)
                    returnValue = String.Format("{0:F3}", (convertValue / 2.54));
            }
            return returnValue;
        }


        

        /// <summary>
        /// 界面储存数据时,转化面积,统一成平方厘米,1 平方英寸=6.4516 平方厘米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ChangeAreaUnit(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || value.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                if (m_UserLengthUnit == Const.LENGTHUNIT_IN)
                    returnValue = String.Format("{0:F3}", (6.4516 * convertValue));
            }
            return returnValue;
        }

        /// <summary>
        /// 界面读取数据时,根据单位转化面积,1 平方英寸=6.4516 平方厘米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ReChangeAreaUnit(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || returnValue.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                if (m_UserLengthUnit == Const.LENGTHUNIT_IN)
                {
                    //returnValue = String.Format("{0:F3}", (convertValue / 6.4516));
                    //Asa,保存的精度不够时,转换英寸会有偏差
                    returnValue = (convertValue / 6.4516).ToString();
                }
            }
            return returnValue;
        }

        /// <summary>
        /// 界面储存数据时,转化面积,统一成平方厘米,1 平方英寸=6.4516 平方厘米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ChangeAreaUnitForAGauge(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || value.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                returnValue = String.Format("{0:F3}", (6.4516 * convertValue));
            }
            return returnValue;
        }

        /// <summary>
        /// 界面读取数据时,根据单位转化面积,1 平方英寸=6.4516 平方厘米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ReChangeAreaUnitForAGauge(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || returnValue.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                returnValue = String.Format("{0:F3}", (convertValue / 6.4516));
            }
            return returnValue;
        }

        /// <summary>
        /// 界面储存数据时,转化时间,统一成秒,1 分 = 60秒
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ChangeTimeUnit(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || value.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                if (m_UserTimeUnit == Const.TIMEUNIT_MIN)
                    returnValue = String.Format("{0:F2}", (60 * convertValue));
            }
            return returnValue;
        }

        /// <summary>
        /// 界面读取数据时,根据单位转化时间,1 分 = 60秒
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ReChangeTimeUnit(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || returnValue.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                if (m_UserTimeUnit == Const.TIMEUNIT_MIN)
                    returnValue = String.Format("{0:F2}", (convertValue / 60));
            }
            return returnValue;
        }

        /// <summary>
        /// 界面储存数据时,转化温度,统一成摄氏温度,C=(F-32)×5/9
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ChangeTempUnit(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || value.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                if (m_UserTempUnit == Const.TEMPUNIT_F)
                    returnValue = String.Format("{0:F2}", ((convertValue - 32) * 5 / 9));
            }
            return returnValue;
        }

        /// <summary>
        /// 界面读取数据时,根据单位转化温度,F=(C×9/5)+32
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string ReChangeTempUnit(string value)
        {
            string returnValue = value;
            double convertValue;
            if (value == null || returnValue.Trim() == "")
            {
                returnValue = "";
            }
            else
            {
                convertValue = Convert.ToDouble(value);
                if (m_UserTempUnit == Const.TEMPUNIT_F)
                    returnValue = String.Format("{0:F2}", ((convertValue * 9 / 5) + 32));
            }
            return returnValue;
        }
        #endregion

        #region 取值
        public string UserName
        {
            get
            {
                return m_UserName;
            }
        }
        public string UserLogin
        {
            get
            {
                return m_UserLogin;
            }
        }
        public string UserComp
        {
            get
            {
                return m_UserComp;
            }
        }
        public string UserDep
        {
            get
            {
                return m_UserDep;
            }
        }
        public string UserPWD
        {
            get
            {
                return m_UserPWD;
            }
        }
        public string UserAuth
        {
            get
            {
                return m_UserAuth;
            }
        }

        #region
        //public string UserResult
        //{
        //    get
        //    {
        //        return m_UserResult;
        //    }
        //}
        //public string UserLengthUnit
        //{
        //    get
        //    {
        //        return m_UserLengthUnit;
        //    }
        //}
        //public string UserCleanUnit
        //{
        //    get
        //    {
        //        return m_UserCleanUnit;
        //    }
        //}
        //public string UserTempUnit
        //{
        //    get
        //    {
        //        return m_UserTempUnit;
        //    }
        //}
        //public string UserTimeUnit
        //{
        //    get
        //    {
        //        return m_UserTimeUnit;
        //    }
        //}
        //public string ParaCleanTroughL
        //{
        //    get
        //    {
        //        return m_ParaCleanTroughL;
        //    }
        //}
        //public string ParaCleanTroughW
        //{
        //    get
        //    {
        //        return m_ParaCleanTroughW;
        //    }
        //}
        //public string ParaPrecision
        //{
        //    get
        //    {
        //        return m_ParaPrecision;
        //    }
        //}
        //public string ParaPort
        //{
        //    get
        //    {
        //        return m_ParaPort;
        //    }
        //}
        //public string ParaConnection
        //{
        //    get
        //    {
        //        return m_ParaConnection;
        //    }
        //}
        //public string ParaAdjustQuotiety
        //{
        //    get
        //    {
        //        return m_ParaAdjustQuotiety;
        //    }
        //}
        //public string ParaWashTime
        //{
        //    get
        //    {
        //        return m_ParaWashTime;
        //    }
        //}
        //public string ParaWashUpperLimit
        //{
        //    get
        //    {
        //        return m_ParaWashUpperLimit;
        //    }
        //}
        //public string ParaVolume
        //{
        //    get
        //    {
        //        return m_ParaVolume;
        //    }
        //}
        //public string ParaKValue
        //{
        //    get
        //    {
        //        return m_ParaKValue;
        //    }
        //}
        //public string ParaDelay1
        //{
        //    get
        //    {
        //        return m_ParaDelay1;
        //    }
        //}
        //public string ParaDelay2
        //{
        //    get
        //    {
        //        return m_ParaDelay2;
        //    }
        //}
        //public string ParaTestMode
        //{
        //    get
        //    {
        //        return m_ParaTestMode;
        //    }
        //}
        //public string ParaIsHeat
        //{
        //    get
        //    {
        //        return m_ParaIsHeat;
        //    }
        //}
        //public string ParaTempStandart
        //{
        //    get
        //    {
        //        return m_ParaTempStandart;
        //    }
        //}
        //public string ParaFiltrateLimit
        //{
        //    get
        //    {
        //        return m_ParaFiltrateLimit;
        //    }
        //}
        //public string ParaInfallMaxLimit
        //{
        //    get
        //    {
        //        return m_ParaInfallMaxLimit;
        //    }
        //}
        //public string ParaInfallMinLimit
        //{
        //    get
        //    {
        //        return m_ParaInfallMinLimit;
        //    }
        //}
        //public string ParaDensityStandard
        //{
        //    get
        //    {
        //        return m_ParaDensityStandard;
        //    }
        //}
        //public string ParaUserLimit
        //{
        //    get
        //    {
        //        return m_ParaUserLimit;
        //    }
        //}
        //public string ParaTestTime
        //{
        //    get
        //    {
        //        return m_ParaTestTime;
        //    }
        //}
        //public string ParaInfallHeigth
        //{
        //    get
        //    {
        //        return m_ParaInfallHeigth;
        //    }
        //}
        //public string ParaTestSolvent
        //{
        //    get
        //    {
        //        return m_ParaTestSolvent;
        //    }
        //}
        //public string ParaReviseType
        //{
        //    get
        //    {
        //        return m_ParaReviseType;
        //    }
        //}
        //public string ParaMIL
        //{
        //    get
        //    {
        //        return m_ParaMIL;
        //    }
        //}
        //public string ParaDEF
        //{
        //    get
        //    {
        //        return m_ParaDEF;
        //    }
        //}
        //public string ParaProduct
        //{
        //    get
        //    {
        //        return m_ParaProduct;
        //    }
        //}
        //public string ParaProductL
        //{
        //    get
        //    {
        //        return m_ParaProductL;
        //    }
        //}
        //public string ParaProductW
        //{
        //    get
        //    {
        //        return m_ParaProductW;
        //    }
        //}
        //public string ParaProductArea
        //{
        //    get
        //    {
        //        return m_ParaProductArea;
        //    }
        //}
        //public string ParaSuggest
        //{
        //    get
        //    {
        //        return m_ParaSuggest;
        //    }
        //}
        #endregion
        #endregion

        #region Remark

        public List<Remark> GetAllRemark(string testDataName)
        {
            List<Remark> listRemark = new List<Remark>();
            try
            {
                string fileName = m_CurrentDirectory + Const.TestDataRemarkRoot + testDataName + "-Remark.xml";
                if (!File.Exists(fileName))
                {
                    return listRemark;
                }
                else
                {
                    Remark _Remark;
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(fileName);

                    XmlNode node = xmlDoc.FirstChild;
                    foreach (XmlNode nc in node.ChildNodes)
                    {
                        string text = GetAttributes(nc, Const.REMARK_TEXT);
                        Color fillColor = System.Drawing.Color.FromArgb(Convert.ToInt32(GetAttributes(nc, Const.REMARK_FillColor)));
                        Color lineColor = System.Drawing.Color.FromArgb(Convert.ToInt32(GetAttributes(nc, Const.REMARK_LineColor)));
                        float rectangleX = (float)Convert.ToDouble(GetAttributes(nc, Const.REMARK_RectangleX));
                        float rectangleY = (float)Convert.ToDouble(GetAttributes(nc, Const.REMARK_RectangleY));
                        float rectangleWidth = (float)Convert.ToDouble(GetAttributes(nc, Const.REMARK_RectangleWidth));
                        float rectangleHeight = (float)Convert.ToDouble(GetAttributes(nc, Const.REMARK_RectangleHeight));
                        float startPointX = (float)Convert.ToDouble(GetAttributes(nc, Const.REMARK_StartPointX));
                        float startPointY = (float)Convert.ToDouble(GetAttributes(nc, Const.REMARK_StartPointY));

                        RectangleF rectangle = new RectangleF(rectangleX, rectangleY, rectangleWidth, rectangleHeight);
                        PointF startPoint = new PointF(startPointX, startPointY);
                        _Remark = new Remark(fillColor, lineColor, rectangle, startPoint, text);

                        listRemark.Add(_Remark);
                    }
                    return listRemark;
                }
            }
            catch
            {
                return listRemark;
            }
        }

        public bool ManageRemark(string testDataName, List<Remark> remarkList)
        {
            try
            {
                string fileName = m_CurrentDirectory + Const.TestDataRemarkRoot + testDataName + "-Remark.xml";
                if (!Directory.Exists(m_CurrentDirectory + Const.TestDataRemarkRoot)) //如果不存在就创建文件夹
                {
                    Directory.CreateDirectory(m_CurrentDirectory + Const.TestDataRemarkRoot);
                }
                File.Delete(fileName);

                //创建一个XmlDocument对象
                XmlDocument xmlDoc = new XmlDocument();
                XmlNode xmlNode;
                XmlElement elem;


                //加入一个根元素
                elem = xmlDoc.CreateElement("", Const.Remark + testDataName, "");
                //XmlNode xmltext = xmlDoc.CreateTextNode(product);
                //elem.AppendChild(xmltext);
                xmlDoc.AppendChild(elem);

                XmlNode root = xmlDoc.FirstChild;
                XmlNode rootChild;
                for (int i = 0; i < remarkList.Count; i++)
                {
                    xmlNode = xmlDoc.CreateElement(Const.Remark + i.ToString());
                    root.PrependChild(xmlNode);
                    rootChild = root.SelectSingleNode(Const.Remark + i.ToString());

                    elem = xmlDoc.CreateElement(Const.REMARK_TEXT);
                    elem.SetAttribute("Value", remarkList[i].Text);
                    rootChild.AppendChild(elem);
                    elem = xmlDoc.CreateElement(Const.REMARK_FillColor);
                    elem.SetAttribute("Value", remarkList[i].FillColor.ToArgb().ToString());
                    rootChild.AppendChild(elem);
                    elem = xmlDoc.CreateElement(Const.REMARK_LineColor);
                    elem.SetAttribute("Value", remarkList[i].LineColor.ToArgb().ToString());
                    rootChild.AppendChild(elem);
                    elem = xmlDoc.CreateElement(Const.REMARK_RectangleX);
                    elem.SetAttribute("Value", remarkList[i].Rectangle.X.ToString());
                    rootChild.AppendChild(elem);
                    elem = xmlDoc.CreateElement(Const.REMARK_RectangleY);
                    elem.SetAttribute("Value", remarkList[i].Rectangle.Y.ToString());
                    rootChild.AppendChild(elem);
                    elem = xmlDoc.CreateElement(Const.REMARK_RectangleWidth);
                    elem.SetAttribute("Value", remarkList[i].Rectangle.Width.ToString());
                    rootChild.AppendChild(elem);
                    elem = xmlDoc.CreateElement(Const.REMARK_RectangleHeight);
                    elem.SetAttribute("Value", remarkList[i].Rectangle.Height.ToString());
                    rootChild.AppendChild(elem);
                    elem = xmlDoc.CreateElement(Const.REMARK_StartPointX);
                    elem.SetAttribute("Value", remarkList[i].StartPoint.X.ToString());
                    rootChild.AppendChild(elem);
                    elem = xmlDoc.CreateElement(Const.REMARK_StartPointY);
                    elem.SetAttribute("Value", remarkList[i].StartPoint.Y.ToString());
                    rootChild.AppendChild(elem);
                }
                //保存这个文档到文件中
                xmlDoc.Save(fileName);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }

        }

        #endregion

        #region project
        public string GetProductRoot()
        {
            return m_CurrentDirectory + Const.ProductRoot;
        }

        public List<string> GetAllProjectName()
        {
            List<string> listProduct = new List<string>();
            XmlDocument xmlDoc = new XmlDocument();
            string root = m_CurrentDirectory + Const.ProductRoot;
            try
            {
                xmlDoc.Load(root + Const.PRODUCTCONFIGNAME);
            }
            catch
            {
                return listProduct;
            }
            XmlNode node = xmlDoc.FirstChild;
            foreach (XmlNode nc in node.ChildNodes)
            {
                listProduct.Add(nc.Name);
            }
            return listProduct;
        }

        public List<string[]> GetAllProject(string root)
        {
            List<string[]> listProduct = new List<string[]>();
            string[] product;
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.Load(root + Const.PRODUCTCONFIGNAME);
            }
            catch
            {
                return listProduct;
            }
            XmlNode node = xmlDoc.FirstChild;
            foreach (XmlNode nc in node.ChildNodes)
            {
                product = new string[12];
                product[0] = nc.Name;
                product[1] = ReChangeLUnit(GetAttributes(nc, Const.PARA_PRODUCTL)); //产品长度
                product[2] = ReChangeLUnit(GetAttributes(nc, Const.PARA_PRODUCTW));//产品宽度
                product[3] = Convert.ToSingle(ReChangeAreaUnit(GetAttributes(nc, Const.PARA_PRODUCTAREA))).ToString("#0.00");//产品面积
                product[4] = ReChangeLUnit(GetAttributes(nc, Const.PARA_SUGGEST));//建议进水高度

                product[5] = ReChangeTimeUnit(GetAttributes(nc, Const.PARA_TESTTIME)); //测试时间
                product[6] = GetAttributes(nc, Const.PARA_REVISETYPE);//修正类型
                product[7] = Convert.ToSingle(ReChangeAreaUnit(GetAttributes(nc, Const.PARA_MIL))).ToString("#0.00");//MIL
                product[8] = GetAttributes(nc, Const.PARA_DEF);//DEF
                product[9] = ChangeAreaUnit(GetAttributes(nc, Const.PARA_USERLIMIT));//用户极限
                product[10] = ChangeAreaUnit(GetAttributes(nc, Const.PARA_IPC));//IPC
                product[11] = GetAttributes(nc, Const.PARA_NOTES);//产品备注
                listProduct.Add(product);
            }
            return listProduct;
        }
        public MemoryStream GetImage(string fileName)
        {
            System.IO.MemoryStream sm = new MemoryStream();
            try
            {
                string root = GetProductRoot();
                XmlDocument doc = new XmlDocument();
                doc.Load(root + fileName + @"\" + fileName + Const.IMAGE + ".xml");

                XmlNodeList NodeList = doc.GetElementsByTagName(Const.PRO_IMAGE);//得到节点列表
                XmlNode ImageNode = NodeList[0];//得到该节点
                string PicByte = ImageNode.InnerXml;//得到节点内的二进制代码
                byte[] b = Convert.FromBase64String(PicByte);//转化为byte[]
                sm.Write(b, 0, b.Length);//写到流中
            }
            catch { }
            return sm;
        }
        public bool SaveImage(string root, string productName, BinaryReader br)
        {
            try
            {
                int readByte = 0;
                int bytesToRead = 100;

                if (!Directory.Exists(root + productName))//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(root + productName);
                }

                XmlTextWriter xmlTxtWt = new XmlTextWriter(root + productName + @"\" + productName + Const.IMAGE + ".xml", Encoding.UTF8);
                //输出设置代码缩进
                xmlTxtWt.Formatting = Formatting.Indented;
                xmlTxtWt.WriteStartDocument();
                xmlTxtWt.WriteStartElement(productName);//定义命名空间
                xmlTxtWt.WriteStartElement(Const.PRO_IMAGE);            //定义节点
                byte[] base64buffer = new byte[bytesToRead];          //开辟缓冲区
                do
                {
                    readByte = br.Read(base64buffer, 0, bytesToRead);      //将数据读入字节数组
                    xmlTxtWt.WriteBase64(base64buffer, 0, readByte);       //将数组中二进制值编码为Base64并写出到XML文件
                } while (bytesToRead <= readByte);
                xmlTxtWt.WriteEndElement();
                xmlTxtWt.WriteEndElement();
                xmlTxtWt.WriteEndDocument();
                xmlTxtWt.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool ManageProductConfig(string productRoot, string operation, string productName, string Parameter, string Value)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(productRoot + Const.PRODUCTCONFIGNAME);
                XmlNode node = doc.FirstChild;
                XmlNode root = doc.FirstChild;
                XmlElement elem;
                string xpath = "descendant::" + productName;
                node = root.SelectSingleNode(xpath);

                if (operation == Const.OPERATION_DELETE)
                {
                    if (node == null)
                    {
                        return false;
                    }
                    else
                    {
                        node.RemoveAll();
                        root.RemoveChild(node);
                        doc.Save(productRoot + Const.PRODUCTCONFIGNAME);
                    }
                    string imageFile = productRoot + productName;
                    if (Directory.Exists(imageFile))
                    {
                        Directory.Delete(imageFile, true);
                    }
                    return true;

                }

                if (node == null)
                {
                    node = doc.FirstChild;
                    elem = doc.CreateElement(productName);
                    node.AppendChild(elem);
                }
                node = doc.FirstChild;
                root = node.SelectSingleNode(xpath);
                //添加.修改参数节点
                xpath = "descendant::" + Parameter;
                node = root.SelectSingleNode(xpath);
                if (node == null)
                {
                    elem = doc.CreateElement(Parameter);
                    elem.SetAttribute("Value", Value);
                    root.AppendChild(elem);
                }
                else
                {
                    //修改用户的参数属性
                    node.Attributes["Value"].Value = Value;
                }

                doc.Save(productRoot + Const.PRODUCTCONFIGNAME);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool SaveProductTest(string product, string testTime, string directory, string MaxValue, string MinValue)
        {
            try
            {
                string TestFileName = directory.Substring(directory.LastIndexOf("\\") + 1);
                string productroot = m_CurrentDirectory + Const.ProductRoot;
                if (!Directory.Exists(productroot + product))//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(productroot + product);
                }
                string file = productroot + product + @"\" + product + Const.TestData + ".xml";

                //创建一个XmlDocument对象
                XmlDocument xmlDoc = new XmlDocument();
                XmlNode xmlNode;
                XmlElement elem;

                try
                {
                    xmlDoc.Load(file);
                }
                catch
                {
                    //加入一个根元素
                    elem = xmlDoc.CreateElement("", product, "");
                    //XmlNode xmltext = xmlDoc.CreateTextNode(product);
                    //elem.AppendChild(xmltext);
                    xmlDoc.AppendChild(elem);
                }

                XmlNode root = xmlDoc.FirstChild;
                xmlNode = root.SelectSingleNode(Const.TestData + TestFileName);
                if (xmlNode == null)
                {
                    xmlNode = xmlDoc.CreateElement(Const.TestData + TestFileName);
                    root.PrependChild(xmlNode);
                }
                root = root.SelectSingleNode(Const.TestData + TestFileName);
                xmlNode = root.SelectSingleNode(Const.TEST_STARTTIME);
                if (xmlNode == null)
                {
                    elem = xmlDoc.CreateElement(Const.TEST_STARTTIME);
                    elem.SetAttribute("Value", testTime);
                    root.AppendChild(elem);
                }
                else
                {
                    xmlNode.Attributes["Value"].Value = testTime;
                }
                xmlNode = root.SelectSingleNode(Const.TEST_MAX);
                if (xmlNode == null)
                {
                    elem = xmlDoc.CreateElement(Const.TEST_MAX);
                    elem.SetAttribute("Value", MaxValue);
                    root.AppendChild(elem);
                }
                else
                {
                    xmlNode.Attributes["Value"].Value = MaxValue;
                }
                xmlNode = root.SelectSingleNode(Const.TEST_MIN);
                if (xmlNode == null)
                {
                    elem = xmlDoc.CreateElement(Const.TEST_MIN);
                    elem.SetAttribute("Value", MinValue);
                    root.AppendChild(elem);
                }
                else
                {
                    xmlNode.Attributes["Value"].Value = MinValue;
                }

                //保存这个文档到文件中
                xmlDoc.Save(file);
                return true;

            }
            catch
            {
                return false;
            }
        }

        public DataTable GetProductTest(string product)
        {
            DataTable table1 = new DataTable(Const.PARA_PRODUCT);
            DataColumnCollection columns = table1.Columns;
            columns.Add(Const.TestData, typeof(System.String));
            columns.Add(Const.PARA_PRODUCT, typeof(System.String));
            columns.Add(Const.TEST_STARTTIME, typeof(System.DateTime));
            columns.Add(Const.TEST_MAX, typeof(System.Double));
            columns.Add(Const.TEST_MIN, typeof(System.Double));
            DataRow newRow;
            string productroot = m_CurrentDirectory + Const.ProductRoot;

            string file = productroot + product + @"\" + product + Const.TestData + ".xml";
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.Load(file);
            }
            catch
            {
                return table1;
            }
            XmlNode node = xmlDoc.FirstChild;
            foreach (XmlNode nc in node.ChildNodes)
            {
                newRow = table1.NewRow();
                newRow[Const.TestData] = nc.Name.Substring(8);
                newRow[Const.PARA_PRODUCT] = product;
                try
                {
                    newRow[Const.TEST_STARTTIME] = Convert.ToDateTime(Convert.ToDateTime(GetAttributes(nc, Const.TEST_STARTTIME)).ToShortDateString());
                }
                catch
                {
                    newRow[Const.TEST_STARTTIME] = DateTime.Now;
                }
                //newRow[Const.TEST_STARTTIME] = Convert.ToDateTime(GetAttributes(nc, Const.TEST_STARTTIME)).ToShortDateString();
                try
                {
                    newRow[Const.TEST_MAX] = Convert.ToDouble(GetAttributes(nc, Const.TEST_MAX));
                }
                catch
                {
                    newRow[Const.TEST_MAX] = 0;
                }
                try
                {
                    newRow[Const.TEST_MIN] = Convert.ToDouble(GetAttributes(nc, Const.TEST_MIN));
                }
                catch
                {
                    newRow[Const.TEST_MIN] = 0;
                }
                table1.Rows.Add(newRow);
            }
            return table1;
        }

        public void CopyProductFile(string newRoot)
        {
            if (newRoot.LastIndexOf(@"\") + 1 != newRoot.Length)
            {
                newRoot = newRoot + @"\";
            }
            string oldRoot = m_CurrentDirectory + Const.ProductRoot;
            string[] files = Directory.GetFiles(oldRoot);
            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i].Substring(files[i].LastIndexOf(@"\") + 1);
                File.Copy(files[i], newRoot + file, true);
            }
            string[] directories = Directory.GetDirectories(oldRoot);
            for (int i = 0; i < directories.Length; i++)
            {
                string directory = directories[i].Substring(directories[i].LastIndexOf(@"\") + 1);
                if (!Directory.Exists(newRoot + directory))//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(newRoot + directory);
                }
                string[] childFiles = Directory.GetFiles(oldRoot + directory + @"\");
                for (int j = 0; j < childFiles.Length; j++)
                {
                    string childFile = childFiles[j].Substring(childFiles[j].LastIndexOf(@"\") + 1);
                    File.Copy(childFiles[j], newRoot + directory + @"\" + childFile, true);
                }
            }

        }
        #endregion

        public string[] GetGaugeData()
        {
            string LoginName = Fuction.m_UserLogin;
            string[] gaugeData = new string[9];
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(m_CurrentDirectory + Const.ParameterRoot + Const.PARAMETERCONFIGNAME);
            XmlNode node = xmlDoc.FirstChild;
            XmlNode root = xmlDoc.FirstChild;

            string xpath = "descendant::" + LoginName;
            root = node.SelectSingleNode(xpath);
            if (root != null)
            {
                gaugeData[0] = GetAttributes(root, Const.GAUGE_MINVALUE); //最小值
                gaugeData[1] = GetAttributes(root, Const.GAUGE_MAXVALUE); //最大值
                gaugeData[2] = GetAttributes(root, Const.GAUGE_MINSCALE); //刻度
                gaugeData[3] = GetAttributes(root, Const.GAUGE_GREEN_MINVALUE); //绿色区域最小值
                gaugeData[4] = GetAttributes(root, Const.GAUGE_GREEN_MAXVALUE); //绿色区域最大值
                gaugeData[5] = GetAttributes(root, Const.GAUGE_YELLOW_MINVALUE); //黄色区域最小值
                gaugeData[6] = GetAttributes(root, Const.GAUGE_YELLOW_MAXVALUE); //黄色区域最大值
                gaugeData[7] = GetAttributes(root, Const.GAUGE_RED_MINVALUE); //红色区域最小值
                gaugeData[8] = GetAttributes(root, Const.GAUGE_RED_MAXVALUE); //红色区域最大值
            }
            return gaugeData;
        }

        #region 读取,保存测试数据
        /// <summary>
        /// 保存测试数据
        /// </summary>
        /// <param name="XMLFile">路径</param>
        /// <param name="NodeType">节点类型</param>
        /// <param name="SaveValue">数值</param>
        public void SaveXmlStr(string XMLFile, string NodeType, string SaveValue)// , string NodeValue)
        {
            //创建一个XmlDocument对象
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode xmlNode;
            XmlElement elem;

            try
            {
                xmlDoc.Load(XMLFile);
            }
            catch
            {
                //加入一个根元素
                elem = xmlDoc.CreateElement("", Const.TEST_RESULT, "");
                XmlNode xmltext = xmlDoc.CreateTextNode(Const.TEST_RESULT);
                elem.AppendChild(xmltext);
                xmlDoc.AppendChild(elem);
            }

            XmlNode root = xmlDoc.FirstChild;
            xmlNode = root.SelectSingleNode(NodeType);
            if (xmlNode == null)
            {
                elem = xmlDoc.CreateElement(NodeType);
                elem.SetAttribute("Value", SaveValue);
                root.AppendChild(elem);
            }
            else
            {
                xmlNode.Attributes["Value"].Value = SaveValue;
            }

            //保存这个文档到文件中
            xmlDoc.Save(XMLFile);
        }
        /// <summary>
        /// 读取测试数据
        /// </summary>
        /// <param name="XMLFile">指定目录下</param>
        /// <returns></returns>
        public string GetTestData(string XMLFile, string NodeValue)
        {
            string listData = "";
            XmlNodeReader reader = null;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                // 装入指定的XML文档
                xmlDoc.Load(XMLFile);
                XmlNode root = xmlDoc.FirstChild;

                XmlNode node = root.SelectSingleNode(NodeValue);
                if (node != null)
                {
                    listData = node.Attributes["Value"].Value;
                }
            }
            finally
            {
                //清除打开的数据流
                if (reader != null)
                    reader.Close();
            }
            return listData;

        }
        #endregion

        #region 读取,保存校准系数/校准结果
        /// <summary>
        /// 保存校准系数/校准结果
        /// </summary>
        /// <param name="XMLFile">路径</param>
        /// <param name="SaveName">保存的文件名称</param>
        /// <param name="NodeStr">需要保存的数据列表</param>
        public bool SaveXmlAdjust(string XMLFile, string SaveName, string[,] NodeStr)// , string NodeValue)
        {
            try
            {
                //创建一个XmlDocument对象
                XmlDocument xmlDoc = new XmlDocument();

                //XmlNode xmlnode = xmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
                //xmlDoc.AppendChild(xmlnode);
                //加入一个根元素
                XmlElement elem;
                elem = xmlDoc.CreateElement("", SaveName, "");
                XmlNode xmltext = xmlDoc.CreateTextNode(SaveName);
                elem.AppendChild(xmltext);
                xmlDoc.AppendChild(elem);
                //加入另外一个元素

                XmlNode root = xmlDoc.FirstChild;
                int rowCount = NodeStr.Length;
                for (int i = 0; i < rowCount / 2; i++)
                {
                    elem = xmlDoc.CreateElement(NodeStr[i, 0]);
                    elem.SetAttribute("Value", NodeStr[i, 1]);
                    root.AppendChild(elem);
                }
                //保存这个文档到文件中
                xmlDoc.Save(XMLFile);
                //doc.Save("data.xml");
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 读取校准系数
        /// </summary>
        /// <param name="XMLFile">指定目录下</param>
        /// <returns></returns>
        public string[] ReadXmlAdjust(string XMLFile)// , string NodeValue)
        {
            string[] listData = new string[16];
            XmlNodeReader reader = null;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                // 装入指定的XML文档
                xmlDoc.Load(XMLFile);
                XmlNode node = xmlDoc.FirstChild;

                listData[0] = GetAttributes(node, Const.PARA_ADJUSTQUOTIETY);
                listData[1] = GetAttributes(node, Const.PARA_WASHTIME);
                listData[2] = GetAttributes(node, Const.PARA_WASHUPPERLIMIT);
                listData[3] = GetAttributes(node, Const.PARA_KVALUE);
                listData[4] = GetAttributes(node, Const.PARA_K75);
                listData[5] = GetAttributes(node, Const.PARA_K50);
                listData[6] = GetAttributes(node, Const.PARA_EC1);
                listData[7] = GetAttributes(node, Const.PARA_EC2);
                listData[8] = GetAttributes(node, Const.PARA_ECName1);
                listData[9] = GetAttributes(node, Const.PARA_ECName2);
                listData[10] = GetAttributes(node, Const.PARA_AdjustingTime);
                listData[11] = GetAttributes(node, Const.PARA_ErrorRang);
                listData[12] = GetAttributes(node, Const.PARA_Solution);
                listData[13] = GetAttributes(node, Const.PARA_MachineModel);
                listData[14] = GetAttributes(node, Const.PARA_SERIALNUMBER);
                listData[15] = GetAttributes(node, Const.PARA_CALIBRATIONDATE);
                //listData[8] = GetAttributes(node, Const.PARA_Height);
            }
            finally
            {
                //清除打开的数据流
                if (reader != null)
                    reader.Close();
            }
            return listData;

        }

        /// <summary>
        /// 读取校准结果
        /// </summary>
        /// <param name="XMLFile">指定目录下</param>
        /// <returns></returns>
        public string[] ReadXmlAdjustResult(string XMLFile)// , string NodeValue)
        {
            string[] listData = new string[16];
            XmlNodeReader reader = null;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                // 装入指定的XML文档
                xmlDoc.Load(XMLFile);
                XmlNode node = xmlDoc.FirstChild;

                listData[0] = GetAttributes(node, Const.ADJ_ADJUSTQ);
                listData[1] = GetAttributes(node, Const.ADJ_STEADBOUD);
                listData[2] = GetAttributes(node, Const.ADJ_WTIME);
                listData[3] = GetAttributes(node, Const.ADJ_SOLVENTV);
                listData[4] = GetAttributes(node, Const.ADJ_DENSITY1);
                listData[5] = GetAttributes(node, Const.ADJ_DENSITY2);
                listData[6] = GetAttributes(node, Const.ADJ_DENSITY3);
                listData[7] = GetAttributes(node, Const.ADJ_US1);
                listData[8] = GetAttributes(node, Const.ADJ_US2);
                listData[9] = GetAttributes(node, Const.ADJ_US3);
                listData[10] = GetAttributes(node, Const.ADJ_SER1);
                listData[11] = GetAttributes(node, Const.ADJ_SER2);
                listData[12] = GetAttributes(node, Const.ADJ_SER3);
                listData[13] = GetAttributes(node, Const.ADJ_SS1);
                listData[14] = GetAttributes(node, Const.ADJ_SS2);
                listData[15] = GetAttributes(node, Const.ADJ_SS3);
            }
            finally
            {
                //清除打开的数据流
                if (reader != null)
                    reader.Close();
            }
            return listData;

        }
        #endregion

        #region 数据校验偏差,10位滞后

        public string CorrectData(string CorrectStr)
        {
            string m_CorrectData = CorrectStr;
            string[] tmpArr;
            double[] DataCheck = new double[10];
            int j;
            double DataCheckTotal;

            //暂时取消偏差
            m_CorrectData = CorrectStr;
            return m_CorrectData;

            tmpArr = CorrectStr.Split(',');
            //校验偏差

            if (tmpArr.Length < 10)
                m_CorrectData = CorrectStr;
            return m_CorrectData;
            //小于10S不进行校正

            for (int i = 0; i <= tmpArr.Length - 1; i++)
            {
                for (j = 0; j <= 8; j++)
                {
                    if (i == 0)//第一次队列用第一个值填充
                        DataCheck[j] = Convert.ToDouble(tmpArr[i]);
                    else
                        DataCheck[j] = DataCheck[j + 1];
                }
                DataCheck[9] = Convert.ToDouble(tmpArr[i]);
                DataCheckTotal = 0;
                for (j = 0; j <= 9; j++)
                {
                    DataCheckTotal = DataCheckTotal + DataCheck[j];
                }
                tmpArr[i] = Convert.ToString(DataCheckTotal / 10);
            }
            for (int i = 0; i <= tmpArr.Length - 1; i++)
            {
                m_CorrectData = m_CorrectData + tmpArr[i] + ",";
            }
            return m_CorrectData;
        }
        #endregion
    }
}