Beispiel #1
0
        ////---Метод: Возвращает из базы данных Единицы измерения----------------------------------------------------------
        //public static ArrayList GetUnits()
        //{
        //    ArrayList list = new ArrayList();
        //    using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = connect.CreateCommand(); // Создание команды
        //            command.CommandText = "SELECT [Unit] FROM [dbo].[Units]"; // Текст команды
        //            SqlDataReader reading = command.ExecuteReader();

        //            while (reading.Read())
        //            {
        //                list.Add(reading.GetValue(0).ToString());
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "Пиздец кароче нахуй блядь!");
        //        }
        //    }
        //    return list;
        //}

        ////---Метод: Возвращает из базы данных Типы Штрих кодов----------------------------------------------------------
        //public static ArrayList GetBarcodeTypes()
        //{
        //    ArrayList list = new ArrayList();
        //    using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = connect.CreateCommand(); // Создание команды
        //            command.CommandText = "SELECT [TypeName] FROM [dbo].[BarсodeTypes] ORDER BY [TypeName]"; // Текст команды
        //            SqlDataReader reading = command.ExecuteReader();

        //            while (reading.Read())
        //            {
        //                list.Add(reading.GetValue(0).ToString());
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "Пиздец кароче нахуй блядь!");
        //        }
        //    }
        //    return list;
        //}


        ////---Метод: Возвращает из базы данных Страны происхождения-------------------------------------------------------
        //public static ArrayList GetCountry()
        //{
        //    ArrayList list = new ArrayList();
        //    using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = connect.CreateCommand(); // Создание команды
        //            command.CommandText = "SELECT [CountryName] FROM [dbo].[Country] ORDER By [CountryName]"; // Текст команды
        //            SqlDataReader reading = command.ExecuteReader();

        //            while (reading.Read())
        //            {
        //                list.Add(reading.GetValue(0).ToString());
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "Пиздец кароче нахуй блядь!");
        //        }
        //    }
        //    return list;
        //}


        ////---Метод: Загружает все свойства номенклатуры (ХП)-------------------------------------------------------------
        //public static ArrayList GetAllNomenProperties()
        //{
        //    ArrayList list = new ArrayList();
        //    using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = new SqlCommand("GetAllNomenProperties", connect);
        //            command.CommandType = CommandType.StoredProcedure;

        //            SqlDataReader reading = command.ExecuteReader();

        //            while (reading.Read())
        //            {
        //                list.Add(reading.GetValue(0).ToString());
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "GetAllNomenProperties");
        //        }
        //    }
        //    return list;
        //}

        ////---Метод: Загружает все значения свойства номенклатуры (ХП)----------------------------------------------------
        //public static ArrayList GetAllNomenPropertyValues(string PropertyName)
        //{
        //    ArrayList list = new ArrayList();
        //    using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = new SqlCommand("GetPropertyValues", connect);
        //            command.CommandType = CommandType.StoredProcedure;

        //            SqlParameter Param0 = new SqlParameter { ParameterName = "@PropertyName", Value = PropertyName }; //---Передаваемый параметр
        //            command.Parameters.Add(Param0);

        //            command.ExecuteNonQuery();

        //            SqlDataReader reading = command.ExecuteReader();

        //            while (reading.Read())
        //            {
        //                list.Add(reading.GetValue(0).ToString());
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "GetAllNomenPropertyValues");
        //        }
        //    }
        //    return list;
        //}



        ////---Метод: Создание новой номенклатуры (Основные данные + штрих-код базовой единицы) (ХП)---------------------------------------------------------------------
        //public static bool CreateNewNomenclature(NomenclatureClass Nomen)
        //{
        //    bool ok = false;
        //    using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        //try
        //        //{
        //        connect.Open();
        //        SqlCommand command = new SqlCommand("CreateNewNomenclature", connect);
        //        command.CommandType = CommandType.StoredProcedure;

        //        SqlParameter Param0 = new SqlParameter { ParameterName = "@ID", Value = Nomen.ID };// Новый ID //---Передаваемый параметр
        //        command.Parameters.Add(Param0);

        //        SqlParameter Param1 = new SqlParameter { ParameterName = "@GroupID", Value = Nomen.GroupID }; //---Передаваемый параметр
        //        command.Parameters.Add(Param1);

        //        SqlParameter Param2 = new SqlParameter { ParameterName = "@Aricle", Value = Nomen.Article }; //---Передаваемый параметр
        //        command.Parameters.Add(Param2);

        //        SqlParameter Param3 = new SqlParameter { ParameterName = "@NomenclatureName", Value = Nomen.Name }; //---Передаваемый параметр
        //        command.Parameters.Add(Param3);

        //        SqlParameter Param4 = new SqlParameter { ParameterName = "@BaseUnitName", Value = Nomen.BaseUnit }; //---Передаваемый параметр
        //        command.Parameters.Add(Param4);

        //        SqlParameter Param5 = new SqlParameter { ParameterName = "@CountryOfOriginName", Value = Nomen.CountryOfOrigin }; //---Передаваемый параметр
        //        command.Parameters.Add(Param5);

        //        SqlParameter Param6 = new SqlParameter { ParameterName = "@BaseUnitWeight", Value = Nomen.WeightBaseUnit }; //---Передаваемый параметр
        //        command.Parameters.Add(Param6);

        //        SqlParameter Param11 = new SqlParameter { ParameterName = "@Barcode", Value = Nomen.Barcode }; //---Передаваемый параметр
        //        command.Parameters.Add(Param11);

        //        SqlParameter Param12 = new SqlParameter { ParameterName = "@BarcodeType", Value = Nomen.BarcodeType }; //---Передаваемый параметр
        //        command.Parameters.Add(Param12);

        //        SqlParameter Param13 = new SqlParameter { ParameterName = "@Description", Value = Nomen.Description }; //---Передаваемый параметр
        //        command.Parameters.Add(Param13);

        //        command.Parameters.Add("@Result", SqlDbType.Bit).Direction = ParameterDirection.Output; // Выходной параметр

        //        command.ExecuteNonQuery();

        //        ok = (bool)command.Parameters["@Result"].Value;
        //        //}
        //        //catch (Exception ex)
        //        //{
        //        //    MessageBox.Show(ex.Message, "DataBaseRequest.CreateNewNomenclature");
        //        //}
        //        return ok;
        //    }
        //}


        ////---Метод: Создание новой номенклатуры (Дополнительные единицы измерения + штрих-коды)(ХП)---------------------------------------------------------------------
        //public static bool CreateAdditionalUnits(AdditionalUnitsClass AUC)
        //{
        //    bool ok = false;
        //    using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = new SqlCommand("CreateAdditionalUnits", connect);
        //            command.CommandType = CommandType.StoredProcedure;

        //            SqlParameter Param0 = new SqlParameter { ParameterName = "@ID", Value = AUC.ID };// Новый ID //---Передаваемый параметр
        //            command.Parameters.Add(Param0);

        //            SqlParameter Param1 = new SqlParameter { ParameterName = "@NomenclatureID", Value = AUC.NomenclatureID };// Новый ID //---Передаваемый параметр
        //            command.Parameters.Add(Param1);

        //            SqlParameter Param2 = new SqlParameter { ParameterName = "@UnitName", Value = AUC.AddUnitName }; //---Передаваемый параметр
        //            command.Parameters.Add(Param2);


        //            SqlParameter Param3 = new SqlParameter { ParameterName = "@BarcodeType", Value = AUC.BarcodeType }; //---Передаваемый параметр
        //            command.Parameters.Add(Param3);

        //            SqlParameter Param4 = new SqlParameter { ParameterName = "@Barcode", Value = AUC.Barcode }; //---Передаваемый параметр
        //            command.Parameters.Add(Param4);


        //            SqlParameter Param5 = new SqlParameter { ParameterName = "@Quantity", Value = AUC.Quantity }; //---Передаваемый параметр
        //            command.Parameters.Add(Param5);

        //            SqlParameter Param6 = new SqlParameter { ParameterName = "@Weight", Value = AUC.Weight }; //---Передаваемый параметр
        //            command.Parameters.Add(Param6);


        //            command.Parameters.Add("@Result", SqlDbType.Bit).Direction = ParameterDirection.Output; // Выходной параметр

        //            command.ExecuteNonQuery();

        //            ok = (bool)command.Parameters["@Result"].Value;
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "DataBaseRequest.CreateAdditionalUnits");
        //        }
        //        return ok;
        //    }
        //}


        ////---Метод: Создание новой номенклатуры (Свойства и значения) (ХП)---------------------------------------------------------------------
        //public static bool CreateNomenProperties(NomenPropertyClass NPC)
        //{
        //    bool ok = false;
        //    using (SqlConnection connect = new SqlConnection(Crypt.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = new SqlCommand("CreateNomenProperties", connect);
        //            command.CommandType = CommandType.StoredProcedure;

        //            SqlParameter Param0 = new SqlParameter { ParameterName = "@NomenclatureID", Value = NPC.ID };// Новый ID //---Передаваемый параметр
        //            command.Parameters.Add(Param0);

        //            SqlParameter Param1 = new SqlParameter { ParameterName = "@ValueName", Value = NPC.ValueName }; //---Передаваемый параметр
        //            command.Parameters.Add(Param1);

        //            SqlParameter Param2 = new SqlParameter { ParameterName = "@PropertyName", Value = NPC.PropertyName }; //---Передаваемый параметр
        //            command.Parameters.Add(Param2);


        //            command.Parameters.Add("@Result", SqlDbType.Bit).Direction = ParameterDirection.Output; // Выходной параметр

        //            command.ExecuteNonQuery();

        //            ok = (bool)command.Parameters["@Result"].Value;
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "DataBaseRequest.CreateNomenProperties");
        //        }
        //        return ok;
        //    }
        //}


        ////---Метод: Создание новой номенклатуры (изображения) (ХП)---------------------------------------------------------------------
        //public static bool CreateNomenImages(Guid NomenclatureID, byte[] imageData, string Description, bool MainImage)
        //{
        //    bool ok = false;
        //    using (SqlConnection connect = new SqlConnection(Crypt.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = new SqlCommand("CreateNomenImages", connect);
        //            command.CommandType = CommandType.StoredProcedure;

        //            SqlParameter Param0 = new SqlParameter { ParameterName = "@NomenclatureID", Value = NomenclatureID };// Новый ID //---Передаваемый параметр
        //            command.Parameters.Add(Param0);

        //            SqlParameter Param1 = new SqlParameter { ParameterName = "@Image", Value = imageData };// Новый ID //---Передаваемый параметр
        //            command.Parameters.Add(Param1);

        //            SqlParameter Param2 = new SqlParameter { ParameterName = "@Description", Value = Description }; //---Передаваемый параметр
        //            command.Parameters.Add(Param2);

        //            SqlParameter Param3 = new SqlParameter { ParameterName = "@MainImage", Value = MainImage }; //---Передаваемый параметр
        //            command.Parameters.Add(Param3);


        //            command.Parameters.Add("@Result", SqlDbType.Bit).Direction = ParameterDirection.Output; // Выходной параметр

        //            command.ExecuteNonQuery();

        //            ok = (bool)command.Parameters["@Result"].Value;
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "DataBaseRequest.CreateNomenProperties");
        //        }
        //        return ok;
        //    }
        //}


        ////---Метод: Создание новой группы номенклатуры (ХП)---------------------------------------------------------------------
        //public static bool CreateNomenclatureGroup(NomenclatureClass NC)
        //{
        //    bool ok = false;
        //    using (SqlConnection connect = new SqlConnection(Crypt.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = new SqlCommand("CreateNomenclatureGroup", connect);
        //            command.CommandType = CommandType.StoredProcedure;

        //            SqlParameter Param0 = new SqlParameter { ParameterName = "@ID", Value = NC.ID };// Новый ID //---Передаваемый параметр
        //            command.Parameters.Add(Param0);

        //            SqlParameter Param1 = new SqlParameter { ParameterName = "@GroupID", Value = NC.GroupID }; //---Передаваемый параметр
        //            command.Parameters.Add(Param1);

        //            SqlParameter Param2 = new SqlParameter { ParameterName = "@GroupName", Value = NC.Name }; //---Передаваемый параметр
        //            command.Parameters.Add(Param2);

        //            SqlParameter Param3 = new SqlParameter { ParameterName = "@GroupNonen", Value = NC.GroupNomen }; //---Передаваемый параметр
        //            command.Parameters.Add(Param3);


        //            command.Parameters.Add("@Result", SqlDbType.Bit).Direction = ParameterDirection.Output; // Выходной параметр

        //            command.ExecuteNonQuery();

        //            ok = (bool)command.Parameters["@Result"].Value;
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "DataBaseRequest.CreateNomenclatureGroup");
        //        }
        //        return ok;
        //    }
        //}

        ////---Метод: Изменение группы номенклатуры (ХП)---------------------------------------------------------------------
        //public static bool UpdateNomenclatureGroup(NomenclatureClass NC)
        //{
        //    bool ok = false;
        //    using (SqlConnection connect = new SqlConnection(Crypt.Decrypt(XmlClass.GetSelectedConnectionString())))
        //    {
        //        try
        //        {
        //            connect.Open();
        //            SqlCommand command = new SqlCommand("UpdateNomenclatureGroup", connect);
        //            command.CommandType = CommandType.StoredProcedure;

        //            SqlParameter Param0 = new SqlParameter { ParameterName = "@ID", Value = NC.ID };// Новый ID //---Передаваемый параметр
        //            command.Parameters.Add(Param0);
        //            SqlParameter Param2 = new SqlParameter { ParameterName = "@GroupName", Value = NC.Name }; //---Передаваемый параметр
        //            command.Parameters.Add(Param2);

        //            command.Parameters.Add("@Result", SqlDbType.Bit).Direction = ParameterDirection.Output; // Выходной параметр

        //            command.ExecuteNonQuery();

        //            ok = (bool)command.Parameters["@Result"].Value;
        //        }
        //        catch (Exception ex)
        //        {
        //            MessageBox.Show(ex.Message, "DataBaseRequest.UpdateNomenclatureGroup");
        //        }
        //        return ok;
        //    }
        //}


        //---Метод: Вырезать/Вставить (ХП)---------------------------------------------------------------------
        public static bool UpdateGroupID(Guid ID, Guid GroupID)
        {
            bool ok = false;

            using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
            {
                try
                {
                    connect.Open();
                    SqlCommand command = new SqlCommand("UpdateGroupID", connect);
                    command.CommandType = CommandType.StoredProcedure;

                    SqlParameter Param0 = new SqlParameter {
                        ParameterName = "@ID", Value = ID
                    };
                    command.Parameters.Add(Param0);
                    SqlParameter Param1 = new SqlParameter {
                        ParameterName = "@GroupID", Value = GroupID
                    };
                    command.Parameters.Add(Param1);

                    command.Parameters.Add("@Result", SqlDbType.Bit).Direction = ParameterDirection.Output;

                    command.ExecuteNonQuery();

                    ok = (bool)command.Parameters["@Result"].Value;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "DataBaseRequest.UpdateGroupID");
                }
                return(ok);
            }
        }
