private void EditAppConfig(object sender, EventArgs e)
        {
            if (dbUA.Settings.Count() == 0)
            {
                MessageBox.Show(GlobalConstants.FieldDatabaseCanNotBeEmpty);
            }
            else
            {
                dataFromSettings = dbUA.Settings
                                   .ToList()
                                   .Last();

                UpdateAppConfig.ViewAppConfig(GlobalConstants.AxDatabaseNameAppConfig, dataFromSettings, appConfigDescription);

                if (appConfigLabel.Visible == false && appConfigDescription.Visible == false &&
                    submitButton.Visible == false && cancelButton.Visible == false)
                {
                    submitButton.Text = GlobalConstants.NameOfButtonYes;
                    cancelButton.Text = GlobalConstants.NameOfButtonNo;

                    submitButton.Visible         = true;
                    cancelButton.Visible         = true;
                    appConfigLabel.Visible       = true;
                    appConfigDescription.Visible = true;
                }

                editFlagAppConfig = true;
            }
        }
        private void EditDatabaseName_Click(object sender, EventArgs e)
        {
            if (AxDbDiscription.Visible == false && databaseNameLabel.Visible == false &&
                submitButton.Visible == false && cancelButton.Visible == false)
            {
                AxDbDiscription.Visible   = true;
                databaseNameLabel.Visible = true;
                submitButton.Visible      = true;
                cancelButton.Visible      = true;
            }

            if (dbUA.Settings.Count() != 0)
            {
                dataFromSettings = dbUA.Settings
                                   .ToList()
                                   .Last();

                if (dataFromSettings.NameOfDatabase == string.Empty)
                {
                    MessageBox.Show("Error");
                }
                else
                {
                    AxDbDiscription.Text = dataFromSettings.NameOfDatabase;
                }
            }

            editFlagDatabaseName = true;
        }
        public static void add(string name, SettingsDbContent nameofDatabaseSettings, TextBox appConfigDescription, string pathG)
        {
            //TODO:
            //string ApplicationPath = Application.StartupPath;
            //string YourPath = Path.GetDirectoryName(ApplicationPath);

            bool isNew = false;

            //string path = Path.GetDirectoryName(YourPath) + "\\App.config";
            string path = pathG;

            XmlDocument doc = new XmlDocument();

            doc.Load(path);
            XmlNodeList list = doc.DocumentElement.SelectNodes(string.Format("connectionStrings/add[@name='{0}']", name));
            XmlNode     node;

            isNew = list.Count == 0;
            if (isNew)
            {
                node = doc.CreateNode(XmlNodeType.Element, "add", null);
                XmlAttribute attribute = doc.CreateAttribute("name");
                attribute.Value = name;
                node.Attributes.Append(attribute);

                attribute       = doc.CreateAttribute("connectionString");
                attribute.Value = "";
                node.Attributes.Append(attribute);

                attribute       = doc.CreateAttribute("providerName");
                attribute.Value = "System.Data.SqlClient";
                node.Attributes.Append(attribute);
            }
            else
            {
                node = list[0];
            }

            string conString = node.Attributes["connectionString"].Value;
            SqlConnectionStringBuilder conStringBuilder = new SqlConnectionStringBuilder(conString);

            conStringBuilder.InitialCatalog           = nameofDatabaseSettings.NameOfDatabase;
            conStringBuilder.DataSource               = GlobalConstants.MachineName;
            conStringBuilder.IntegratedSecurity       = true;
            conStringBuilder.MultipleActiveResultSets = true;
            node.Attributes["connectionString"].Value = conStringBuilder.ConnectionString;
            if (isNew)
            {
                doc.DocumentElement.SelectNodes("connectionStrings")[0].AppendChild(node);
            }

            doc.Save(path);
        }
        public static void Query(USERINFO updateCheckbox, string queryUpdateCheckbox, SettingsDbContent nameofDatabaseSettings, string machineName)
        {
            SqlConnection con = new SqlConnection(string.Format(GlobalConstants.ConnectionStringToAx, machineName, nameofDatabaseSettings.NameOfDatabase));

            con.Open();

            SqlCommand cmd = new SqlCommand(string.Format(queryUpdateCheckbox, nameofDatabaseSettings.NameOfDatabase, updateCheckbox.NAME));

            cmd.Connection = con;
            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
            DataTable      dbTable     = new DataTable();

            dataAdapter.Fill(dbTable);
        }
