using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using GZTW.AyaNova.BLL; using Infragistics.Win; using log4net; namespace AyaNova { /// /// Summary description for ClientSelector. /// public class ClientSelector : System.Windows.Forms.Form { // Create a logger for use in this class //case 1039 private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private System.Windows.Forms.Panel ClientSelector_Fill_Panel; private Infragistics.Win.Misc.UltraButton btnClientID; private GZTW.WinForm.Controls.GZUltraComboEditor cbClientID; private System.Windows.Forms.Button btnOK; private System.Windows.Forms.Button btnCancel; private GZTW.WinForm.Controls.GZUltraComboEditor cbTemplateID; private Infragistics.Win.Misc.UltraLabel lblTemplate; private Button btnSearch; private TextBox edSearch; private System.Windows.Forms.Button btnRefresh; //private System.ComponentModel.IContainer components; public ClientSelector(WorkorderTypes WoType) { // // Required for Windows Form Designer support // InitializeComponent(); woType = WoType; // // // } private WorkorderTypes woType = WorkorderTypes.Unknown; /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { //if (components != null) //{ // components.Dispose(); //} } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { Infragistics.Win.ValueListItem valueListItem1 = new Infragistics.Win.ValueListItem(); Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance(); Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance(); this.ClientSelector_Fill_Panel = new System.Windows.Forms.Panel(); this.edSearch = new System.Windows.Forms.TextBox(); this.btnSearch = new System.Windows.Forms.Button(); this.lblTemplate = new Infragistics.Win.Misc.UltraLabel(); this.cbTemplateID = new GZTW.WinForm.Controls.GZUltraComboEditor(); this.btnRefresh = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button(); this.btnOK = new System.Windows.Forms.Button(); this.cbClientID = new GZTW.WinForm.Controls.GZUltraComboEditor(); this.btnClientID = new Infragistics.Win.Misc.UltraButton(); this.ClientSelector_Fill_Panel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.cbTemplateID)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.cbClientID)).BeginInit(); this.SuspendLayout(); // // ClientSelector_Fill_Panel // this.ClientSelector_Fill_Panel.Controls.Add(this.edSearch); this.ClientSelector_Fill_Panel.Controls.Add(this.btnSearch); this.ClientSelector_Fill_Panel.Controls.Add(this.lblTemplate); this.ClientSelector_Fill_Panel.Controls.Add(this.cbTemplateID); this.ClientSelector_Fill_Panel.Controls.Add(this.btnRefresh); this.ClientSelector_Fill_Panel.Controls.Add(this.btnCancel); this.ClientSelector_Fill_Panel.Controls.Add(this.btnOK); this.ClientSelector_Fill_Panel.Controls.Add(this.cbClientID); this.ClientSelector_Fill_Panel.Controls.Add(this.btnClientID); this.ClientSelector_Fill_Panel.Cursor = System.Windows.Forms.Cursors.Default; this.ClientSelector_Fill_Panel.Dock = System.Windows.Forms.DockStyle.Fill; this.ClientSelector_Fill_Panel.Location = new System.Drawing.Point(0, 0); this.ClientSelector_Fill_Panel.Name = "ClientSelector_Fill_Panel"; this.ClientSelector_Fill_Panel.Size = new System.Drawing.Size(421, 323); this.ClientSelector_Fill_Panel.TabIndex = 0; // // edSearch // this.edSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.edSearch.Location = new System.Drawing.Point(8, 105); this.edSearch.Name = "edSearch"; this.edSearch.Size = new System.Drawing.Size(355, 20); this.edSearch.TabIndex = 1; // // btnSearch // this.btnSearch.Image = global::AyaNova.Resource1.SearchDatabase16; this.btnSearch.Location = new System.Drawing.Point(383, 101); this.btnSearch.Name = "btnSearch"; this.btnSearch.Size = new System.Drawing.Size(28, 26); this.btnSearch.TabIndex = 2; this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); // // lblTemplate // this.lblTemplate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lblTemplate.Location = new System.Drawing.Point(8, 146); this.lblTemplate.Name = "lblTemplate"; this.lblTemplate.Size = new System.Drawing.Size(409, 17); this.lblTemplate.TabIndex = 31; this.lblTemplate.Tag = ""; this.lblTemplate.Text = "LT:O.Region"; this.lblTemplate.WrapText = false; // // cbTemplateID // this.cbTemplateID.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.cbTemplateID.AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend; this.cbTemplateID.Location = new System.Drawing.Point(8, 167); this.cbTemplateID.Name = "cbTemplateID"; this.cbTemplateID.Size = new System.Drawing.Size(403, 21); this.cbTemplateID.TabIndex = 3; // // btnRefresh // this.btnRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnRefresh.Image = global::AyaNova.Resource1.Refresh24; this.btnRefresh.Location = new System.Drawing.Point(179, 277); this.btnRefresh.Name = "btnRefresh"; this.btnRefresh.Size = new System.Drawing.Size(75, 34); this.btnRefresh.TabIndex = 5; this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click); // // btnCancel // this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnCancel.Image = global::AyaNova.Resource1.Cancel24; this.btnCancel.Location = new System.Drawing.Point(8, 276); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 35); this.btnCancel.TabIndex = 4; this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); // // btnOK // this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; this.btnOK.Image = global::AyaNova.Resource1.OK24; this.btnOK.Location = new System.Drawing.Point(337, 276); this.btnOK.Name = "btnOK"; this.btnOK.Size = new System.Drawing.Size(75, 35); this.btnOK.TabIndex = 6; this.btnOK.Click += new System.EventHandler(this.btnOK_Click); // // cbClientID // this.cbClientID.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.cbClientID.AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend; appearance1.BackColor = System.Drawing.SystemColors.GrayText; valueListItem1.Appearance = appearance1; valueListItem1.DataValue = new System.Guid("00000000-0000-0000-0000-000000000000"); valueListItem1.DisplayText = "-"; this.cbClientID.Items.AddRange(new Infragistics.Win.ValueListItem[] { valueListItem1}); this.cbClientID.LimitToList = true; this.cbClientID.Location = new System.Drawing.Point(8, 41); this.cbClientID.Name = "cbClientID"; this.cbClientID.Size = new System.Drawing.Size(403, 21); this.cbClientID.TabIndex = 0; this.cbClientID.Tag = "I AM FROM CLIENTSELECTOR FORM"; this.cbClientID.SelectionChanged += new System.EventHandler(this.cbClientID_SelectionChanged); // // btnClientID // this.btnClientID.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); appearance4.TextHAlignAsString = "Left"; this.btnClientID.Appearance = appearance4; this.btnClientID.ButtonStyle = Infragistics.Win.UIElementButtonStyle.PopupBorderless; this.btnClientID.Location = new System.Drawing.Point(8, 17); this.btnClientID.Name = "btnClientID"; this.btnClientID.Size = new System.Drawing.Size(404, 24); this.btnClientID.TabIndex = 7; this.btnClientID.Tag = ""; this.btnClientID.Text = "LT:O.Client"; this.btnClientID.UseHotTracking = Infragistics.Win.DefaultableBoolean.True; this.btnClientID.Click += new System.EventHandler(this.btnClientID_Click); // // ClientSelector // this.AcceptButton = this.btnOK; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.CancelButton = this.btnCancel; this.ClientSize = new System.Drawing.Size(421, 323); this.Controls.Add(this.ClientSelector_Fill_Panel); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ClientSelector"; this.ShowInTaskbar = false; this.Closing += new System.ComponentModel.CancelEventHandler(this.ClientSelector_Closing); this.Load += new System.EventHandler(this.ClientSelector_Load); this.ClientSelector_Fill_Panel.ResumeLayout(false); this.ClientSelector_Fill_Panel.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.cbTemplateID)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.cbClientID)).EndInit(); this.ResumeLayout(false); } #endregion // __ _ _ ___ ____ __ __ __ __ __ ___ ___ // / _)( )( )/ __)(_ _)/ \( \/ ) / _)/ \( \( _) // ( (_ )()( \__ \ )( ( () )) ( ( (_( () )) ) )) _) // \__) \__/ (___/ (__) \__/(_/\/\_) \__)\__/(___/(___) // #region Global vars / Properties private Guid mSelectedClientID=Guid.Empty; public Guid SelectedClientID { get{ return mSelectedClientID;} set { mSelectedClientID = value; } } private Guid mSelectedTemplateID = Guid.Empty; public Guid SelectedTemplateID { get { return mSelectedTemplateID; } } #endregion #region Load / close events private void ClientSelector_Load(object sender, System.EventArgs e) { //case 1039 //log.Debug("ClientSelector_Load"); this.Icon = Resource1.Client16icon; switch (woType) { case WorkorderTypes.TemplatePreventiveMaintenance: lblTemplate.Text = "LT:O.WorkorderPreventiveMaintenanceTemplate"; break; case WorkorderTypes.TemplateQuote: lblTemplate.Text = "LT:O.WorkorderQuoteTemplate"; break; case WorkorderTypes.TemplateService: lblTemplate.Text = "LT:O.WorkorderServiceTemplate"; break; } Util.Localize(this); //case 1172 lblTemplate.Visible = !AyaBizUtils.Lite; cbTemplateID.Visible = !AyaBizUtils.Lite; cpl = ClientPickList.GetList(true); LoadCombo(); Application.Idle+= new EventHandler(Application_Idle); } private void ClientSelector_Closing(object sender, System.ComponentModel.CancelEventArgs e) { //case 1039 //log.Debug("ClientSelector_Closing"); Application.Idle-= new EventHandler(Application_Idle); if(mSelectedClientID==Guid.Empty) this.DialogResult=DialogResult.Cancel; if(!AyaBizUtils.Lite)//case 1172 mSelectedTemplateID = (Guid)cbTemplateID.SelectedItem.DataValue; } #endregion #region Idle processing private void Application_Idle(object sender, EventArgs e) { // tbManager.Tools["LT:UI.Command.OK"].SharedProps.Enabled= this.btnOK.Enabled=mSelectedClientID!=Guid.Empty; this.btnSearch.Enabled = edSearch.Text.Length > 0; } #endregion #region UI Commands /// /// Load or create client /// /// /// private void btnClientID_Click(object sender, System.EventArgs e) { //case 1039 //log.Debug("btnClientID_Click"); ClientInfoForm cf=new ClientInfoForm(); if(mSelectedClientID!=Guid.Empty) { cf.ClientToEdit=Client.GetItem(mSelectedClientID); } else { if(AyaBizUtils.Right("Object.Client")< (int)SecurityLevelTypes.ReadWrite) { //case 1039 //log.Debug("No Client selected to view and user has no rights to create a new one."); return; } cf.ClientToEdit=Client.NewItem(); } cf.Visible=false; cf.ShowDialog(); if(cf.ChangesMade) { //case 1007 cpl = ClientPickList.GetList(true); LoadCombo(); foreach(ValueListItem vi in cbClientID.Items) { if((Guid)vi.DataValue==cf.ClientToEdit.ID) { cbClientID.SelectedItem=vi; break; } } } } #endregion #region Combo box intialization / events ClientPickList cpl = null; private void LoadCombo() { //case 1039 //log.Debug("LoadCombo"); cbClientID.Items.Clear(); cbClientID.Items.Add(cbClientID.EmptyValueListItem); //case 1144 cbClientID.SortStyle = ValueListSortStyle.None; //tested using databinding and it was a lot slower //this is actually far faster. Typical Infragistics bullshit foreach (ClientPickList.ClientPickListInfo i in cpl) { if(i.Active)//case 1500 cbClientID.Items.Add(i.ID, i.Name); } //case 1144 // cbClientID.SortStyle = ValueListSortStyle.Ascending; if(cbClientID.Items.Count>0) cbClientID.SelectedIndex = 0; if (mSelectedClientID != Guid.Empty) Util.ComboSelectGuid(cbClientID, mSelectedClientID); cbTemplateID.Items.Clear(); if (!AyaBizUtils.Lite)//case 1172 { TemplatePickList UList = TemplatePickList.GetList(woType, true); foreach (TemplatePickList.TemplatePickListInfo ui in UList) { cbTemplateID.Items.Add(ui.ID, ui.Description); } } if(woType == WorkorderTypes.TemplateService) Util.ComboSelectGuid(cbTemplateID, TemplateServiceResolver.ResolveTemplate(mSelectedClientID, User.CurrentThreadUserID)); else cbTemplateID.SelectedIndex = 0; bLoading = false; } bool bLoading = true; private void cbClientID_SelectionChanged(object sender, System.EventArgs e) { if (bLoading) return; //Added:4-Sept-2006 check if selected item is null //this came about because when adding a new client via this form //timing was causing the selected item to be null when this even fired first if (cbClientID.SelectedItem != null) { mSelectedClientID = (Guid)cbClientID.SelectedItem.DataValue; Util.ComboSelectGuid(cbTemplateID, TemplateServiceResolver.ResolveTemplate(mSelectedClientID, User.CurrentThreadUserID)); } } #endregion private void btnCancel_Click(object sender, System.EventArgs e) { mSelectedClientID=Guid.Empty; this.DialogResult=DialogResult.Cancel; this.Close(); } private void btnOK_Click(object sender, System.EventArgs e) { this.DialogResult=DialogResult.OK; this.Close(); } private void btnRefresh_Click(object sender, System.EventArgs e) { edSearch.Text = ""; cpl = ClientPickList.GetList(true); LoadCombo(); } private void btnSearch_Click(object sender, EventArgs e) { SearchResultList srl = SearchResultList.GetPickListForObjectType(edSearch.Text, RootObjectTypes.Client); cpl = ClientPickList.GetList(srl.ListPickListID, true); LoadCombo(); } //-------------------------------------------------------- } }