Beispiel #2
0
        //---Метод: Получение названия интерфейса для пользователя (ХП)-------------------------------------------------
        public static string GetUserInterfaceName(string Login)
        {
            string UserInterfaceName = "";

            using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
            {
                try
                {
                    connect.Open();
                    SqlCommand command = new SqlCommand("GetUserInterface", connect);
                    command.CommandType = CommandType.StoredProcedure;

                    SqlParameter Param1 = new SqlParameter {
                        ParameterName = "@Login", Value = Login
                    };
                    command.Parameters.Add(Param1);


                    UserInterfaceName = command.ExecuteScalar().ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            return(UserInterfaceName);
        }
Beispiel #3
0
        //---Метод: Возвращает строку подключения из Config файла------------------------------------------------------------
        public static string GetSelectedConnectionString()
        {
            string ConnString = null;

            try
            {
                CreateConfigFile();
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")
                    {
                        foreach (XmlNode xnode in El)
                        {
                            XmlNode XSelect = xnode.Attributes.GetNamedItem("Selected");
                            if (Cryption.Decrypt(XSelect.Value) == "Y")
                            {
                                XmlNode CS = xnode.Attributes.GetNamedItem("ConnString");
                                ConnString = CS.Value;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "XmlClass.GetSelectedConnectionString()");
            }

            return(ConnString);
        }
Beispiel #4
0
        //---Метод: Читает и возвращает список названий подключений----------------------------------------------------------
        public static ArrayList ReadAllConnectionsName()
        {
            ArrayList list = new ArrayList();

            try
            {
                CreateConfigFile();
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement Element in RootElement)
                {
                    if (Element.Name == "Connections")
                    {
                        foreach (XmlNode xnode in Element)
                        {
                            XmlNode XName = xnode.Attributes.GetNamedItem("Name");
                            list.Add(Cryption.Decrypt(XName.Value));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "XmlClass.ReadAllConnectionsName()");
            }
            return(list);
        }
Beispiel #5
0
        //---Метод: Отмечает все подключения как НЕвыбранный-----------------------------------------------------------------
        public static void DeSelectAllConnections()
        {
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")      // Если имя элемента "Connections"
                    {
                        foreach (XmlNode childnode in El.ChildNodes)
                        {
                            if (childnode.Name == "Connection")
                            {
                                childnode.Attributes[0].Value = Cryption.Encrypt("N");
                            }
                        }
                    }
                }
                document.Save(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "XmlClass.DeSelectAllConnections()");
            }
        }
Beispiel #6
0
        //---Метод: Удаляет подключение из Config файла----------------------------------------------------------------------
        public static void DeleteConnection(string ConnectionName)
        {
            try
            {
                //DeSelectAllConnections();
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")      // Если имя элемента "Connections"
                    {
                        foreach (XmlNode childnode in El.ChildNodes)
                        {
                            if (childnode.Name == "Connection")
                            {
                                XmlNode атрибут = childnode.Attributes.GetNamedItem("Name");

                                if (Cryption.Decrypt(атрибут.Value) == ConnectionName) // Если "Название" равно "Осень"
                                {
                                    El.RemoveChild(childnode);
                                }
                            }
                        }
                    }
                }
                document.Save(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "XmlClass.DeleteConnection(string ConnectionName)");
            }
        }
Beispiel #7
0
        public static ObservableCollection <NomenclatureClass> GetAllNomenclaturesBack(ref Guid GroupID, ref Guid ID)
        {
            ObservableCollection <NomenclatureClass> list = new ObservableCollection <NomenclatureClass>();

            using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
            {
                try
                {
                    connect.Open();
                    SqlCommand command = new SqlCommand("GetAllNomenclaturesBack", connect);
                    command.CommandType = CommandType.StoredProcedure;

                    SqlParameter Param0 = new SqlParameter {
                        ParameterName = "@GroupID", Value = GroupID
                    };                                                                                      //---Передаваемый параметр
                    command.Parameters.Add(Param0);

                    SqlDataReader reading = command.ExecuteReader();

                    while (reading.Read())
                    {
                        NomenclatureClass NC = new NomenclatureClass();
                        NC.ID         = (Guid)reading.GetValue(0);
                        NC.GroupID    = (Guid)reading.GetValue(1);
                        NC.GroupNomen = (bool)reading.GetValue(2);

                        NC.Name = reading.GetValue(4).ToString();

                        if (NC.GroupNomen == true)
                        {
                            NC.Article         = reading.GetValue(3).ToString();
                            NC.BaseUnit        = reading.GetValue(5).ToString();
                            NC.WeightBaseUnit  = Convert.ToDouble(reading.GetValue(6));
                            NC.BarcodeType     = reading.GetValue(7).ToString();
                            NC.Barcode         = reading.GetValue(8).ToString();
                            NC.CountryOfOrigin = reading.GetValue(9).ToString();
                            NC.Description     = reading.GetValue(10).ToString();
                            NC.Aksia           = (bool)reading.GetValue(11);
                            NC.Focus           = (bool)reading.GetValue(12);
                            NC.New             = (bool)reading.GetValue(13);
                        }
                        list.Add(NC);
                        GroupID = (Guid)reading.GetValue(14);
                        ID      = (Guid)reading.GetValue(15);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка в методе: DataBaseRequest.GetAllNomenclatures" + "\n" + ex.Message, "Хуёво!");
                }
            }
            return(list);
        }
Beispiel #8
0
        //---Метод: Отмечает подключение как выбранный-----------------------------------------------------------------------
        public static void SetSelectConnection(string ConnectionName)
        {
            try
            {
                DeSelectAllConnections();
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")      // Если имя элемента "Connections"
                    {
                        foreach (XmlNode childnode in El.ChildNodes)
                        {
                            if (childnode.Name == "Connection")
                            {
                                XmlNode атрибут = childnode.Attributes.GetNamedItem("Name");

                                if (Cryption.Decrypt(атрибут.Value) == ConnectionName) // Если "Название" равно
                                {
                                    childnode.Attributes[0].Value = Cryption.Encrypt("Y");
                                }
                            }
                        }
                    }
                }
                document.Save(path);
            }
            catch (Exception ex)
            {
                //if (MessageBox.Show("Close Application?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                //{
                //    //do no stuff
                //}
                //else
                //{
                //    //do yes stuff
                //}

                MessageBox.Show(ex.Message, "SetSelectConnection(string ConnectionName)");
            }
        }
Beispiel #9
0
        //---Добавление Параметра подключения--------------------------------------------------------------------------------
        public static bool CreateConnectionString(string Name, string ConnectionString)
        {
            bool flag = false;

            try
            {
                CreateConfigFile();
                DeSelectAllConnections();

                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlNode xnode in RootElement)
                {
                    if (xnode.Name == "Connections")
                    {
                        XmlNode Connection = document.CreateElement("Connection");

                        XmlAttribute Selected = document.CreateAttribute("Selected");
                        Selected.Value = Cryption.Encrypt("Y");
                        Connection.Attributes.Append(Selected);

                        XmlAttribute ConnName = document.CreateAttribute("Name");
                        ConnName.Value = Cryption.Encrypt(Name);
                        Connection.Attributes.Append(ConnName);

                        XmlAttribute connectionString = document.CreateAttribute("ConnString");
                        connectionString.Value = Cryption.Encrypt(ConnectionString);
                        Connection.Attributes.Append(connectionString);

                        xnode.AppendChild(Connection);
                    }
                }
                document.Save(path);
                flag = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "AddConnectSetting(string Name, string ConnectionString)");
            }
            return(flag);
        }