Beispiel #5
0
        public void UserChecker()
        {
            uContent.Description = discriptionBox.Text;

            var dataFromUSERINFO = dbAx.USERINFOes
                                   .Where(u => u.NETWORKALIAS == UserName)
                                   .ToList()
                                   .Last();

            var dataFromSYSUSERINFO = dbAx.SYSUSERINFOes
                                      .Where(x => x.RECID == dataFromUSERINFO.RECID)
                                      .ToList()
                                      .Last();

            dataFromSettings = dbUA.Settings
                               .ToList()
                               .Last();


            NameOfCompany = dataFromUSERINFO.COMPANY;

            if (Validations.DiscriptionLengths(discriptionBox.Text, submitBtnWasClickedAndAxIsOpen) == true)
            {
                if (dataFromUSERINFO.NETWORKALIAS.ToLower() == UserName.ToLower())
                {
                    IfCheckboxIsCheck();

                    AxOptions.OpenAx(newProcess, _startedProcesses);

                    Thread.Sleep(10000);

                    submitBtnWasClickedAndAxIsOpen = true;

                    Validations.ClearDiscriptionText(discriptionBox);

                    var dataFromUSERLOG = dbAx.SYSUSERLOGs
                                          .Where(t => t.USERID == dataFromUSERINFO.ID)
                                          .ToList()
                                          .Last();



                    uContent.CustomerName = UserName;

                    uContent.RECID = dataFromUSERLOG.RECID;

                    uContent.LogOn = dataFromUSERLOG.CREATEDDATETIME;

                    dbUA.UserAccess.Add(uContent);

                    dbUA.SaveChanges();



                    new Thread(() =>
                    {
                        AxOptions.IfAxIsClosed(newProcess, _startedProcesses, discriptionBox, Handle, NameOfCompany, submitBtnWasClickedAndAxIsOpen, dataFromUSERINFO, dataFromSettings, dataFromUSERLOG);

                        submitBtnWasClickedAndAxIsOpen = false;
                    }).Start();
                }
                else
                {
                    MessageBox.Show(GlobalConstants.UsernameIsNotValid);
                }
            }
        }
Beispiel #6
0
        public static void IfAxIsClosed(Process newProcess, Stack <Process> _startedProcesses, TextBox discriptionBox, IntPtr Handle, string NameOfCompany, bool submitBtnWasClickedAndAxIsOpen, USERINFO dataFromUSERINFO, SettingsDbContent nameofDatabaseSettings, SYSUSERLOG dataFromUSERLOG)
        {
            AxContext           AxContextt  = new AxContext();
            UserAccessDbContext UserAccesss = new UserAccessDbContext();

            while (_startedProcesses.Count > 0)
            {
                Thread.Sleep(10);

                if (newProcess == null || newProcess.HasExited)
                {
                    _startedProcesses.Pop();
                }

                if (_startedProcesses.Count == 0)
                {
                    SqlQueryWithString.Query(dataFromUSERINFO, GlobalConstants.UpdateCheckBoxTestsWithFalse, nameofDatabaseSettings, GlobalConstants.MachineName);


                    var dataFromUSERLOGQueryLOGOUT = AxContextt.SYSUSERLOGs
                                                     .Where(t => t.USERID == dataFromUSERINFO.ID)
                                                     .ToList()
                                                     .Last();

                    var dataFromUserAccessQueryRECID = UserAccesss.UserAccess
                                                       .ToList()
                                                       .Last();

                    UpdateDbMethod.UpdateLogOutTime(dataFromUserAccessQueryRECID, dataFromUSERLOGQueryLOGOUT);
                    //Update LogOut Time
                    //var _time = new UserAccessDbContent() { Id = dataFromUserAccessQueryRECID.Id, LogOut = dataFromUSERLOGQueryLOGOUT.LOGOUTDATETIME };
                    //
                    //using (var newContext = new UserAccessDbContext())
                    //{
                    //    newContext.UserAccess.Attach(_time);
                    //    newContext.Entry(_time).Property(x => x.LogOut).IsModified = true;
                    //    newContext.SaveChanges();
                    //}


                    DynamicsAxApplication axComClient = new DynamicsAxApplication();
                    axComClient.OpenMenuItem(NameOfCompany, GlobalConstants.AxFormOpenSYSUSERINFOPAGE, AxClientLib.AxMenuType.DisplayMenu);
                    ProcessKiller.KillProcessByNameAndUser(GlobalConstants.AxProcessWork, Environment.UserName, 0);

                    submitBtnWasClickedAndAxIsOpen = false;

                    DisableFunctionalityOfExitBtn.EnableCloseButton(Handle);
                    discriptionBox.ReadOnly = false;

                    Validations.ClearDiscriptionText(discriptionBox);
                }
                else
                {
                    DisableFunctionalityOfExitBtn.DisableCloseButton(Handle);
                    discriptionBox.ReadOnly = true;
                }
            }
        }