PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/LDAPOfficeTool/Person2DisplayUniversal.cs

#
C# | 309 lines | 260 code | 35 blank | 14 comment | 29 complexity | 5928e19febe49e6b4e8977f7b6968a7e 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 Person2DisplayUniversal : UserControl
  12. {
  13. bool Initialized; // if the initialization was well done
  14. string MainOrg;
  15. string MainOrgKurzBez;
  16. LDAPServiceNS.PersonBean PersBean;
  17. LDAPServiceNS.OrganisationBean[] OrgBeanArr;
  18. LDAPServiceNS.LdapGvAtQueryClient LdapClient;
  19. Microsoft.Office.Interop.Word.Document Doc2Handle;
  20. const int ContractedHeightLimit = 46;
  21. const int ExpandedHeightLimit = 129;
  22. const int MaxNameLengthLimit = 36;
  23. const int LblOrgTooltipMinLenLimit = 42;
  24. string GetPersonNameWithTitle()
  25. {
  26. string RetVal;
  27. RetVal = "";
  28. if (PersBean.personalTitle != null)
  29. {
  30. if (PersBean.personalTitle.Length > 0)
  31. {
  32. RetVal = PersBean.personalTitle + " ";
  33. }
  34. }
  35. RetVal = RetVal + PersBean.givenName + " " + PersBean.sn;
  36. if (PersBean.gvIntTitle != null)
  37. {
  38. RetVal = RetVal + ", " + PersBean.gvIntTitle;
  39. }
  40. return RetVal;
  41. }
  42. // 2011.04.14 Bobic
  43. // mail from Pesendorfer, at Addresat passiert nix beim Einfügen -> actually, it was a catch
  44. string GetPersonPostalAddress()
  45. {
  46. string RetVal;
  47. RetVal = "";
  48. string [] AddressPartArr;
  49. if (PersBean.postalAddress != null)
  50. {
  51. if (PersBean.postalAddress.Length > 0)
  52. {
  53. AddressPartArr = PersBean.postalAddress.Split('$');
  54. RetVal = AddressPartArr[0] + ",";
  55. for (int i = 1; i < AddressPartArr.Length; i++)
  56. {
  57. RetVal = RetVal + " " + AddressPartArr[i];
  58. }
  59. }
  60. else
  61. {
  62. RetVal = "-0-";
  63. }
  64. }
  65. else
  66. {
  67. RetVal = "- adresse nicht vorhanden -";
  68. }
  69. return RetVal;
  70. }
  71. string GetPersonOrg()
  72. {
  73. string RetVal;
  74. RetVal = "";
  75. bool gvCnExists;
  76. gvCnExists = false;
  77. if (PersBean != null)
  78. {
  79. // sRetVal = torgBean[0].ou + ", " + torgBean[0].cn[0];
  80. if (OrgBeanArr.Length > 1)
  81. {
  82. RetVal = "> org ";
  83. }
  84. // 2011.06.29 correction
  85. if (OrgBeanArr[0].gvCn != null)
  86. {
  87. if (OrgBeanArr[0].gvCn.Length > 0)
  88. {
  89. RetVal = RetVal + OrgBeanArr[0].gvCn;
  90. gvCnExists = true;
  91. }
  92. }
  93. if (!gvCnExists)
  94. {
  95. RetVal = RetVal + StringUtils.StringStorage2String(OrgBeanArr[0].cn);
  96. }
  97. }
  98. else
  99. {
  100. RetVal = "org ?";
  101. }
  102. return RetVal;
  103. }
  104. string GetPersonEMail()
  105. {
  106. string RetVal = "";
  107. if (PersBean.mail.Length > 0)
  108. {
  109. RetVal = PersBean.mail.ToLower ();
  110. }
  111. else
  112. {
  113. RetVal = "keine E-Mail Adresse";
  114. }
  115. return RetVal;
  116. }
  117. string GetPersonPhone()
  118. {
  119. string RetVal;
  120. RetVal = "";
  121. if (PersBean.telefoneNumber != null)
  122. {
  123. RetVal = StringUtils.StringTable2OneLine(PersBean.telefoneNumber, ',');
  124. }
  125. else
  126. {
  127. RetVal = "keine Telefonnummer";
  128. }
  129. return RetVal;
  130. }
  131. public Person2DisplayUniversal(LDAPServiceNS.PersonBean pPerson, string psMainOrg, string psMainOrgKurzBez, Microsoft.Office.Interop.Word.Document pdoc2Handle)
  132. {
  133. InitializeComponent();
  134. PersBean = pPerson;
  135. // correct person's email address to lower
  136. if (PersBean.mail != null)
  137. {
  138. PersBean.mail = PersBean.mail.ToLower();
  139. }
  140. else
  141. {
  142. PersBean.mail = "";
  143. }
  144. MainOrg = psMainOrg;
  145. MainOrgKurzBez = psMainOrgKurzBez;
  146. Initialized = false;
  147. linklblLDAP.Text = StringUtils.CutOffWithTail(GetPersonNameWithTitle(), "...", MaxNameLengthLimit);
  148. lblEMail.Text = GetPersonEMail ();
  149. lblPhone.Text = GetPersonPhone();
  150. lblMainOrg.Text = MainOrgKurzBez;
  151. this.Height = ContractedHeightLimit;
  152. Doc2Handle = pdoc2Handle;
  153. btnExpand.Visible = true;
  154. btnContract.Visible = false;
  155. }
  156. private void btnExpand_Click(object sender, EventArgs e)
  157. {
  158. // MessageBox.Show("Einfugen loc: " + btnEinfuegen.Location.ToString() + " exp.heicht: " + ciExpandedHeight.ToString());
  159. if (!Initialized)
  160. {
  161. LdapClient = new LDAPServiceNS.LdapGvAtQueryClient();
  162. // BBB09
  163. OrgBeanArr = LdapClient.findOrganizationsBy(null, PersBean.gvOu[0], null, null, null, null, null, false, true, 10);
  164. // the old method took 9 arguments, removed on 2011.02.09
  165. // torgBean = ldapClient.findOrganizationsBy(null, personBean.gvOu[0], null, null, null, null, false, true, 10);
  166. lblOrg.Text = GetPersonOrg();
  167. if (lblOrg.Text.Length > LblOrgTooltipMinLenLimit)
  168. {
  169. toolTipOrgLabel.SetToolTip(lblOrg, lblOrg.Text);
  170. lblOrg.Text = GetPersonOrg().Substring(0, LblOrgTooltipMinLenLimit) + "...";
  171. }
  172. Initialized = true;
  173. LdapClient.Close();
  174. }
  175. this.Height = ExpandedHeightLimit;
  176. btnExpand.Visible = false;
  177. btnContract.Visible = true;
  178. btnEinfuegen.Visible = true;
  179. // MessageBox.Show("Einfugen loc: " + btnEinfuegen.Location.ToString() + " exp.heicht: " + ciExpandedHeight.ToString());
  180. }
  181. private void btnContract_Click(object sender, EventArgs e)
  182. {
  183. btnExpand.Visible = true;
  184. btnContract.Visible = false;
  185. this.Height = ContractedHeightLimit;
  186. btnEinfuegen.Visible = false;
  187. }
  188. private void linklblLDAP_MouseClick(object sender, MouseEventArgs e)
  189. {
  190. BrowserForm Person2LDAP;
  191. Person2LDAP = new BrowserForm();
  192. string Link2Open;
  193. Link2Open = "http://ldap.gv.at/lfrz.at/ldapw/index.php?sPage=1&showDetailDn=" + PersBean.dn + "&detailType=person";
  194. Person2LDAP.SetUri(Link2Open);
  195. Person2LDAP.Visible = true;
  196. }
  197. private void lblEMail_Click(object sender, EventArgs e)
  198. {
  199. System.Diagnostics.Process.Start("mailto:" + PersBean.mail);
  200. }
  201. #region BLOCK_EINFUEGEN
  202. private void btnEinfuegen_Click(object sender, EventArgs e)
  203. {
  204. Point AuxPoint;
  205. AuxPoint = new Point(5, 5);
  206. contextMenuStripPActions.Show(btnEinfuegen, AuxPoint);
  207. }
  208. private void nameToolStripMenuItem_Click(object sender, EventArgs e)
  209. {
  210. Microsoft.Office.Interop.Word.Selection Selection;
  211. Selection = Doc2Handle.Application.Selection;
  212. Selection.TypeText(GetPersonNameWithTitle() + " ");
  213. }
  214. private void telefonnummerToolStripMenuItem_Click(object sender, EventArgs e)
  215. {
  216. Microsoft.Office.Interop.Word.Selection Selection;
  217. if (PersBean.telefoneNumber != null)
  218. {
  219. Selection = Doc2Handle.Application.Selection;
  220. Selection.TypeText(GetPersonPhone());
  221. }
  222. else
  223. {
  224. MessageBox.Show("Keine Telefonnummer");
  225. }
  226. }
  227. // called by Einfügen -> Adressat
  228. private void adressatToolStripMenuItem_Click(object sender, EventArgs e)
  229. {
  230. string Text2Insert;
  231. try
  232. {
  233. Text2Insert = MainOrg + Environment.NewLine;
  234. Text2Insert = Text2Insert + "z.H. " + GetPersonNameWithTitle() + Environment.NewLine;
  235. // 2011.06.29 gerold correction
  236. // Text2Insert = Text2Insert + OrgBeanArr[0].cn[0] + Environment.NewLine;
  237. Text2Insert = Text2Insert + GetPersonOrg() + Environment.NewLine;
  238. Text2Insert = Text2Insert + GetPersonPostalAddress() + Environment.NewLine;
  239. if (PersBean.telefoneNumber != null)
  240. {
  241. Text2Insert = Text2Insert + "Tel: " + GetPersonPhone() + Environment.NewLine;
  242. }
  243. Text2Insert = Text2Insert + PersBean.mail + Environment.NewLine;
  244. // person2Display.g
  245. Microsoft.Office.Interop.Word.Selection Selection;
  246. Selection = Doc2Handle.Application.Selection;
  247. Selection.TypeText(Text2Insert);
  248. }
  249. catch (Exception exAddresat)
  250. {
  251. MessageBox.Show("Exception at Adressat einfügen: " + Environment.NewLine + exAddresat.Message);
  252. }
  253. }
  254. private void AnschriftToolStripMenuItem_Click(object sender, EventArgs e)
  255. {
  256. string Text2Enter;
  257. string[] AddressPartsArr;
  258. Microsoft.Office.Interop.Word.Selection Selection;
  259. if (PersBean.postalAddress != null)
  260. {
  261. AddressPartsArr = PersBean.postalAddress.Split('$');
  262. Text2Enter = GetPersonNameWithTitle() + Environment.NewLine;
  263. Text2Enter = Text2Enter + GetPersonPostalAddress();
  264. Selection = Doc2Handle.Application.Selection;
  265. Selection.TypeText(Text2Enter);
  266. }
  267. else
  268. {
  269. MessageBox.Show("Adresse ist nicht verfügbar");
  270. }
  271. }
  272. #endregion
  273. }
  274. }