Beispiel #10
0
        //---Метод: Проверка авторизации (ХП)---------------------------------------------------------------------------
        public static bool CheckAuthorization(string login, string password, ref string message)
        {
            bool ok = false;

            using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
            {
                try
                {
                    connect.Open();
                    SqlCommand command = new SqlCommand("CheckAuthorization", connect);
                    command.CommandType = CommandType.StoredProcedure;

                    SqlParameter Param1 = new SqlParameter {
                        ParameterName = "@Login", Value = login
                    };
                    command.Parameters.Add(Param1);

                    SqlParameter Param2 = new SqlParameter {
                        ParameterName = "@Password", Value = password
                    };
                    command.Parameters.Add(Param2);

                    int result = Convert.ToInt32(command.ExecuteScalar());

                    if (result == 1)
                    {
                        ok = true;
                    }
                    else
                    {
                        ok      = false;
                        message = "Хуёвый логин или пароль.";
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message.ToString();
                }
            }
            return(ok);
        }
Beispiel #11
0
        //---Метод: Возвращает название "выбранной" строки подключения из Config файла---------------------------------------
        public static string GetSelectedConnectionName()
        {
            CreateConfigFile();

            string ConnName = "";

            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")      // Если имя элемента "Книга"
                    {
                        foreach (XmlNode xnode in El)
                        {
                            XmlNode XSelect = xnode.Attributes.GetNamedItem("Selected");
                            if (Cryption.Decrypt(XSelect.Value) == "Y")
                            {
                                XmlNode CS = xnode.Attributes.GetNamedItem("Name");
                                ConnName = Cryption.Decrypt(CS.Value);
                            }
                        }
                    }
                }
            }
            catch
            {
                if (MessageBox.Show("Ошибка чтения файла конфигурации.\nУдалить ошибочный файл и создать новый файл конфигурации?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    File.Delete(@"C:\Users\" + Environment.UserName + @"\Documents\Control Systems\Config.xml");
                    CreateConfigFile();

                    MessageBox.Show("Создан новый файл конфигурации.\nСоздайте новое подключение.", "XmlClass.GetSelectedConnectionName()"); // Вывод сообщения об ошибке
                }
            }
            return(ConnName);
        }
