Esempio n. 1
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (VerifyData())
            {
                List <String> PermissionArray = new List <String>();
                for (int i = 0; i < UserPermissionType.RowCount; i++)
                {
                    if (Convert.ToBoolean(UserPermissionType[0, i].Value))
                    {
                        PermissionArray.Add(UserPermissionType[1, i].Value.ToString());
                    }
                }

                List <String> StationArray = new List <String>();
                for (int i = 0; i < UserStationPermission.RowCount; i++)
                {
                    if (Convert.ToBoolean(UserStationPermission[0, i].Value))
                    {
                        StationArray.Add(UserStationPermission[1, i].Value.ToString());
                    }
                }

                if (UserID == null)
                {
                    UserID = TTCSHelper.GenNewID();
                    UserManagement.AddUser(UserID, UserName.Text, UserLoginName.Text, UserLoginPassword.Text, String.Join(",", PermissionArray), String.Join(",", StationArray));
                }
                else
                {
                    UserManagement.UpdateUser(UserID, UserName.Text, UserLoginName.Text, UserLoginPassword.Text, String.Join(",", PermissionArray), String.Join(",", StationArray));
                }

                this.Close();
            }
        }
Esempio n. 2
0
        private static void ReadScriptFromBuffer()
        {
            Task TTCSTask = Task.Run(() =>
            {
                Boolean IsDatabaseUpdate = false;
                while (IsScriptActive)
                {
                    ScriptBuffer ThisBuffer = null;
                    if (NewScriptBuffer.TryDequeue(out ThisBuffer))
                    {
                        ScriptTB ExistingScript = ScriptDBBuffer.FirstOrDefault(Item => Item.Value.BlockName == ThisBuffer.Script.BlockName && Item.Value.ScriptState != "EXECUTED").Value;
                        if (ExistingScript == null)  //New block name
                        {
                            ThisBuffer.Script.TargetID    = TTCSHelper.GenNewID();
                            ThisBuffer.Script.BlockID     = ThisBuffer.Script.TargetID;
                            ThisBuffer.Script.ScriptState = "CREATED";
                            ScriptDBBuffer.TryAdd(ThisBuffer.Script.BlockID + ThisBuffer.Script.ExecutionNumber, ThisBuffer.Script);

                            DatabaseSynchronization.InsertScript(ThisBuffer.Script);
                            IsDatabaseUpdate = true;
                            AddScriptToMonitoring(ThisBuffer.Script);
                        }
                        else if (ExistingScript.ScriptState != "EXECUTING") //Existing block name
                        {
                            ScriptTB ExistingBlockScript = ScriptDBBuffer.FirstOrDefault(Item => Item.Value.BlockName == ThisBuffer.Script.BlockName && Item.Value.ExecutionNumber == ThisBuffer.Script.ExecutionNumber && Item.Value.ScriptState != "EXECUTED").Value;

                            if (ExistingBlockScript == null)  //Add new script to the same BlockName
                            {
                                ExistingBlockScript         = ThisBuffer.Script;
                                ExistingBlockScript.BlockID = ExistingScript.BlockID;
                                ScriptDBBuffer.TryAdd(ExistingBlockScript.BlockID + ExistingBlockScript.ExecutionNumber, ExistingBlockScript);

                                DatabaseSynchronization.InsertScript(ExistingBlockScript);
                                IsDatabaseUpdate = true;
                                AddScriptToMonitoring(ExistingBlockScript);
                            }
                            else
                            {
                                if (!IsEqualScript(ExistingBlockScript, ThisBuffer.Script))  //Update existing BlockName
                                {
                                    ExistingBlockScript.CommandCounter     = ThisBuffer.Script.CommandCounter;
                                    ExistingBlockScript.CommandName        = ThisBuffer.Script.CommandName;
                                    ExistingBlockScript.DelayTime          = ThisBuffer.Script.DelayTime;
                                    ExistingBlockScript.DeviceCategory     = ThisBuffer.Script.DeviceCategory;
                                    ExistingBlockScript.DeviceName         = ThisBuffer.Script.DeviceName;
                                    ExistingBlockScript.ExecutionTimeEnd   = ThisBuffer.Script.ExecutionTimeEnd;
                                    ExistingBlockScript.ExecutionTimeStart = ThisBuffer.Script.ExecutionTimeStart;
                                    ExistingBlockScript.Owner       = ThisBuffer.Script.Owner;
                                    ExistingBlockScript.Parameter   = ThisBuffer.Script.Parameter;
                                    ExistingBlockScript.ScriptState = "CREATED";
                                    ExistingBlockScript.StationName = ThisBuffer.Script.StationName;

                                    UpdateScriptToMonitoring(ExistingBlockScript);
                                }
                            }
                        }
                    }

                    ResponseToClient(ThisBuffer);
                    if (!IsDatabaseUpdate)
                    {
                        IsDatabaseUpdate = ResponseToStation(ThisBuffer);
                    }
                    else
                    {
                        ResponseToStation(ThisBuffer);
                    }

                    if (!IsDatabaseUpdate)
                    {
                        IsDatabaseUpdate = RemoveExpireScript();
                    }
                    else
                    {
                        RemoveExpireScript();
                    }

                    if (IsDatabaseUpdate)
                    {
                        IsDatabaseUpdate = !DatabaseSynchronization.ScriptSaveChange(true);
                    }

                    Thread.Sleep(10);
                }
            });
        }