PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/LDAPOfficeTool/Org2DisplayUniversal.cs

#
C# | 314 lines | 264 code | 36 blank | 14 comment | 35 complexity | 274c24584a2b1512122514c9f88fad14 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LDAPOfficeTool
  10. {
  11. public partial class Org2DisplayUniversal : UserControl
  12. {
  13. LDAPServiceNS.OrganisationBean Org2Display;
  14. string OuTop;
  15. Microsoft.Office.Interop.Word.Document Doc2Handle; // handle to document to be processed
  16. const int ExpandedHeightLimit = 115;
  17. const int ContractedHeightLimit = 48;
  18. // auf welche länge wird der Name für die Ausgabe in die Minimaske abgeschnitten
  19. const int MaxNameLengthLimit = 33;
  20. bool PhysicalAddressExists()
  21. {
  22. if (Org2Display.gvPhysicalAddress != null)
  23. {
  24. return true;
  25. }
  26. return false;
  27. }
  28. string GetPhysicalAddress()
  29. {
  30. string RetVal;
  31. string[] AddressArr;
  32. AddressArr = Org2Display.gvPhysicalAddress.Split('$');
  33. // org2Display.postal
  34. RetVal = AddressArr[0] + ", ";
  35. for (int i = 1; i < AddressArr.Length; i++)
  36. {
  37. RetVal = RetVal + AddressArr[i];
  38. }
  39. return RetVal;
  40. }
  41. bool PostalAddressExists()
  42. {
  43. if (Org2Display.postalAddress != null)
  44. {
  45. return true;
  46. }
  47. return false;
  48. }
  49. string GetPostalAddress()
  50. {
  51. string RetVal;
  52. string[] AddressArr;
  53. AddressArr = Org2Display.postalAddress.Split('$');
  54. RetVal = AddressArr[0];
  55. for (int i = 1; i < AddressArr.Length; i++)
  56. {
  57. RetVal = RetVal + ", " + AddressArr[i];
  58. }
  59. return RetVal;
  60. }
  61. string GetPostalAddressX()
  62. {
  63. string RetVal;
  64. string []AddressArr;
  65. RetVal = "?";
  66. if (Org2Display.gvPhysicalAddress != null)
  67. {
  68. AddressArr = Org2Display.gvPhysicalAddress.Split('$');
  69. RetVal = "PH: " + StringUtils.StringStorage2StringWithDelimiter(AddressArr, " ");
  70. }
  71. else
  72. {
  73. if (Org2Display.postalAddress != null)
  74. {
  75. AddressArr = Org2Display.postalAddress.Split('$');
  76. RetVal = "PO: " + StringUtils.StringStorage2StringWithDelimiter(AddressArr, " ");
  77. }
  78. else
  79. {
  80. MessageBox.Show("Nothing at all of address for organisation");
  81. RetVal = " - ";
  82. }
  83. }
  84. return RetVal;
  85. }
  86. public string GetOrgDescription()
  87. {
  88. string RetVal;
  89. string DiagnosticsTxt;
  90. if (Org2Display.description != null)
  91. {
  92. DiagnosticsTxt = "Getting org description, data length: " + Org2Display.description.Length.ToString();
  93. for (int i =0; i < Org2Display.description.Length; i++)
  94. {
  95. DiagnosticsTxt = DiagnosticsTxt + Environment.NewLine + i.ToString () + ": " + Org2Display.description[i];
  96. }
  97. RetVal = StringUtils.StringStorage2String(Org2Display.description);
  98. }
  99. else
  100. {
  101. RetVal = "-";
  102. }
  103. return RetVal;
  104. }
  105. public Org2DisplayUniversal(LDAPServiceNS.OrganisationBean pOrg, string psOuTop, Microsoft.Office.Interop.Word.Document pdoc2Handle)
  106. {
  107. InitializeComponent();
  108. Org2Display = pOrg;
  109. OuTop = psOuTop;
  110. lblEmail.Text = Org2Display.mail;
  111. bool CommonNameSet;
  112. CommonNameSet = false;
  113. // BBB09 take care of gvcn
  114. if (Org2Display.gvCn != null)
  115. {
  116. if (Org2Display.gvCn.Length > 0)
  117. {
  118. // use it now
  119. CommonNameSet = true;
  120. linklblLDAP.Text = StringUtils.CutOffWithTail(Org2Display.gvCn, "...", MaxNameLengthLimit);
  121. }
  122. }
  123. if (!CommonNameSet)
  124. {
  125. // set it as usual
  126. linklblLDAP.Text = StringUtils.CutOffWithTail(Org2Display.cn[0], "...", MaxNameLengthLimit);
  127. }
  128. // BBB09
  129. if (PhysicalAddressExists())
  130. {
  131. lblAddress.Text = GetPhysicalAddress();
  132. toolTipAddress.SetToolTip(lblAddress, "Besuchsadresse");
  133. }
  134. else
  135. {
  136. if (PostalAddressExists())
  137. {
  138. lblAddress.Text = GetPostalAddress();
  139. toolTipAddress.SetToolTip(lblAddress, "Postanschrift");
  140. }
  141. else
  142. {
  143. lblAddress.Text = "-";
  144. toolTipAddress.SetToolTip(lblAddress, "weder Besuchadresse noch Postanschrift vorhanden");
  145. }
  146. }
  147. lblMainOrg.Text = OuTop;
  148. Doc2Handle = pdoc2Handle;
  149. btnExpand.Visible = true;
  150. btnContract.Visible = false;
  151. this.Height = ContractedHeightLimit;
  152. }
  153. private void btnExpand_Click(object sender, EventArgs e)
  154. {
  155. this.Height = ExpandedHeightLimit;
  156. btnContract.Visible = true;
  157. btnExpand.Visible = false;
  158. btnEinfuegen.Visible = true;
  159. // MessageBox.Show("Text: " + this.subBrowser.DocumentText);
  160. }
  161. private void btnContract_Click(object sender, EventArgs e)
  162. {
  163. this.Height = ContractedHeightLimit;
  164. btnContract.Visible = false;
  165. btnExpand.Visible = true;
  166. btnEinfuegen.Visible = false;
  167. }
  168. private void eMailAdresseToolStripMenuItem_Click(object sender, EventArgs e)
  169. {
  170. Microsoft.Office.Interop.Word.Selection CurrentDocSelection;
  171. CurrentDocSelection = Doc2Handle.Application.Selection;
  172. CurrentDocSelection.TypeText(Org2Display.mail);
  173. }
  174. private void linklblLDAP_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  175. {
  176. string Link2Open;
  177. BrowserForm Org2LDAP;
  178. Org2LDAP = new BrowserForm();
  179. Link2Open = "http://ldap.gv.at/lfrz.at/ldapw/index.php?sPage=1&showDetailDn=" + Org2Display.dn + "&detailType=organisation";
  180. Org2LDAP.SetUri(Link2Open);
  181. Org2LDAP.Visible = true;
  182. // MessageBox.Show("link: " + sLink2Open);
  183. }
  184. private void orgEinheitToolStripMenuItem_Click(object sender, EventArgs e)
  185. {
  186. string Text2Enter;
  187. Text2Enter = "";
  188. // 2011.06.29 gerold sagt, gvCn hat vorrang vorm cn; wenn leer, dann cn nehmen
  189. if (Org2Display.gvCn != null)
  190. {
  191. if (Org2Display.gvCn.Length > 0)
  192. {
  193. Text2Enter = Org2Display.gvCn;
  194. }
  195. }
  196. if (Text2Enter.Length == 0)
  197. {
  198. Text2Enter = StringUtils.StringStorage2String(Org2Display.cn);
  199. }
  200. Microsoft.Office.Interop.Word.Selection CurrentDocSelection;
  201. CurrentDocSelection = Doc2Handle.Application.Selection;
  202. CurrentDocSelection.TypeText(Text2Enter);
  203. }
  204. private void aufgabeToolStripMenuItem_Click(object sender, EventArgs e)
  205. {
  206. string Text2Enter;
  207. Text2Enter = GetOrgDescription();
  208. Microsoft.Office.Interop.Word.Selection CurrentDocSelection;
  209. CurrentDocSelection = Doc2Handle.Application.Selection;
  210. CurrentDocSelection.TypeText(Text2Enter);
  211. }
  212. private void btnEinfuegen_Click(object sender, EventArgs e)
  213. {
  214. Point AuxPoint;
  215. AuxPoint = new Point(5, 5);
  216. contextMenuStripOActions.Show(btnEinfuegen, AuxPoint);
  217. }
  218. private void ouBezeichnung_Click(object sender, EventArgs e)
  219. {
  220. string Text2Enter;
  221. //
  222. Text2Enter = StringUtils.StringStorage2String(Org2Display.cn);
  223. Microsoft.Office.Interop.Word.Selection Selection;
  224. Selection = Doc2Handle.Application.Selection;
  225. Selection.TypeText(Text2Enter);
  226. }
  227. private void anschriftMenuStripMenuItem_Click(object sender, EventArgs e)
  228. {
  229. bool Found;
  230. string Text2Enter;
  231. string AddressCandidate;
  232. AddressCandidate = "";
  233. Found = false;
  234. //
  235. if (PostalAddressExists())
  236. {
  237. AddressCandidate = GetPostalAddress();
  238. if (AddressCandidate.Length > 4)
  239. {
  240. Found = true;
  241. }
  242. }
  243. if (!Found)
  244. {
  245. if (PhysicalAddressExists())
  246. {
  247. AddressCandidate = GetPhysicalAddress();
  248. if (AddressCandidate.Length > 4)
  249. {
  250. Found = true;
  251. }
  252. }
  253. }
  254. if (Found)
  255. {
  256. // 2011.06.29 gerold hat gemerkt, dass manche Adressen verkehrt sind; falsches Attrib verwendet
  257. // Text2Enter = StringUtils.StringStorage2String(Org2Display.cn) + Environment.NewLine + AddressCandidate;
  258. Text2Enter = "";
  259. if (Org2Display.gvCn != null)
  260. {
  261. if (Org2Display.gvCn.Length > 0)
  262. {
  263. Text2Enter = Org2Display.gvCn;
  264. }
  265. }
  266. if (Text2Enter.Length == 0)
  267. {
  268. Text2Enter = StringUtils.StringStorage2String(Org2Display.cn);
  269. }
  270. Text2Enter = Text2Enter +Environment.NewLine + AddressCandidate;
  271. Microsoft.Office.Interop.Word.Selection vSelection;
  272. // org2Display.
  273. vSelection = Doc2Handle.Application.Selection;
  274. vSelection.TypeText(Text2Enter);
  275. }
  276. }
  277. }
  278. }