/trunk/GenIX/styles/StyleT.cs

http://e12.codeplex.com · C# · 543 lines · 510 code · 23 blank · 10 comment · 28 complexity · 575f0aad3479ca657bf50bde356218c9 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Xml;
  7. using System.IO;
  8. using System.Drawing;
  9. using System.Windows.Forms;
  10. using System.Xml.Linq;
  11. using System.ComponentModel;
  12. namespace GenIX.StyleSpace
  13. {
  14. //<STYLET>Отвечает за Безошибочное преобразование типов</STYLET>
  15. class StyleT
  16. {
  17. public StyleT() : this("Microsoft Sans Serif", "Regular", "Black", "8", "WhiteSmoke") { }
  18. public StyleT(string fontFamalyS, string fontStyleS, string foreColorS, string fontSizeS, string colorS)
  19. {
  20. this.foreColorS = ConvertForeColor(foreColorS);
  21. this.colorS = ConvertColor(colorS);
  22. this.fontSizeS = ConvertFontSize(fontSizeS);
  23. this.fontFamalyS = ConvertFont(fontFamalyS);
  24. this.fontStyleS = ConvertFontStyle(fontStyleS);
  25. this.FontS = new Font(this.fontFamalyS, this.fontSizeS, this.fontStyleS);
  26. this.Err = "";
  27. }
  28. //<TYPE> ТИП ПО УМОЛЧАНИЮ</TYPE>
  29. private string foreColorT = "Black";
  30. private string colorT = "WhiteSmoke";
  31. private string fontSizeT = "8";
  32. private string fontFamalyT = "Microsoft Sans Serif";
  33. private string fontStyleT = "Regular";
  34. public string Err;
  35. public Color foreColorS;
  36. public Color colorS;
  37. public int fontSizeS;
  38. public string fontFamalyS;
  39. public FontStyle fontStyleS;
  40. public Font FontS;
  41. private string ConvertFont(string fontFamalyT)
  42. {
  43. string temp = "";
  44. var query = from table in FontFamily.Families.Where(k => k.Name == fontFamalyT) select new { Name = table.Name };
  45. foreach (var item in query) temp = item.Name;
  46. if (temp != "")
  47. {
  48. this.fontFamalyT = temp;
  49. return this.fontFamalyT;
  50. }
  51. else
  52. {
  53. this.Err += " -ошибка преобразования текста в тип шрифт\r\n";
  54. }
  55. return this.fontFamalyT;
  56. }
  57. private FontStyle ConvertFontStyle(string fontStyleT)
  58. {
  59. try
  60. {
  61. FontStyle temp = (FontStyle)TypeDescriptor.GetConverter(fontStyleS).ConvertFrom(fontStyleT);
  62. this.fontStyleT = fontStyleT;
  63. return temp;
  64. }
  65. catch
  66. {
  67. this.Err += " -ошибка преобразования текста в тип стиль шрифта\r\n";
  68. }
  69. return ConvertFontStyle(this.fontStyleT);
  70. }
  71. private int ConvertFontSize(string fontSizeT)
  72. {
  73. try
  74. {
  75. int temp = Int32.Parse(fontSizeT);
  76. this.fontSizeT = fontSizeT;
  77. return temp;
  78. }
  79. catch
  80. {
  81. this.Err += " -ошибка преобразования текста в тип число\r\n";
  82. MessageBox.Show("err");
  83. }
  84. return ConvertFontSize(this.fontSizeT);
  85. }
  86. private Color ConvertColor(string colorT)
  87. {
  88. ColorConverter convert = new ColorConverter();
  89. try
  90. {
  91. Color temp = ((Color)convert.ConvertFrom(colorT));
  92. this.colorT = colorT;
  93. return temp;
  94. }
  95. catch
  96. {
  97. this.Err += " -ошибка преобразования текста в тип цвет фона\r\n";
  98. MessageBox.Show("err");
  99. }
  100. return ConvertColor(this.colorT);
  101. }
  102. private Color ConvertForeColor(string foreColorT)
  103. {
  104. ColorConverter convert = new ColorConverter();
  105. try
  106. {
  107. Color temp = ((Color)convert.ConvertFrom(foreColorT));
  108. this.foreColorT = foreColorT;
  109. return temp;
  110. }
  111. catch
  112. {
  113. this.Err += " -ошибка преобразования текста в тип цвет шрифта\r\n";
  114. MessageBox.Show("err");
  115. }
  116. return ConvertColor(this.foreColorT);
  117. }
  118. public string FontFamalyT
  119. {
  120. get { return fontFamalyT; }
  121. set
  122. {
  123. this.fontFamalyS = ConvertFont(value);
  124. this.FontS = new Font(this.fontFamalyS, this.fontSizeS, this.fontStyleS);
  125. }
  126. }
  127. public string FontStyleT
  128. {
  129. get { return fontStyleT; }
  130. set
  131. {
  132. this.fontStyleS = ConvertFontStyle(value);
  133. this.FontS = new Font(this.fontFamalyS, this.fontSizeS, this.fontStyleS);
  134. }
  135. }
  136. public string FontSizeT
  137. {
  138. get { return fontSizeT; }
  139. set
  140. {
  141. this.fontSizeS = ConvertFontSize(value);
  142. this.FontS = new Font(this.fontFamalyS, this.fontSizeS, this.fontStyleS);
  143. }
  144. }
  145. public string ColorT
  146. {
  147. get { return colorT; }
  148. set
  149. {
  150. this.colorS = ConvertColor(value);
  151. }
  152. }
  153. public string ForeColorT
  154. {
  155. get { return foreColorT; }
  156. set
  157. {
  158. this.foreColorS = ConvertForeColor(value);
  159. }
  160. }
  161. }
  162. class SButton : StyleT
  163. {
  164. public SButton() : base() { }
  165. public SButton(string fontFamalyS, string fontStyleS, string foreColorS, string fontSizeS, string colorS)
  166. : base("Microsoft Sans Serif", "Regular", "Black", "8", "WhiteSmoke")
  167. {
  168. }
  169. public bool check = false;
  170. public static SButton ReadElement(IEnumerable<XElement> queryStyle, string nameStyle)
  171. {
  172. var queryElement = from table in
  173. queryStyle.Elements("Sbutton")
  174. // <GET_STRUCT>получаем структуру элемента</GET_STRUCT>
  175. select table;
  176. SButton tempOBJ = new SButton();
  177. tempOBJ.Err += "-элемент стиля:Sbutton\n\r";
  178. string str = "";
  179. // <CYCLE>так как элементов типа Sbutton может быть более чем 1 проходим циклам</CYCLE>
  180. foreach (var elements in queryElement)
  181. {
  182. tempOBJ.check = true;
  183. XElement element = (XElement)elements;
  184. //<FIRST_NODE> получаем первый узел конкретной структуры </FIRST_NODE>
  185. XNode node = element.FirstNode;
  186. while (node != null)
  187. {
  188. //<IS_NODE> если узел есть элемент то бегаем по свойствам </IS_NODE>
  189. if (node.NodeType == XmlNodeType.Element)
  190. {
  191. XElement property = (XElement)node;
  192. str = property.Name.ToString();
  193. switch (str)
  194. {
  195. case "color":
  196. tempOBJ.ColorT = property.Value;
  197. break;
  198. case "font":
  199. tempOBJ.FontFamalyT = property.Value;
  200. break;
  201. case "fontSize":
  202. tempOBJ.FontSizeT = property.Value;
  203. break;
  204. case "foreColor":
  205. tempOBJ.ForeColorT = property.Value;
  206. break;
  207. case "fontStyle":
  208. tempOBJ.FontStyleT = property.Value;
  209. break;
  210. default:
  211. break;
  212. }
  213. }
  214. node = node.NextNode;
  215. }
  216. }
  217. return tempOBJ;
  218. }
  219. public Button ConvertToButton(Button bt)
  220. {
  221. bool currE = bt.Enabled;
  222. bt.Enabled = true;
  223. bt.BackColor = this.colorS;
  224. bt.Font = this.FontS;
  225. bt.ForeColor = this.foreColorS;
  226. bt.Enabled = currE;
  227. return bt;
  228. }
  229. }
  230. class SForm : StyleT
  231. {
  232. public SForm() : base() { }
  233. public SForm(string fontFamalyS, string fontStyleS, string foreColorS, string fontSizeS, string colorS)
  234. : base("Microsoft Sans Serif", "Regular", "Black", "8", "WhiteSmoke")
  235. {
  236. }
  237. public bool check = false;
  238. public static SForm ReadElement(IEnumerable<XElement> queryStyle, string nameStyle)
  239. {
  240. //<GET_QUERY> получаем конкретный стиль</GET_QUERY>
  241. var queryElement = from table in
  242. queryStyle.Elements("Sform")
  243. //<GET_EL_STRUCT> получаем структуру элемента</GET_EL_STRUCT>
  244. select table;
  245. SForm tempOBJ = new SForm();
  246. tempOBJ.Err += "-элемент стиля:Sform\n\r";
  247. string str = "";
  248. //<MORE_SB> так как элемента типа Sbutton могут быть более чем 1 проходим циклам</MORE_SB>
  249. foreach (var elements in queryElement)
  250. {
  251. tempOBJ.check = true;
  252. XElement element = (XElement)elements;
  253. //<FIRST_NODE> получаем первый узел конкретной структуры </FIRST_NODE>
  254. XNode node = element.FirstNode;
  255. while (node != null)
  256. {
  257. if (node.NodeType == XmlNodeType.Element)
  258. {
  259. XElement property = (XElement)node;
  260. str = property.Name.ToString();
  261. switch (str)
  262. {
  263. case "color":
  264. tempOBJ.ColorT = property.Value;
  265. break;
  266. case "font":
  267. tempOBJ.FontFamalyT = property.Value;
  268. break;
  269. case "fontSize":
  270. tempOBJ.FontSizeT = property.Value;
  271. break;
  272. case "foreColor":
  273. tempOBJ.ForeColorT = property.Value;
  274. break;
  275. case "fontStyle":
  276. tempOBJ.FontStyleT = property.Value;
  277. break;
  278. default:
  279. break;
  280. }
  281. }
  282. node = node.NextNode;
  283. }
  284. }
  285. return tempOBJ;
  286. }
  287. public Form ConvertToForm(Form fr)
  288. {
  289. bool currE = fr.Enabled;
  290. fr.Enabled = true;
  291. fr.BackColor = this.colorS;
  292. fr.Font = this.FontS;
  293. fr.ForeColor = this.foreColorS;
  294. fr.Enabled = currE;
  295. return fr;
  296. }
  297. }
  298. class SEdit : StyleT
  299. {
  300. public SEdit() : base() { }
  301. public SEdit(string fontFamalyS, string fontStyleS, string foreColorS, string fontSizeS, string colorS)
  302. : base("Microsoft Sans Serif", "Regular", "Black", "8", "WhiteSmoke")
  303. {
  304. }
  305. public bool check = false;
  306. public static SEdit ReadElement(IEnumerable<XElement> queryStyle, string nameStyle)
  307. {
  308. var queryElement = from table in
  309. queryStyle.Elements("Sedit")
  310. select table;
  311. SEdit tempOBJ = new SEdit();
  312. tempOBJ.Err += "-элемент стиля:Sedit\n\r";
  313. string str = "";
  314. foreach (var elements in queryElement)
  315. {
  316. tempOBJ.check = true;
  317. XElement element = (XElement)elements;
  318. XNode node = element.FirstNode;
  319. while (node != null)
  320. {
  321. if (node.NodeType == XmlNodeType.Element)
  322. {
  323. XElement property = (XElement)node;
  324. str = property.Name.ToString();
  325. switch (str)
  326. {
  327. case "color":
  328. tempOBJ.ColorT = property.Value;
  329. break;
  330. case "font":
  331. tempOBJ.FontFamalyT = property.Value;
  332. break;
  333. case "fontSize":
  334. tempOBJ.FontSizeT = property.Value;
  335. break;
  336. case "foreColor":
  337. tempOBJ.ForeColorT = property.Value;
  338. break;
  339. case "fontStyle":
  340. tempOBJ.FontStyleT = property.Value;
  341. break;
  342. default:
  343. break;
  344. }
  345. }
  346. node = node.NextNode;
  347. }
  348. }
  349. return tempOBJ;
  350. }
  351. public TextBox ConvertToTextBox(TextBox tb)
  352. {
  353. bool currE = tb.Enabled;
  354. tb.Enabled = true;
  355. tb.BackColor = this.colorS;
  356. tb.Font = this.FontS;
  357. tb.ForeColor = this.foreColorS;
  358. tb.Enabled = currE;
  359. return tb;
  360. }
  361. public ComboBox ConvertToTextBox(ComboBox tb)
  362. {
  363. bool currE = tb.Enabled;
  364. tb.Enabled = true;
  365. tb.BackColor = this.colorS;
  366. tb.Font = this.FontS;
  367. tb.ForeColor = this.foreColorS;
  368. tb.Enabled = currE;
  369. return tb;
  370. }
  371. public MaskedTextBox ConvertToTextBox(MaskedTextBox tb)
  372. {
  373. bool currE = tb.Enabled;
  374. tb.Enabled = true;
  375. tb.BackColor = this.colorS;
  376. tb.Font = this.FontS;
  377. tb.ForeColor = this.foreColorS;
  378. tb.Enabled = currE;
  379. return tb;
  380. }
  381. public DateTimePicker ConvertToDateTimePicker(DateTimePicker tb)
  382. {
  383. bool currE = tb.Enabled;
  384. tb.Enabled = true;
  385. tb.BackColor = this.colorS;
  386. tb.Font = this.FontS;
  387. tb.ForeColor = this.foreColorS;
  388. tb.Enabled = currE;
  389. return tb;
  390. }
  391. }
  392. class SMenu : StyleT
  393. {
  394. public SMenu() : base() { }
  395. public SMenu(string fontFamalyS, string fontStyleS, string foreColorS, string fontSizeS, string colorS)
  396. : base("Microsoft Sans Serif", "Regular", "Black", "8", "WhiteSmoke")
  397. {
  398. }
  399. public bool check = false;
  400. public static SMenu ReadElement(IEnumerable<XElement> queryStyle, string nameStyle)
  401. {
  402. var queryElement = from table in
  403. queryStyle.Elements("Smenu")
  404. select table;
  405. SMenu tempOBJ = new SMenu();
  406. tempOBJ.Err += "-элемент стиля:Smenu\n\r";
  407. string str = "";
  408. foreach (var elements in queryElement)
  409. {
  410. tempOBJ.check = true;
  411. XElement element = (XElement)elements;
  412. XNode node = element.FirstNode;
  413. while (node != null)
  414. {
  415. if (node.NodeType == XmlNodeType.Element)
  416. {
  417. XElement property = (XElement)node;
  418. str = property.Name.ToString();
  419. switch (str)
  420. {
  421. case "color":
  422. tempOBJ.ColorT = property.Value;
  423. break;
  424. case "font":
  425. tempOBJ.FontFamalyT = property.Value;
  426. break;
  427. case "fontSize":
  428. tempOBJ.FontSizeT = property.Value;
  429. break;
  430. case "foreColor":
  431. tempOBJ.ForeColorT = property.Value;
  432. break;
  433. case "fontStyle":
  434. tempOBJ.FontStyleT = property.Value;
  435. break;
  436. default:
  437. break;
  438. }
  439. }
  440. node = node.NextNode;
  441. }
  442. }
  443. return tempOBJ;
  444. }
  445. public MenuStrip ConvertToMenu(MenuStrip mn)
  446. {
  447. bool currE = mn.Enabled;
  448. mn.Enabled = true;
  449. mn.BackColor = this.colorS;
  450. mn.Font = this.FontS;
  451. mn.ForeColor = this.foreColorS;
  452. mn.Enabled = currE;
  453. return mn;
  454. }
  455. }
  456. class SLabel : StyleT
  457. {
  458. public SLabel() : base() { }
  459. public SLabel(string fontFamalyS, string fontStyleS, string foreColorS, string fontSizeS, string colorS)
  460. : base("Microsoft Sans Serif", "Regular", "Black", "8", "WhiteSmoke")
  461. {
  462. }
  463. public bool check = false;
  464. public static SLabel ReadElement(IEnumerable<XElement> queryStyle, string nameStyle)
  465. {
  466. var queryElement = from table in
  467. queryStyle.Elements("Slabel")
  468. select table;
  469. SLabel tempOBJ = new SLabel();
  470. tempOBJ.Err += "-элемент стиля:Slabel\n\r";
  471. string str = "";
  472. foreach (var elements in queryElement)
  473. {
  474. tempOBJ.check = true;
  475. XElement element = (XElement)elements;
  476. XNode node = element.FirstNode;
  477. while (node != null)
  478. {
  479. if (node.NodeType == XmlNodeType.Element)
  480. {
  481. XElement property = (XElement)node;
  482. str = property.Name.ToString();
  483. switch (str)
  484. {
  485. case "color":
  486. tempOBJ.ColorT = property.Value;
  487. break;
  488. case "font":
  489. tempOBJ.FontFamalyT = property.Value;
  490. break;
  491. case "fontSize":
  492. tempOBJ.FontSizeT = property.Value;
  493. break;
  494. case "foreColor":
  495. tempOBJ.ForeColorT = property.Value;
  496. break;
  497. case "fontStyle":
  498. tempOBJ.FontStyleT = property.Value;
  499. break;
  500. default:
  501. break;
  502. }
  503. }
  504. node = node.NextNode;
  505. }
  506. }
  507. return tempOBJ;
  508. }
  509. public Label ConvertToLabel(Label lb)
  510. {
  511. bool currE = lb.Enabled;
  512. lb.Enabled = true;
  513. lb.BackColor = this.colorS;
  514. lb.Font = this.FontS;
  515. lb.ForeColor = this.foreColorS;
  516. lb.Enabled = currE;
  517. return lb;
  518. }
  519. }
  520. }