Variable.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. /**
  2. *
  3. * @author seagle
  4. * @date 2024-7-10
  5. * @Description 处理变量的相关计算
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace MECF.Framework.UI.Core.DxfScript
  13. {
  14. public enum VariableDataType{
  15. DOUBLE,STRING,BOOL
  16. }
  17. public class Variable
  18. {
  19. private string _stringValue;
  20. public string StringValue
  21. {
  22. get
  23. {
  24. if (Name != null && !Name.Equals(""))
  25. {
  26. //刷新io值
  27. _stringValue = ScriptVariables.GetStringByName(Name);
  28. IsNone = false;
  29. }
  30. return _stringValue;
  31. }
  32. set
  33. {
  34. if (DataType != VariableDataType.STRING)
  35. {
  36. throw new Exception("Variable " + Name + " DataType is not STRING");
  37. }
  38. _stringValue = value;
  39. if (Name != null && !Name.Equals(""))
  40. {
  41. //刷新io值
  42. ScriptVariables.SetStringByName(Name, _stringValue);
  43. }
  44. IsNone = false;
  45. }
  46. }
  47. private double _doubleValue;
  48. public double DoubleValue
  49. {
  50. get
  51. {
  52. if (Name != null && !Name.Equals(""))
  53. {
  54. //刷新io值
  55. _doubleValue = ScriptVariables.GetDoubleByName(Name);
  56. IsNone = false;
  57. }
  58. return _doubleValue;
  59. }
  60. set
  61. {
  62. if (DataType != VariableDataType.DOUBLE)
  63. {
  64. throw new Exception("Variable " + Name + " DataType is not DOUBLE");
  65. }
  66. _doubleValue = value;
  67. if (Name != null && !Name.Equals(""))
  68. {
  69. //刷新io值
  70. ScriptVariables.SetDoubleByName(Name, _doubleValue);
  71. }
  72. IsNone = false;
  73. }
  74. }
  75. public bool _boolValue;
  76. public bool BoolValue
  77. {
  78. get
  79. {
  80. if (Name != null && !Name.Equals(""))
  81. {
  82. //刷新io值
  83. _boolValue = ScriptVariables.GetBoolByName(Name);
  84. IsNone = false;
  85. }
  86. return _boolValue;
  87. }
  88. set
  89. {
  90. if (DataType != VariableDataType.BOOL)
  91. {
  92. throw new Exception("Variable " + Name + "DataType is not BOOL");
  93. }
  94. _boolValue = value;
  95. if (Name != null && !Name.Equals(""))
  96. {
  97. ScriptVariables.SetBoolByName(Name, _boolValue);
  98. //刷新io值
  99. }
  100. IsNone = false;
  101. }
  102. }
  103. public string Name { get; set; }
  104. public bool IsNone { get; set;}
  105. public VariableDataType DataType { get; set; }
  106. public Variable(string name, VariableDataType dataType)
  107. {
  108. Name = name;
  109. DataType = dataType;
  110. if (name == null || name.Equals(""))
  111. {
  112. IsNone = true;
  113. }
  114. else
  115. {
  116. //有名字的变量都来自外部,有值
  117. IsNone = false;
  118. }
  119. }
  120. //从参数变量中复制内容
  121. public void CopyFrom(Variable v,bool OnlyCheckDataType=false)
  122. {
  123. if (v == null )
  124. {
  125. throw new Exception("Variable " + Name + " can not copy from null");
  126. }
  127. if(v.IsNone && !OnlyCheckDataType)
  128. {
  129. throw new Exception("Variable " + v.Name + " is none and can not copy");
  130. }
  131. if (Name == null || Name.Equals(""))
  132. {
  133. //无Name的变量可以认为是临时变量,可以随意复制
  134. DataType = v.DataType;
  135. if (OnlyCheckDataType) return;
  136. }
  137. if (DataType != v.DataType)
  138. {
  139. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  140. }
  141. switch (DataType)
  142. {
  143. case VariableDataType.BOOL:
  144. BoolValue = v.BoolValue;
  145. break;
  146. case VariableDataType.DOUBLE:
  147. DoubleValue = v.DoubleValue;
  148. break;
  149. case VariableDataType.STRING:
  150. StringValue = v.StringValue;
  151. break;
  152. }
  153. IsNone = false;
  154. }
  155. //逗号连接参数
  156. public void Comma(Variable other, bool onlyCheckDataType)
  157. {
  158. if (onlyCheckDataType)
  159. {
  160. // 如果只检查数据类型,可以在这里实现相应的逻辑
  161. return;
  162. }
  163. // 逗号拼接逻辑:将当前值与其他值拼接成字符串
  164. if (this.StringValue == null)
  165. {
  166. this.StringValue = other.StringValue?.ToString();
  167. }
  168. else
  169. {
  170. this.StringValue = this.StringValue.ToString() + "," + other.StringValue?.ToString();
  171. }
  172. }
  173. //与参数变量相加
  174. public void Plus(Variable v, bool OnlyCheckDataType = false)
  175. {
  176. if (v == null)
  177. {
  178. throw new Exception("Variable " + Name + " can not plus from null");
  179. }
  180. if (v.IsNone && !OnlyCheckDataType)
  181. {
  182. throw new Exception("Variable " + v.Name + " is none and can not plus");
  183. }
  184. if (IsNone && !OnlyCheckDataType)
  185. {
  186. throw new Exception("Variable " + Name + " is none and can not plus others");
  187. }
  188. if (DataType != v.DataType)
  189. {
  190. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  191. }
  192. if (OnlyCheckDataType)
  193. {
  194. if(DataType== VariableDataType.DOUBLE || DataType == VariableDataType.STRING)
  195. {
  196. return;
  197. }
  198. else
  199. {
  200. throw new Exception("Variable " + Name + "'s DataType is not supported to plus");
  201. }
  202. }
  203. switch (DataType)
  204. {
  205. case VariableDataType.DOUBLE:
  206. DoubleValue += v.DoubleValue;
  207. break;
  208. case VariableDataType.STRING:
  209. StringValue += v.StringValue;
  210. break;
  211. default:
  212. throw new Exception("Variable " + Name + "'s DataType is not supported to plus");
  213. }
  214. }
  215. //与参数变量相减:当前-参数
  216. public void Minus(Variable v, bool OnlyCheckDataType = false)
  217. {
  218. if (v == null)
  219. {
  220. throw new Exception("Variable " + Name + " can not minus from null");
  221. }
  222. if (v.IsNone && !OnlyCheckDataType)
  223. {
  224. throw new Exception("Variable " + v.Name + " is none and can not minus");
  225. }
  226. if (IsNone && !OnlyCheckDataType)
  227. {
  228. throw new Exception("Variable " + Name + " is none and can not minus others");
  229. }
  230. if (DataType != v.DataType)
  231. {
  232. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  233. }
  234. if (OnlyCheckDataType)
  235. {
  236. if (DataType == VariableDataType.DOUBLE)
  237. {
  238. return;
  239. }
  240. else
  241. {
  242. throw new Exception("Variable " + Name + "'s DataType is not supported to minus");
  243. }
  244. }
  245. switch (DataType)
  246. {
  247. case VariableDataType.DOUBLE:
  248. DoubleValue -= v.DoubleValue;
  249. break;
  250. default:
  251. throw new Exception("Variable " + Name + "'s DataType is not supported to minus");
  252. }
  253. }
  254. //与参数变量相乘
  255. public void Multiple(Variable v, bool OnlyCheckDataType = false)
  256. {
  257. if (v == null)
  258. {
  259. throw new Exception("Variable " + Name + " can not multiple from null");
  260. }
  261. if (v.IsNone && !OnlyCheckDataType)
  262. {
  263. throw new Exception("Variable " + v.Name + " is none and can not multiple");
  264. }
  265. if (IsNone && !OnlyCheckDataType)
  266. {
  267. throw new Exception("Variable " + Name + " is none and can not multiple others");
  268. }
  269. if (DataType != v.DataType)
  270. {
  271. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  272. }
  273. if (OnlyCheckDataType)
  274. {
  275. if(DataType== VariableDataType.DOUBLE )
  276. {
  277. return;
  278. }
  279. else
  280. {
  281. throw new Exception("Variable " + Name + "'s DataType is not supported to multiple");
  282. }
  283. }
  284. switch (DataType)
  285. {
  286. case VariableDataType.DOUBLE:
  287. DoubleValue *= v.DoubleValue;
  288. break;
  289. default:
  290. throw new Exception("Variable " + Name + "'s DataType is not supported to multiple");
  291. }
  292. }
  293. //与参数变量相除
  294. public void Devide(Variable v, bool OnlyCheckDataType = false)
  295. {
  296. if (v == null)
  297. {
  298. throw new Exception("Variable " + Name + " can not devide from null");
  299. }
  300. if (v.IsNone && !OnlyCheckDataType)
  301. {
  302. throw new Exception("Variable " + v.Name + " is none and can not devide");
  303. }
  304. if (IsNone && !OnlyCheckDataType)
  305. {
  306. throw new Exception("Variable " + Name + " is none and can not devide others");
  307. }
  308. if (DataType != v.DataType)
  309. {
  310. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  311. }
  312. if (OnlyCheckDataType)
  313. {
  314. if (DataType == VariableDataType.DOUBLE )
  315. {
  316. return;
  317. }
  318. else
  319. {
  320. throw new Exception("Variable " + Name + "'s DataType is not supported to devide");
  321. }
  322. }
  323. switch (DataType)
  324. {
  325. case VariableDataType.DOUBLE:
  326. DoubleValue /= v.DoubleValue;
  327. break;
  328. default:
  329. throw new Exception("Variable " + Name + "'s DataType is not supported to devide");
  330. }
  331. }
  332. //与参数变量相与
  333. public void And(Variable v, bool OnlyCheckDataType = false)
  334. {
  335. if (v == null)
  336. {
  337. throw new Exception("Variable " + Name + " can not and from null");
  338. }
  339. if (v.IsNone && !OnlyCheckDataType)
  340. {
  341. throw new Exception("Variable " + v.Name + " is none and can not and");
  342. }
  343. if (IsNone && !OnlyCheckDataType)
  344. {
  345. throw new Exception("Variable " + Name + " is none and can not and others");
  346. }
  347. if (DataType != v.DataType)
  348. {
  349. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  350. }
  351. if (OnlyCheckDataType)
  352. {
  353. if (DataType == VariableDataType.BOOL)
  354. {
  355. return;
  356. }
  357. else
  358. {
  359. throw new Exception("Variable " + Name + "'s DataType is not supported to and");
  360. }
  361. }
  362. switch (DataType)
  363. {
  364. case VariableDataType.BOOL:
  365. BoolValue = BoolValue && v.BoolValue;
  366. break;
  367. default:
  368. throw new Exception("Variable " + Name + "'s DataType is not supported to and");
  369. }
  370. }
  371. //与参数变量相或
  372. public void Or(Variable v, bool OnlyCheckDataType = false)
  373. {
  374. if (v == null)
  375. {
  376. throw new Exception("Variable " + Name + " can not OR from null");
  377. }
  378. if (v.IsNone && !OnlyCheckDataType)
  379. {
  380. throw new Exception("Variable " + v.Name + " is none and can not OR");
  381. }
  382. if (IsNone && !OnlyCheckDataType)
  383. {
  384. throw new Exception("Variable " + Name + " is none and can not OR others");
  385. }
  386. if (DataType != v.DataType)
  387. {
  388. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  389. }
  390. if (OnlyCheckDataType)
  391. {
  392. if (DataType == VariableDataType.BOOL)
  393. {
  394. return;
  395. }
  396. else
  397. {
  398. throw new Exception("Variable " + Name + "'s DataType is not supported to OR");
  399. }
  400. }
  401. switch (DataType)
  402. {
  403. case VariableDataType.BOOL:
  404. BoolValue = BoolValue || v.BoolValue;
  405. break;
  406. default:
  407. throw new Exception("Variable " + Name + "'s DataType is not supported to OR");
  408. }
  409. }
  410. //单目求非
  411. public void Not( bool OnlyCheckDataType = false)
  412. {
  413. if (IsNone && !OnlyCheckDataType)
  414. {
  415. throw new Exception("Variable " + Name + " is none and can not NOT others");
  416. }
  417. if (OnlyCheckDataType)
  418. {
  419. if (DataType == VariableDataType.BOOL)
  420. {
  421. return;
  422. }
  423. else
  424. {
  425. throw new Exception("Variable " + Name + "'s DataType is not supported to NOT");
  426. }
  427. }
  428. switch (DataType)
  429. {
  430. case VariableDataType.BOOL:
  431. BoolValue = !BoolValue;
  432. break;
  433. default:
  434. throw new Exception("Variable " + Name + "'s DataType is not supported to NOT");
  435. }
  436. }
  437. //与参数变量相等判断
  438. public void Equal(Variable v, bool OnlyCheckDataType = false)
  439. {
  440. if (v == null)
  441. {
  442. throw new Exception("Variable " + Name + " can not equal from null");
  443. }
  444. if (v.IsNone && !OnlyCheckDataType)
  445. {
  446. throw new Exception("Variable " + v.Name + " is none and can not equal");
  447. }
  448. if (IsNone && !OnlyCheckDataType)
  449. {
  450. throw new Exception("Variable " + Name + " is none and can not equal others");
  451. }
  452. if (DataType != v.DataType)
  453. {
  454. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  455. }
  456. if (OnlyCheckDataType)
  457. {
  458. return;
  459. }
  460. switch (DataType)
  461. {
  462. case VariableDataType.DOUBLE:
  463. DataType = VariableDataType.BOOL;
  464. BoolValue = Math.Abs(DoubleValue - v.DoubleValue) <= 0.0000001;
  465. break;
  466. case VariableDataType.STRING:
  467. DataType = VariableDataType.BOOL;
  468. if (StringValue == null || v.StringValue == null)
  469. {
  470. BoolValue = false;
  471. }
  472. else
  473. {
  474. BoolValue = StringValue.Equals(v.StringValue);
  475. }
  476. break;
  477. case VariableDataType.BOOL:
  478. BoolValue = BoolValue == v.BoolValue;
  479. break;
  480. default:
  481. throw new Exception("Variable " + Name + "'s DataType is not supported to equal");
  482. }
  483. }
  484. //与参数变量不等判断
  485. public void NotEqual(Variable v, bool OnlyCheckDataType = false)
  486. {
  487. if (v == null)
  488. {
  489. throw new Exception("Variable " + Name + " can not not_equal from null");
  490. }
  491. if (v.IsNone && !OnlyCheckDataType)
  492. {
  493. throw new Exception("Variable " + v.Name + " is none and can not not_equal");
  494. }
  495. if (IsNone && !OnlyCheckDataType)
  496. {
  497. throw new Exception("Variable " + Name + " is none and can not not_equal others");
  498. }
  499. if (DataType != v.DataType)
  500. {
  501. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  502. }
  503. if (OnlyCheckDataType)
  504. {
  505. return;
  506. }
  507. switch (DataType)
  508. {
  509. case VariableDataType.DOUBLE:
  510. DataType = VariableDataType.BOOL;
  511. BoolValue = Math.Abs(DoubleValue - v.DoubleValue) > 0.0000001;
  512. break;
  513. case VariableDataType.STRING:
  514. DataType = VariableDataType.BOOL;
  515. if (StringValue == null || v.StringValue == null)
  516. {
  517. BoolValue = true;
  518. }
  519. else
  520. {
  521. BoolValue = !StringValue.Equals(v.StringValue);
  522. }
  523. break;
  524. case VariableDataType.BOOL:
  525. BoolValue = BoolValue != v.BoolValue;
  526. break;
  527. default:
  528. throw new Exception("Variable " + Name + "'s DataType is not supported to not_equal");
  529. }
  530. }
  531. //与参数变量做大于
  532. public void Gt(Variable v, bool OnlyCheckDataType = false)
  533. {
  534. if (v == null)
  535. {
  536. throw new Exception("Variable " + Name + " can not GT from null");
  537. }
  538. if (v.IsNone && !OnlyCheckDataType)
  539. {
  540. throw new Exception("Variable " + v.Name + " is none and can not GT");
  541. }
  542. if (IsNone && !OnlyCheckDataType)
  543. {
  544. throw new Exception("Variable " + Name + " is none and can not GT others");
  545. }
  546. if (DataType != v.DataType)
  547. {
  548. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  549. }
  550. if (OnlyCheckDataType)
  551. {
  552. if(DataType== VariableDataType.DOUBLE ||DataType == VariableDataType.STRING)
  553. {
  554. return;
  555. }
  556. else
  557. {
  558. throw new Exception("Variable " + Name + "'s DataType is not supported to GT");
  559. }
  560. }
  561. switch (DataType)
  562. {
  563. case VariableDataType.DOUBLE:
  564. DataType = VariableDataType.BOOL;
  565. BoolValue = DoubleValue - v.DoubleValue> 0.0000001;
  566. break;
  567. case VariableDataType.STRING:
  568. DataType = VariableDataType.BOOL;
  569. if (StringValue == null || v.StringValue == null)
  570. {
  571. BoolValue = false;
  572. }
  573. else
  574. {
  575. BoolValue = StringValue.CompareTo(v.StringValue) > 0;
  576. }
  577. break;
  578. default:
  579. throw new Exception("Variable " + Name + "'s DataType is not supported to GT");
  580. }
  581. }
  582. //与参数变量做大于等于
  583. public void Ge(Variable v, bool OnlyCheckDataType = false)
  584. {
  585. if (v == null)
  586. {
  587. throw new Exception("Variable " + Name + " can not GE from null");
  588. }
  589. if (v.IsNone && !OnlyCheckDataType)
  590. {
  591. throw new Exception("Variable " + v.Name + " is none and can not GE");
  592. }
  593. if (IsNone && !OnlyCheckDataType)
  594. {
  595. throw new Exception("Variable " + Name + " is none and can not GE others");
  596. }
  597. if (DataType != v.DataType)
  598. {
  599. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  600. }
  601. if (OnlyCheckDataType)
  602. {
  603. if (DataType == VariableDataType.DOUBLE || DataType == VariableDataType.STRING)
  604. {
  605. return;
  606. }
  607. else
  608. {
  609. throw new Exception("Variable " + Name + "'s DataType is not supported to GE");
  610. }
  611. }
  612. switch (DataType)
  613. {
  614. case VariableDataType.DOUBLE:
  615. DataType = VariableDataType.BOOL;
  616. BoolValue = DoubleValue - v.DoubleValue >= -0.0000001;
  617. break;
  618. case VariableDataType.STRING:
  619. DataType = VariableDataType.BOOL;
  620. if (StringValue == null || v.StringValue == null)
  621. {
  622. BoolValue = false;
  623. }
  624. else
  625. {
  626. BoolValue = StringValue.CompareTo(v.StringValue) >= 0;
  627. }
  628. break;
  629. default:
  630. throw new Exception("Variable " + Name + "'s DataType is not supported to GE");
  631. }
  632. }
  633. //与参数变量做小于
  634. public void Lt(Variable v, bool OnlyCheckDataType = false)
  635. {
  636. if (v == null)
  637. {
  638. throw new Exception("Variable " + Name + " can not LT from null");
  639. }
  640. if (v.IsNone && !OnlyCheckDataType)
  641. {
  642. throw new Exception("Variable " + v.Name + " is none and can not LT");
  643. }
  644. if (IsNone && !OnlyCheckDataType)
  645. {
  646. throw new Exception("Variable " + Name + " is none and can not lT others");
  647. }
  648. if (DataType != v.DataType)
  649. {
  650. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  651. }
  652. if (OnlyCheckDataType)
  653. {
  654. if (DataType == VariableDataType.DOUBLE || DataType == VariableDataType.STRING)
  655. {
  656. return;
  657. }
  658. else
  659. {
  660. throw new Exception("Variable " + Name + "'s DataType is not supported to LT");
  661. }
  662. }
  663. switch (DataType)
  664. {
  665. case VariableDataType.DOUBLE:
  666. DataType = VariableDataType.BOOL;
  667. BoolValue = DoubleValue - v.DoubleValue <- 0.0000001;
  668. break;
  669. case VariableDataType.STRING:
  670. DataType = VariableDataType.BOOL;
  671. if (StringValue == null || v.StringValue == null)
  672. {
  673. BoolValue = false;
  674. }
  675. else
  676. {
  677. BoolValue = StringValue.CompareTo(v.StringValue) < 0;
  678. }
  679. break;
  680. default:
  681. throw new Exception("Variable " + Name + "'s DataType is not supported to LT");
  682. }
  683. }
  684. //与参数变量做小于等于
  685. public void Le(Variable v, bool OnlyCheckDataType = false)
  686. {
  687. if (v == null)
  688. {
  689. throw new Exception("Variable " + Name + " can not LE from null");
  690. }
  691. if (v.IsNone && !OnlyCheckDataType)
  692. {
  693. throw new Exception("Variable " + v.Name + " is none and can not LE");
  694. }
  695. if (IsNone && !OnlyCheckDataType)
  696. {
  697. throw new Exception("Variable " + Name + " is none and can not LE others");
  698. }
  699. if (DataType != v.DataType)
  700. {
  701. throw new Exception("Variable " + Name + "'s DataType is not matched with " + v.Name + "'s DataType");
  702. }
  703. if (OnlyCheckDataType)
  704. {
  705. if (DataType == VariableDataType.DOUBLE || DataType == VariableDataType.STRING)
  706. {
  707. return;
  708. }
  709. else
  710. {
  711. throw new Exception("Variable " + Name + "'s DataType is not supported to LE");
  712. }
  713. }
  714. switch (DataType)
  715. {
  716. case VariableDataType.DOUBLE:
  717. DataType = VariableDataType.BOOL;
  718. BoolValue = DoubleValue - v.DoubleValue <= 0.0000001;
  719. break;
  720. case VariableDataType.STRING:
  721. DataType = VariableDataType.BOOL;
  722. if (StringValue == null || v.StringValue == null)
  723. {
  724. BoolValue = false;
  725. }
  726. else
  727. {
  728. BoolValue = StringValue.CompareTo(v.StringValue) <= 0;
  729. }
  730. break;
  731. default:
  732. throw new Exception("Variable " + Name + "'s DataType is not supported to LE");
  733. }
  734. }
  735. //单目取负
  736. public void Nigtive(bool OnlyCheckDataType = false)
  737. {
  738. if (IsNone && !OnlyCheckDataType)
  739. {
  740. throw new Exception("Variable " + Name + " is none and can not Nigtive");
  741. }
  742. if (OnlyCheckDataType)
  743. {
  744. if (DataType == VariableDataType.DOUBLE)
  745. {
  746. return;
  747. }
  748. else
  749. {
  750. throw new Exception("Variable " + Name + "'s DataType is not supported to Nigtive");
  751. }
  752. }
  753. switch (DataType)
  754. {
  755. case VariableDataType.DOUBLE:
  756. DoubleValue = -DoubleValue ;
  757. break;
  758. default:
  759. throw new Exception("Variable " + Name + "'s DataType is not supported to Negtive");
  760. }
  761. }
  762. }
  763. }