Beispiel #12
0
        //---Метод: Проверяет не создана ли подключение с таким названием----------------------------------------------------
        public static bool CheckConnectionName(string ConnectionName)
        {
            CreateConfigFile();
            bool flag = false;

            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")
                    {
                        foreach (XmlNode childnode in El.ChildNodes)
                        {
                            if (childnode.Name == "Connection")
                            {
                                XmlNode атрибут = childnode.Attributes.GetNamedItem("Name");

                                if (Cryption.Decrypt(атрибут.Value) == ConnectionName)
                                {
                                    flag = true;
                                }
                            }
                        }
                    }
                }
                return(flag);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "XmlClass.CheckConnectionName(string ConnectionName)");
                return(false);
            }
        }
Beispiel #13
0
        //---Метод: Создание новой номенклатуры (ХП)---------------------------------------------------------------------
        public static bool UpdateTagNew(NomenclatureClass Nomen)
        {
            bool ok = false;

            using (SqlConnection connect = new SqlConnection(Cryption.Decrypt(XmlClass.GetSelectedConnectionString())))
            {
                try
                {
                    connect.Open();
                    SqlCommand command = new SqlCommand("UpdateTagNew", connect);
                    command.CommandType = CommandType.StoredProcedure;

                    SqlParameter Param0 = new SqlParameter {
                        ParameterName = "@NomenID", Value = Nomen.ID
                    };                                                                                      // Новый ID //---Передаваемый параметр
                    command.Parameters.Add(Param0);

                    SqlParameter Param1 = new SqlParameter {
                        ParameterName = "@Checked", Value = Nomen.New
                    };                                                                                        //---Передаваемый параметр
                    command.Parameters.Add(Param1);


                    command.Parameters.Add("@Result", SqlDbType.Bit).Direction = ParameterDirection.Output; // Выходной параметр

                    command.ExecuteNonQuery();

                    ok = (bool)command.Parameters["@Result"].Value;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "DataBaseRequest.UpdateTagAksia");
                }
                return(ok);
            }
        }