|
1 | | -namespace OSAE |
2 | | -{ |
3 | | - using System; |
4 | | - using System.Collections.Generic; |
5 | | - using System.Data; |
6 | | - using MySql.Data.MySqlClient; |
7 | | - |
8 | | - public static class OSAEScreenControlManager |
9 | | - { |
10 | | - public static void ScreenObjectAdd(string screen, string objectName, string controlName) |
11 | | - { |
12 | | - using (MySqlCommand command = new MySqlCommand()) |
13 | | - { |
14 | | - command.CommandText = "CALL osae_sp_screen_object_add(@Screen, @ObjectName, @ControlName)"; |
15 | | - command.Parameters.AddWithValue("@Screen", screen); |
16 | | - command.Parameters.AddWithValue("@ObjectName", objectName); |
17 | | - command.Parameters.AddWithValue("@ControlName", controlName); |
18 | | - |
19 | | - try |
20 | | - { |
21 | | - OSAESql.RunQuery(command); |
22 | | - } |
23 | | - catch (Exception ex) |
24 | | - { |
25 | | - Logging.GetLogger().AddToLog("ScreenObjectAdd error: " + command.CommandText + " - error: " + ex.Message, true); |
26 | | - } |
27 | | - } |
28 | | - } |
29 | | - |
30 | | - public static List<OSAEScreenControl> GetScreenControls(string screenName) |
31 | | - { |
32 | | - List<OSAEScreenControl> controls = new List<OSAEScreenControl>(); |
33 | | - |
34 | | - try |
35 | | - { |
36 | | - using (MySqlCommand command = new MySqlCommand()) |
37 | | - { |
38 | | - DataSet dataset = new DataSet(); |
39 | | - OSAEScreenControl ctrl = new OSAEScreenControl(); |
40 | | - |
41 | | - command.CommandText = "SELECT object_name, control_name, control_type, state_name, last_updated, coalesce(time_in_state, 0) as time_in_state FROM osae_v_screen_object WHERE screen_name=@ScreenName AND control_enabled = 1"; |
42 | | - command.Parameters.AddWithValue("@ScreenName", screenName); |
43 | | - dataset = OSAESql.RunQuery(command); |
44 | | - |
45 | | - if (dataset.Tables[0].Rows.Count > 0) |
46 | | - { |
47 | | - foreach (DataRow dr in dataset.Tables[0].Rows) |
48 | | - { |
49 | | - ctrl = new OSAEScreenControl(); |
50 | | - ctrl.ObjectState = dr["state_name"].ToString(); |
51 | | - |
52 | | - ctrl.TimeInState = Convert.ToInt64(dr["time_in_state"]).ToString(); |
53 | | - ctrl.ControlName = dr["control_name"].ToString(); |
54 | | - ctrl.ControlType = dr["control_type"].ToString(); |
55 | | - ctrl.LastUpdated = DateTime.Parse(dr["last_updated"].ToString()); |
56 | | - ctrl.ObjectName = dr["object_name"].ToString(); |
57 | | - |
58 | | - controls.Add(ctrl); |
59 | | - } |
60 | | - |
61 | | - return controls; |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - return controls; |
66 | | - } |
67 | | - catch (Exception ex) |
68 | | - { |
69 | | - Logging.GetLogger().AddToLog("API - GetObjectsByBaseType error: " + ex.Message, true); |
70 | | - return controls; |
71 | | - } |
72 | | - } |
73 | | - } |
74 | | -} |
| 1 | +namespace OSAE |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using System.Collections.Generic; |
| 5 | + using System.Data; |
| 6 | + using MySql.Data.MySqlClient; |
| 7 | + |
| 8 | + public static class OSAEScreenControlManager |
| 9 | + { |
| 10 | + public static void ScreenObjectAdd(string screen, string objectName, string controlName) |
| 11 | + { |
| 12 | + using (MySqlCommand command = new MySqlCommand()) |
| 13 | + { |
| 14 | + command.CommandText = "CALL osae_sp_screen_object_add(@Screen, @ObjectName, @ControlName)"; |
| 15 | + command.Parameters.AddWithValue("@Screen", screen); |
| 16 | + command.Parameters.AddWithValue("@ObjectName", objectName); |
| 17 | + command.Parameters.AddWithValue("@ControlName", controlName); |
| 18 | + |
| 19 | + try |
| 20 | + { |
| 21 | + OSAESql.RunQuery(command); |
| 22 | + } |
| 23 | + catch (Exception ex) |
| 24 | + { |
| 25 | + Logging.GetLogger().AddToLog("ScreenObjectAdd error: " + command.CommandText + " - error: " + ex.Message, true); |
| 26 | + } |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public static void ScreenObjectUpdate(string screen, string objectName, string controlName) |
| 31 | + { |
| 32 | + using (MySqlCommand command = new MySqlCommand()) |
| 33 | + { |
| 34 | + command.CommandText = "CALL osae_sp_screen_object_update(@Screen, @ObjectName, @ControlName)"; |
| 35 | + command.Parameters.AddWithValue("@Screen", screen); |
| 36 | + command.Parameters.AddWithValue("@ObjectName", objectName); |
| 37 | + command.Parameters.AddWithValue("@ControlName", controlName); |
| 38 | + |
| 39 | + try |
| 40 | + { |
| 41 | + OSAESql.RunQuery(command); |
| 42 | + } |
| 43 | + catch (Exception ex) |
| 44 | + { |
| 45 | + Logging.GetLogger().AddToLog("ScreenObjectUpdate error: " + command.CommandText + " - error: " + ex.Message, true); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + public static void ScreenObjectDelete(string screen, string objectName, string controlName) |
| 52 | + { |
| 53 | + using (MySqlCommand command = new MySqlCommand()) |
| 54 | + { |
| 55 | + command.CommandText = "CALL osae_sp_screen_object_delete(@Screen, @ObjectName, @ControlName)"; |
| 56 | + command.Parameters.AddWithValue("@Screen", screen); |
| 57 | + command.Parameters.AddWithValue("@ObjectName", objectName); |
| 58 | + command.Parameters.AddWithValue("@ControlName", controlName); |
| 59 | + |
| 60 | + try |
| 61 | + { |
| 62 | + OSAESql.RunQuery(command); |
| 63 | + } |
| 64 | + catch (Exception ex) |
| 65 | + { |
| 66 | + Logging.GetLogger().AddToLog("ScreenObjectDelete error: " + command.CommandText + " - error: " + ex.Message, true); |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + public static List<OSAEScreenControl> GetScreenControls(string screenName) |
| 74 | + { |
| 75 | + List<OSAEScreenControl> controls = new List<OSAEScreenControl>(); |
| 76 | + |
| 77 | + try |
| 78 | + { |
| 79 | + using (MySqlCommand command = new MySqlCommand()) |
| 80 | + { |
| 81 | + DataSet dataset = new DataSet(); |
| 82 | + OSAEScreenControl ctrl = new OSAEScreenControl(); |
| 83 | + |
| 84 | + command.CommandText = "SELECT object_name, control_name, control_type, state_name, last_updated, coalesce(time_in_state, 0) as time_in_state FROM osae_v_screen_object WHERE screen_name=@ScreenName AND control_enabled = 1"; |
| 85 | + command.Parameters.AddWithValue("@ScreenName", screenName); |
| 86 | + dataset = OSAESql.RunQuery(command); |
| 87 | + |
| 88 | + if (dataset.Tables[0].Rows.Count > 0) |
| 89 | + { |
| 90 | + foreach (DataRow dr in dataset.Tables[0].Rows) |
| 91 | + { |
| 92 | + ctrl = new OSAEScreenControl(); |
| 93 | + ctrl.ObjectState = dr["state_name"].ToString(); |
| 94 | + |
| 95 | + ctrl.TimeInState = Convert.ToInt64(dr["time_in_state"]).ToString(); |
| 96 | + ctrl.ControlName = dr["control_name"].ToString(); |
| 97 | + ctrl.ControlType = dr["control_type"].ToString(); |
| 98 | + ctrl.LastUpdated = DateTime.Parse(dr["last_updated"].ToString()); |
| 99 | + ctrl.ObjectName = dr["object_name"].ToString(); |
| 100 | + |
| 101 | + controls.Add(ctrl); |
| 102 | + } |
| 103 | + |
| 104 | + return controls; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + return controls; |
| 109 | + } |
| 110 | + catch (Exception ex) |
| 111 | + { |
| 112 | + Logging.GetLogger().AddToLog("API - GetObjectsByBaseType error: " + ex.Message, true); |
| 113 | + return controls; |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments