public GXAccountCreditChargeDlg(GXCreditChargeConfiguration target, GXDLMSObjectCollection objects) { InitializeComponent(); Target = target; foreach (var it in Enum.GetValues(typeof(CreditCollectionConfiguration))) { //None is not added. if ((int)it != 0) { ConfigurationLb.Items.Add(it, (Target.CollectionConfiguration & (CreditCollectionConfiguration)it) != 0); } } foreach (GXDLMSObject it in objects.GetObjects(Enums.ObjectType.Credit)) { CreditCb.Items.Add(it); if (target.CreditReference == it.LogicalName) { CreditCb.SelectedItem = it; } } foreach (GXDLMSObject it in objects.GetObjects(Enums.ObjectType.Charge)) { ChargeCb.Items.Add(it); if (target.ChargeReference == it.LogicalName) { ChargeCb.SelectedItem = it; } } }
public GXDLMSProfileGenericColumnDlg( GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> target, GXDLMSObjectCollection list, string title) { Target = target; AllObjects = new GXDLMSObjectCollection(); AllObjects.AddRange(list); //Remove not needed objects. foreach (GXDLMSObject it in list.GetObjects(new ObjectType[] { ObjectType.AssociationLogicalName, ObjectType.AssociationShortName, ObjectType.ProfileGeneric })) { AllObjects.Remove(it); } InitializeComponent(); if (title != null) { this.Text = title; } foreach (GXDLMSObject it in AllObjects) { TargetCb.Items.Add(it); } if (Target.Key != null) { TargetCb.SelectedItem = AllObjects.FindByLN(Target.Key.ObjectType, Target.Key.LogicalName); } if (Target.Value != null) { IndexTB.Text = target.Value.AttributeIndex.ToString(); DataIndexTb.Text = target.Value.DataIndex.ToString(); } else { IndexTB.Text = "2"; DataIndexTb.Text = "0"; } }
/// <summary> /// Constructor. /// </summary> /// <param name="caption">Window caption.</param> /// <param name="target">Selected objects.</param> /// <param name="objects">List of COSEM objects.</param> public GXDLMSTokenGatewayConfigurationDlg(GXTokenGatewayConfiguration target, GXDLMSObjectCollection objects) { Target = target; InitializeComponent(); foreach (GXDLMSObject it in objects.GetObjects(Enums.ObjectType.Credit)) { TargetCb.Items.Add(it); if (it.LogicalName == target.CreditReference) { TargetCb.SelectedItem = it; } } ProportionTb.Text = target.TokenProportion.ToString(); }
/// <summary> /// After UpdateObjects call objects can be read using Objects property. /// </summary> public void UpdateObjects() { try { GXDLMSObjectCollection objs = Comm.GetObjects(); objs.Tag = this; int pos = 0; foreach (GXDLMSObject it in objs) { ++pos; NotifyProgress(this, "Creating object " + it.LogicalName, pos, objs.Count); Objects.Add(it); } GXLogWriter.WriteLog("--- Created " + Objects.Count.ToString() + " objects. ---"); //Read registers units and scalers. int cnt = Objects.Count; if (!UseLogicalNameReferencing) { GXLogWriter.WriteLog("--- Reading Access rights. ---"); try { foreach (GXDLMSAssociationShortName sn in Objects.GetObjects(ObjectType.AssociationShortName)) { if (sn.Version > 1) { Comm.ReadValue(sn, 3); } } } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); } GXLogWriter.WriteLog("--- Reading Access rights end. ---"); } GXLogWriter.WriteLog("--- Reading scalers and units. ---"); this.OnProgress(this, "Reading scalers and units.", cnt + pos + 1, 3 * cnt); if ((Comm.client.NegotiatedConformance & Gurux.DLMS.Enums.Conformance.MultipleReferences) != 0) { List <KeyValuePair <GXDLMSObject, int> > list = new List <KeyValuePair <GXDLMSObject, int> >(); foreach (GXDLMSObject it in Objects) { if (it is GXDLMSRegister && (it.GetAccess(3) & AccessMode.Read) != 0) { list.Add(new KeyValuePair <GXDLMSObject, int>(it, 3)); } if (it is GXDLMSDemandRegister && (it.GetAccess(4) & AccessMode.Read) != 0) { list.Add(new KeyValuePair <GXDLMSObject, int>(it, 4)); } } if (list.Count != 0) { try { Comm.ReadList(list); } catch (Exception) { //Show error. } } } else { for (pos = 0; pos != cnt; ++pos) { GXDLMSObject it = Objects[pos]; if (it is GXDLMSRegister) { //Read scaler first. try { if ((it.GetAccess(3) & AccessMode.Read) != 0) { Comm.ReadValue(it, 3); } } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); it.SetAccess(3, AccessMode.NoAccess); if (ex is GXDLMSException) { continue; } throw ex; } } if (it is GXDLMSDemandRegister) { //Read scaler first. try { if ((it.GetAccess(4) & AccessMode.Read) != 0) { Comm.ReadValue(it, 4); } } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); UpdateError(it, 4, ex); if (ex is GXDLMSException) { continue; } throw ex; } //Read Period try { Comm.ReadValue(it, 8); } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); UpdateError(it, 8, ex); if (ex is GXDLMSException) { continue; } throw ex; } //Read number of periods try { Comm.ReadValue(it, 9); } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); UpdateError(it, 9, ex); if (ex is GXDLMSException) { continue; } throw ex; } } } } GXLogWriter.WriteLog("--- Reading scalers and units end. ---"); this.OnProgress(this, "Reading profile generic columns.", cnt, cnt); foreach (Gurux.DLMS.Objects.GXDLMSProfileGeneric it in objs.GetObjects(ObjectType.ProfileGeneric)) { ++pos; //Read Profile Generic Columns. try { NotifyProgress(this, "Get profile generic columns", (2 * cnt) + pos, 3 * objs.Count); UpdateColumns(it, Manufacturers.FindByIdentification(Manufacturer)); if (it.CaptureObjects == null || it.CaptureObjects.Count == 0) { continue; } } catch { GXLogWriter.WriteLog(string.Format("Failed to read Profile Generic {0} columns.", it.LogicalName)); continue; } } } finally { NotifyProgress(this, "", 0, 0); } }
static void Main(string[] args) { IGXMedia media = null; GXCommunicatation comm = null; try { TextWriter logFile = new StreamWriter(File.Open("LogFile.txt", FileMode.Create)); //////////////////////////////////////// //Handle command line parameters. String id = "", host = "", port = "", pw = ""; bool trace = false, iec = true; Authentication auth = Authentication.None; foreach (string it in args) { String item = it.Trim().ToLower(); if (string.Compare(item, "/u", true) == 0)//Update { //Get latest manufacturer settings from Gurux web server. GXManufacturerCollection.UpdateManufactureSettings(); } else if (item.StartsWith("/m="))//Manufacturer { id = item.Replace("/m=", ""); } else if (item.StartsWith("/h=")) //Host { host = item.Replace("/h=", ""); } else if (item.StartsWith("/p="))// TCP/IP Port { media = new Gurux.Net.GXNet(); port = item.Replace("/p=", ""); } else if (item.StartsWith("/sp="))//Serial Port { port = item.Replace("/sp=", ""); media = new GXSerial(); } else if (item.StartsWith("/t"))//Are messages traced. { trace = true; } else if (item.StartsWith("/s="))//Start { String tmp = item.Replace("/s=", ""); iec = string.Compare(tmp, "dlms", true) != 0; } else if (item.StartsWith("/a="))//Authentication { auth = (Authentication)Enum.Parse(typeof(Authentication), it.Trim().Replace("/a=", "")); } else if (item.StartsWith("/pw="))//Password { pw = it.Trim().Replace("/pw=", ""); } else { ShowHelp(); return; } } if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(port) || (media is GXNet && string.IsNullOrEmpty(host))) { ShowHelp(); return; } //////////////////////////////////////// //Initialize connection settings. if (media is GXSerial) { GXSerial serial = media as GXSerial; serial.PortName = port; if (iec) { serial.BaudRate = 300; serial.DataBits = 7; serial.Parity = System.IO.Ports.Parity.Even; serial.StopBits = System.IO.Ports.StopBits.One; } else { serial.BaudRate = 9600; serial.DataBits = 8; serial.Parity = System.IO.Ports.Parity.None; serial.StopBits = System.IO.Ports.StopBits.One; } } else if (media is GXNet) { Gurux.Net.GXNet net = media as GXNet; net.Port = Convert.ToInt32(port); net.HostName = host; net.Protocol = Gurux.Net.NetworkType.Tcp; } else { throw new Exception("Unknown media type."); } //////////////////////////////////////// //Update manufacturer depended settings. GXManufacturerCollection Manufacturers = new GXManufacturerCollection(); GXManufacturerCollection.ReadManufacturerSettings(Manufacturers); GXManufacturer man = Manufacturers.FindByIdentification(id); if (man == null) { throw new Exception("Unknown manufacturer: " + id); } GXDLMSClient dlms = new GXDLMSClient(); //Update Obis code list so we can get right descriptions to the objects. dlms.CustomObisCodes = man.ObisCodes; comm = new GXCommunicatation(dlms, media, iec, auth, pw); comm.Trace = trace; comm.InitializeConnection(man); GXDLMSObjectCollection objects = null; string path = host.Replace('.', '_') + "_" + port.ToString() + ".xml"; List <Type> extraTypes = new List <Type>(Gurux.DLMS.GXDLMSClient.GetObjectTypes()); extraTypes.Add(typeof(GXDLMSAttributeSettings)); extraTypes.Add(typeof(GXDLMSAttribute)); XmlSerializer x = new XmlSerializer(typeof(GXDLMSObjectCollection), extraTypes.ToArray()); //You can save association view, but make sure that it is not change. //Save Association view to the cache so it is not needed to retrieve every time. /* * if (File.Exists(path)) * { * try * { * using (Stream stream = File.Open(path, FileMode.Open)) * { * Console.WriteLine("Get available objects from the cache."); * objects = x.Deserialize(stream) as GXDLMSObjectCollection; * stream.Close(); * } * } * catch (Exception ex) * { * if (File.Exists(path)) * { * File.Delete(path); * } * throw ex; * } * } * else */ { Console.WriteLine("Get available objects from the device."); objects = comm.GetAssociationView(); GXDLMSObjectCollection objs = objects.GetObjects(new ObjectType[] { ObjectType.Register, ObjectType.ExtendedRegister, ObjectType.DemandRegister }); Console.WriteLine("Read scalers and units from the device."); Thread.Sleep(1000); foreach (GXDLMSObject it in objs) { if (it is GXDLMSRegister) { Console.WriteLine(it.Name); comm.Read(it, 3); } if (it is GXDLMSDemandRegister) { Console.WriteLine(it.Name); comm.Read(it, 4); } } Thread.Sleep(1000); //Read Profile Generic columns first. foreach (GXDLMSObject it in objects.GetObjects(ObjectType.ProfileGeneric)) { try { Console.WriteLine(it.Name); comm.Read(it, 3); GXDLMSObject[] cols = (it as GXDLMSProfileGeneric).GetCaptureObject(); TraceLine(logFile, "Profile Generic " + it.Name + " Columns:"); StringBuilder sb = new StringBuilder(); bool First = true; foreach (GXDLMSObject col in cols) { if (!First) { sb.Append(" | "); } First = false; sb.Append(col.Name); sb.Append(" "); sb.Append(col.Description); } TraceLine(logFile, sb.ToString()); } catch (Exception ex) { TraceLine(logFile, "Err! Failed to read columns:" + ex.Message); //Continue reading. } } try { using (Stream stream = File.Open(path, FileMode.Create)) { TextWriter writer = new StreamWriter(stream); x.Serialize(writer, objects); writer.Close(); stream.Close(); } } catch (Exception ex) { if (File.Exists(path)) { File.Delete(path); } throw ex; } Console.WriteLine("--- Available objects ---"); foreach (GXDLMSObject it in objects) { Console.WriteLine(it.Name + " " + it.Description); } } Thread.Sleep(1000); foreach (GXDLMSObject it in objects) { // Profile generics are read later because they are special cases. // (There might be so lots of data and we so not want waste time to read all the data.) if (it is GXDLMSProfileGeneric) { continue; } if (!(it is IGXDLMSBase)) { //If interface is not implemented. //Example manufacturer spesific interface. Console.WriteLine("Unknown Interface: " + it.ObjectType.ToString()); continue; } TraceLine(logFile, "-------- Reading " + it.GetType().Name + " " + it.Name + " " + it.Description); foreach (int pos in (it as IGXDLMSBase).GetAttributeIndexToRead()) { try { object val = comm.Read(it, pos); //If data is array. if (val is byte[]) { val = GXCommon.ToHex((byte[])val, true); } else if (val is Array) { string str = ""; for (int pos2 = 0; pos2 != (val as Array).Length; ++pos2) { if (str != "") { str += ", "; } if ((val as Array).GetValue(pos2) is byte[]) { str += GXCommon.ToHex((byte[])(val as Array).GetValue(pos2), true); } else { str += (val as Array).GetValue(pos2).ToString(); } } val = str; } else if (val is System.Collections.IList) { string str = "["; bool empty = true; foreach (object it2 in val as System.Collections.IList) { if (!empty) { str += ", "; } empty = false; if (it2 is byte[]) { str += GXCommon.ToHex((byte[])it2, true); } else { str += it2.ToString(); } } str += "]"; val = str; } TraceLine(logFile, "Index: " + pos + " Value: " + val); } catch (Exception ex) { TraceLine(logFile, "Error! Index: " + pos + " " + ex.Message); } } } Thread.Sleep(1000); //Find profile generics and read them. foreach (GXDLMSObject it in objects.GetObjects(ObjectType.ProfileGeneric)) { TraceLine(logFile, "-------- Reading " + it.GetType().Name + " " + it.Name + " " + it.Description); long entriesInUse = Convert.ToInt64(comm.Read(it, 7)); long entries = Convert.ToInt64(comm.Read(it, 8)); TraceLine(logFile, "Entries: " + entriesInUse + "/" + entries); //If there are no columns or rows. if (entriesInUse == 0 || (it as GXDLMSProfileGeneric).CaptureObjects.Count == 0) { continue; } try { //Read first row from Profile Generic. object[] rows = comm.ReadRowsByEntry(it as GXDLMSProfileGeneric, 0, 1); StringBuilder sb = new StringBuilder(); foreach (object[] row in rows) { foreach (object cell in row) { if (cell is byte[]) { sb.Append(GXCommon.ToHex((byte[])cell, true)); } else { sb.Append(Convert.ToString(cell)); } sb.Append(" | "); } sb.Append("\r\n"); } Trace(logFile, sb.ToString()); } catch (Exception ex) { TraceLine(logFile, "Error! Failed to read first row: " + ex.Message); //Continue reading. } try { //Read last day from Profile Generic. object[] rows = comm.ReadRowsByRange(it as GXDLMSProfileGeneric, DateTime.Now.Date, DateTime.MaxValue); StringBuilder sb = new StringBuilder(); foreach (object[] row in rows) { foreach (object cell in row) { if (cell is byte[]) { sb.Append(GXCommon.ToHex((byte[])cell, true)); } else { sb.Append(Convert.ToString(cell)); } sb.Append(" | "); } sb.Append("\r\n"); } Trace(logFile, sb.ToString()); } catch (Exception ex) { TraceLine(logFile, "Error! Failed to read last day: " + ex.Message); //Continue reading. } } logFile.Flush(); logFile.Close(); } catch (Exception ex) { if (comm != null) { comm.Close(); } Console.WriteLine(ex.Message); if (!System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } } finally { if (comm != null) { comm.Close(); } if (System.Diagnostics.Debugger.IsAttached) { Console.WriteLine("Ended. Press any key to continue."); Console.ReadKey(); } } }
/// <summary> /// After UpdateObjects call objects can be read using Objects property. /// </summary> public void UpdateObjects() { try { GXDLMSObjectCollection objs = Comm.GetObjects(); objs.Tag = this; int pos = 0; foreach (GXDLMSObject it in objs) { //Profile Generic objects are added later. if (it.ObjectType == ObjectType.ProfileGeneric) { continue; } if (it.GetType() == typeof(GXDLMSObject)) { continue; } ++pos; NotifyProgress(this, "Creating object " + it.LogicalName, pos, objs.Count); m_Objects.Add(it); } GXLogWriter.WriteLog("--- Created " + m_Objects.Count.ToString() + " objects. ---"); int objPos = 0; //Read registers units and scalers. int cnt = Objects.Count; GXLogWriter.WriteLog("--- Reading scalers and units. ---"); for (pos = 0; pos != cnt; ++pos) { GXDLMSObject it = Objects[pos]; it.UpdateDefaultValueItems(); this.OnProgress(this, "Reading scalers and units.", pos + 1, cnt); if (it is GXDLMSRegister) { object data = it.ShortName; if (it.ShortName == 0) { data = it.LogicalName; } //Read scaler first. DataType type = DataType.None; try { data = Comm.ReadValue(data, it.ObjectType, 3, ref type); object tmp = GXHelpers.ConvertFromDLMS(data, DataType.None, DataType.None, false); //Actaris ACE 6000 is returning wrong value here. if (tmp is object[]) { object[] scalerUnit = (object[])tmp; ((GXDLMSRegister)it).Scaler = Math.Pow(10, Convert.ToInt32(scalerUnit.GetValue(0))); ((GXDLMSRegister)it).Unit = (Unit)Convert.ToInt32(scalerUnit.GetValue(1)); } } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); UpdateError(it, 3, ex); if (ex is GXDLMSException) { continue; } throw ex; } } if (it is GXDLMSDemandRegister) { object name = it.ShortName; object data; if (it.ShortName == 0) { name = it.LogicalName; } //Read scaler first. DataType type = DataType.None; byte attributeOrder = 4; try { data = Comm.ReadValue(name, it.ObjectType, attributeOrder, ref type); Array scalerUnit = (Array)GXHelpers.ConvertFromDLMS(data, DataType.None, DataType.None, false); ((GXDLMSDemandRegister)it).Scaler = Math.Pow(10, Convert.ToInt32(scalerUnit.GetValue(0))); ((GXDLMSDemandRegister)it).Unit = (Unit)Convert.ToInt32(scalerUnit.GetValue(1)); //Read Period data = Comm.ReadValue(name, it.ObjectType, 8, ref type); ((GXDLMSDemandRegister)it).Period = Convert.ToUInt64(data); //Read number of periods data = Comm.ReadValue(name, it.ObjectType, 9, ref type); ((GXDLMSDemandRegister)it).NumberOfPeriods = Convert.ToUInt32(data); } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); UpdateError(it, 3, ex); if (ex is GXDLMSException) { continue; } throw ex; } } } GXLogWriter.WriteLog("--- Reading scalers and units end. ---"); /* TODO: * if (!m.UseLogicalNameReferencing) * { * GXLogWriter.WriteLog("--- Reading Access rights. ---"); * try * { * foreach (GXDLMSAssociationShortName sn in dev.Objects.GetObjects(ObjectType.AssociationShortName)) * { * dev.Comm.Read(sn, 3); * } * } * catch (Exception ex) * { * GXLogWriter.WriteLog(ex.Message); * } * GXLogWriter.WriteLog("--- Reading Access rights end. ---"); * } * */ this.OnProgress(this, "Reading scalers and units.", cnt, cnt); foreach (Gurux.DLMS.Objects.GXDLMSProfileGeneric it in objs.GetObjects(ObjectType.ProfileGeneric)) { ++pos; NotifyProgress(this, "Creating object " + it.LogicalName, pos, objs.Count); //Read Profile Generic Columns. try { NotifyProgress(this, "Get profile generic columns", ++objPos, objs.Count); UpdateColumns(it, Manufacturers.FindByIdentification(Manufacturer)); if (it.CaptureObjects == null || it.CaptureObjects.Count == 0) { continue; } } catch { GXLogWriter.WriteLog(string.Format("Failed to read Profile Generic {0} columns.", it.LogicalName)); continue; } m_Objects.Add(it); } } finally { NotifyProgress(this, "", 0, 0); } }
/// <summary> /// After UpdateObjects call objects can be read using Objects property. /// </summary> public void UpdateObjects() { try { GXDLMSObjectCollection objs = Comm.GetObjects(); objs.Tag = this; int pos = 0; foreach (GXDLMSObject it in objs) { ++pos; NotifyProgress(this, "Creating object " + it.LogicalName, pos, objs.Count); m_Objects.Add(it); } GXLogWriter.WriteLog("--- Created " + m_Objects.Count.ToString() + " objects. ---"); //Read registers units and scalers. int cnt = Objects.Count; GXLogWriter.WriteLog("--- Reading scalers and units. ---"); for (pos = 0; pos != cnt; ++pos) { GXDLMSObject it = Objects[pos]; this.OnProgress(this, "Reading scalers and units.", cnt + pos + 1, 3 * cnt); if (it is GXDLMSRegister) { //Read scaler first. try { Comm.ReadValue(it, 3); } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); UpdateError(it, 3, ex); if (ex is GXDLMSException) { continue; } throw ex; } } if (it is GXDLMSDemandRegister) { try { //Read scaler first. Comm.ReadValue(it, 4); //Read Period Comm.ReadValue(it, 8); //Read number of periods Comm.ReadValue(it, 9); } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); UpdateError(it, 3, ex); if (ex is GXDLMSException) { continue; } throw ex; } } } GXLogWriter.WriteLog("--- Reading scalers and units end. ---"); if (!UseLogicalNameReferencing) { GXLogWriter.WriteLog("--- Reading Access rights. ---"); try { foreach (GXDLMSAssociationShortName sn in Objects.GetObjects(ObjectType.AssociationShortName)) { Comm.ReadValue(sn, 3); } } catch (Exception ex) { GXLogWriter.WriteLog(ex.Message); } GXLogWriter.WriteLog("--- Reading Access rights end. ---"); } this.OnProgress(this, "Reading profile generic columns.", cnt, cnt); foreach (Gurux.DLMS.Objects.GXDLMSProfileGeneric it in objs.GetObjects(ObjectType.ProfileGeneric)) { ++pos; //Read Profile Generic Columns. try { NotifyProgress(this, "Get profile generic columns", (2 * cnt) + pos, 3 * objs.Count); UpdateColumns(it, Manufacturers.FindByIdentification(Manufacturer)); if (it.CaptureObjects == null || it.CaptureObjects.Count == 0) { continue; } } catch { GXLogWriter.WriteLog(string.Format("Failed to read Profile Generic {0} columns.", it.LogicalName)); continue; } } } finally { NotifyProgress(this, "", 0, 0); } }
public GXDLMScheduleDlg( GXScheduleEntry e, GXDLMSObjectCollection objects, int index) { entry = e; if (entry.SwitchTime == null) { entry.SwitchTime = new GXTime(); } if (entry.BeginDate == null) { entry.BeginDate = new GXDate(-1, 1, 1); } if (entry.EndDate == null) { entry.EndDate = new GXDate(-1, 1, 1); } InitializeComponent(); foreach (GXDLMSObject it in objects.GetObjects(ObjectType.ScriptTable)) { ScriptTb.Items.Add(it); } ScriptTb.SelectedItem = entry.Script; IndexTB.Text = entry.Index.ToString(); EnabledCb.Checked = entry.Enable; SelectorTb.Text = entry.ScriptSelector.ToString(); TimeTb.Text = entry.SwitchTime.ToFormatString(); MondayCb.Checked = (entry.ExecWeekdays & Weekdays.Monday) != 0; TuesdayCb.Checked = (entry.ExecWeekdays & Weekdays.Tuesday) != 0; WednesdayCb.Checked = (entry.ExecWeekdays & Weekdays.Wednesday) != 0; ThursdayCb.Checked = (entry.ExecWeekdays & Weekdays.Thursday) != 0; FridayCb.Checked = (entry.ExecWeekdays & Weekdays.Friday) != 0; SaturdayCb.Checked = (entry.ExecWeekdays & Weekdays.Saturday) != 0; SundayCb.Checked = (entry.ExecWeekdays & Weekdays.Sunday) != 0; ValidityWindowTb.Text = entry.ValidityWindow.ToString(); ExecSpecDaysTb.Text = entry.ExecSpecDays; BeginTb.Text = entry.BeginDate.ToFormatString(); EndTb.Text = entry.EndDate.ToFormatString(); //Enable/Disable if (index == 1) { this.Text = "Enable/Disable schedule entry"; ScriptTb.Enabled = false; IndexTB.ReadOnly = true; EnabledCb.Enabled = true; SelectorTb.ReadOnly = true; TimeTb.ReadOnly = true; MondayCb.Enabled = false; TuesdayCb.Enabled = false; WednesdayCb.Enabled = false; ThursdayCb.Enabled = false; FridayCb.Enabled = false; SaturdayCb.Enabled = false; SundayCb.Enabled = false; ValidityWindowTb.ReadOnly = true; ExecSpecDaysTb.ReadOnly = true; BeginTb.ReadOnly = true; EndTb.ReadOnly = true; } else if (index == 2) { this.Text = "Add schedule entry"; } //Remove else if (index == 3) { this.Text = "Remove schedule entry"; ScriptTb.Enabled = false; IndexTB.ReadOnly = true; EnabledCb.Enabled = false; SelectorTb.ReadOnly = true; TimeTb.ReadOnly = true; MondayCb.Enabled = false; TuesdayCb.Enabled = false; WednesdayCb.Enabled = false; ThursdayCb.Enabled = false; FridayCb.Enabled = false; SaturdayCb.Enabled = false; SundayCb.Enabled = false; ValidityWindowTb.ReadOnly = true; ExecSpecDaysTb.ReadOnly = true; BeginTb.ReadOnly = true; EndTb.ReadOnly = true; } }