Beispiel #1
0
        private bool check_sertificate_active(string sertificate_code)
        {
            bool result = true;

            Cash8.DS.DS ds = MainStaticClass.get_ds();
            ds.Timeout = 60000;
            //Получить параметр для запроса на сервер
            string nick_shop = MainStaticClass.Nick_Shop.Trim();

            if (nick_shop.Trim().Length == 0)
            {
                MessageBox.Show(" Не удалось получить название магазина ");
                return(false);
            }
            string code_shop = MainStaticClass.Code_Shop.Trim();

            if (code_shop.Trim().Length == 0)
            {
                MessageBox.Show(" Не удалось получить код магазина ");
                return(false);
            }
            string count_day = CryptorEngine.get_count_day();
            string key       = nick_shop.Trim() + count_day.Trim() + code_shop.Trim();
//            string sertificate_code = get_tovar_code(barcode);
            string encrypt_data = CryptorEngine.Encrypt(sertificate_code, true, key);
            string status       = "-1";

            try
            {
                status = ds.GetStatusSertificat(MainStaticClass.Nick_Shop, encrypt_data);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (status == "-1")
            {
                MessageBox.Show("Произошли ошибки при работе с сертификатами");
                return(false);
            }
            else
            {
                string decrypt_data = CryptorEngine.Decrypt(status, true, key);
                if (decrypt_data != "1")
                {
                    MessageBox.Show("Сертификат с кодом " + sertificate_code + " не активирован");
                    result = false;
                }
            }

            //if (result) //проверим в локальной базе
            //{
            //    NpgsqlConnection conn = MainStaticClass.NpgsqlConn();
            //    try
            //    {
            //        conn.Open();
            //        string query = "SELECT is_active FROM sertificates WHERE code_tovar="+sertificate_code;
            //        NpgsqlCommand command = new NpgsqlCommand(query, conn);
            //        object result_query = command.ExecuteScalar();
            //        if(result_query!=null)
            //        {
            //            if(result_query.ToString()!="1")
            //            {
            //                MessageBox.Show(" Произошли ошибки при определении cтатуса сертификата в локальной базе, необходимо обновить данные через интернет");
            //                result=false;
            //            }
            //        }
            //        else
            //        {
            //            result=false;
            //        }
            //    }
            //    catch (NpgsqlException ex)
            //    {
            //        MessageBox.Show(" Произошли ошибки при определении мтатуса сертификата в локальной базе " + ex.Message + " | " + ex.Detail);
            //        result = false;
            //    }
            //    catch (Exception ex)
            //    {
            //        MessageBox.Show(" Произошли ошибки при определении мтатуса сертификата в локальной базе " + ex.Message);
            //        result = false;
            //    }
            //    finally
            //    {
            //        if (conn.State == ConnectionState.Open)
            //        {
            //            conn.Close();
            //        }
            //    }
            //}

            return(result);
        }
Beispiel #2
0
        public void check_new_version_programm()
        {
            if (!MainStaticClass.service_is_worker())
            {
                return;
            }

            Cash8.DS.DS ds = MainStaticClass.get_ds();
            ds.Timeout = 50000;

            //Получить параметра для запроса на сервер
            string nick_shop = MainStaticClass.Nick_Shop.Trim();

            if (nick_shop.Trim().Length == 0)
            {
                return;
            }

            string code_shop = MainStaticClass.Code_Shop.Trim();

            if (code_shop.Trim().Length == 0)
            {
                return;
            }

            string count_day = CryptorEngine.get_count_day();

            string key              = nick_shop.Trim() + count_day.Trim() + code_shop.Trim();
            string data             = code_shop.Trim() + "|" + MainStaticClass.version() + "|" + code_shop.Trim();
            string result_web_query = "";

            try
            {
                result_web_query = ds.ExistsUpdateProrgam(nick_shop, CryptorEngine.Encrypt(data, true, key));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            if (result_web_query == "")
            {
                label_update.Text = "Не удалось проверить версию программы на сервере";
            }
            else// (result_web_query != "")
            {
                result_web_query = CryptorEngine.Decrypt(result_web_query, true, key);

                if (MainStaticClass.version() == result_web_query)
                {
                    label_update.Text = " У вас установлена самая последняя версия программы ";
                }
                else
                {
                    //это старое решение по контролю версий
                    version = result_web_query;
                    //result_web_query = result_web_query.Replace(".", "");
                    //string my_version = result_web_query.Substring(0, 2) + "-" + result_web_query.Substring(2, 2) + "-" + result_web_query.Substring(4, 4);
                    //label_update.Text = "Есть обновление программы от " + my_version;
                    //btn_download.Enabled = true;
                    //new_version_of_the_program = true;

                    //это новое решение по контролю версий
                    //здесь наверное надо установить проверку на больше меньше по версиям
                    Int64 local_version  = Convert.ToInt64(MainStaticClass.version().Replace(".", ""));
                    Int64 remote_version = Convert.ToInt64(result_web_query.Replace(".", ""));
                    if (remote_version > local_version)
                    {
                        label_update.Text          = "Есть обновление программы " + result_web_query;
                        btn_download.Enabled       = true;
                        new_version_of_the_program = true;
                    }
                }
            }
        }
Beispiel #3
0
        private void btn_download_Click(object sender, EventArgs e)
        {
            check_and_update_npgsql();

            btn_close.Enabled = false;
            if (!MainStaticClass.service_is_worker())
            {
                return;
            }

            Cash8.DS.DS ds = MainStaticClass.get_ds();
            ds.Timeout = 50000;

            //Получить параметра для запроса на сервер
            string nick_shop = MainStaticClass.Nick_Shop.Trim();

            if (nick_shop.Trim().Length == 0)
            {
                return;
            }

            string code_shop = MainStaticClass.Code_Shop.Trim();

            if (code_shop.Trim().Length == 0)
            {
                return;
            }

            string count_day = CryptorEngine.get_count_day();

            string key = nick_shop.Trim() + count_day.Trim() + code_shop.Trim();
            //старая версия
            //string my_version = version.Substring(0, 2) + "-" + version.Substring(2, 2) + "-" + version.Substring(4, 4);
            string my_version = version;

            string data = code_shop.Trim() + "|" + version + "|" + code_shop.Trim();

            byte[] result_web_query = new byte[0];
            try
            {
                result_web_query = ds.GetUpdateProgram(nick_shop, CryptorEngine.Encrypt(data, true, key));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            if (result_web_query.Length > 10)
            {
                try
                {
                    if (!Directory.Exists(Application.StartupPath + "/Update"))
                    {
                        Directory.CreateDirectory(Application.StartupPath + "/Update");
                    }

                    File.WriteAllBytes(Application.StartupPath + "/Update/Cash.exe", result_web_query);

                    if (!Directory.Exists(Application.StartupPath + "/Previous"))
                    {
                        Directory.CreateDirectory(Application.StartupPath + "/Previous");
                    }

                    File.Copy(Application.StartupPath + "/Cash.exe", Application.StartupPath + "/Previous/Cash.exe", true);
                    //File.Copy(Application.StartupPath + "/Update/Cash.exe", Application.StartupPath + "/Cash.exe", true); При переходе на wine это не будет работать.
                    //update_execute_addcolumn();
                    //*********************************************************************** update_execute_addcolumn()
                    NpgsqlConnection conn = MainStaticClass.NpgsqlConn();

                    try
                    {
                        conn.Open();
                        string        query   = " UPDATE constants SET execute_addcolumn = 2 ";
                        NpgsqlCommand command = new NpgsqlCommand(query, conn);
                        command.ExecuteNonQuery();
                        conn.Close();
                    }
                    catch (NpgsqlException ex)
                    {
                        MessageBox.Show(" Ошибка при обновлении значения константы " + ex.Message);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(" Ошибка при обновлении значения константы " + ex.Message);
                    }
                    finally
                    {
                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }
                    //*********************************************************************** КОНЕЦ update_execute_addcolumn()
                    MessageBox.Show(" Обновление успешно загружено, теперь необходимо перезапустить программу ");
                    this.DialogResult = DialogResult.Yes;
                    this.Close();
                    //this.Dispose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(" При загрузке произошли ошибки " + ex.Message);
                }
            }

            btn_close.Enabled = true;
        }
Beispiel #4
0
        private void check_and_update_npgsql()
        {
            FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Application.StartupPath + "/Npgsql.dll");
            int             cash_version      = int.Parse(myFileVersionInfo.FileVersion.Replace(".", ""));

            if (cash_version == 20100)//Старая версия Npgsql
            {
                if (!Directory.Exists(Application.StartupPath + "/PreviousNpgsql"))
                {
                    Directory.CreateDirectory(Application.StartupPath + "/PreviousNpgsql");
                }

                if (!Directory.Exists(Application.StartupPath + "/UpdateNpgsql"))
                {
                    Directory.CreateDirectory(Application.StartupPath + "/UpdateNpgsql");
                }


                if (!MainStaticClass.service_is_worker())
                {
                    return;
                }

                Cash8.DS.DS ds = MainStaticClass.get_ds();
                ds.Timeout = 50000;

                //Получить параметра для запроса на сервер
                string nick_shop = MainStaticClass.Nick_Shop.Trim();
                if (nick_shop.Trim().Length == 0)
                {
                    return;
                }

                string code_shop = MainStaticClass.Code_Shop.Trim();
                if (code_shop.Trim().Length == 0)
                {
                    return;
                }

                string count_day = CryptorEngine.get_count_day();

                string key = nick_shop.Trim() + count_day.Trim() + code_shop.Trim();
                //старая версия
                //string my_version = version.Substring(0, 2) + "-" + version.Substring(2, 2) + "-" + version.Substring(4, 4);

                string data             = code_shop.Trim() + "|" + code_shop.Trim();
                byte[] result_web_query = new byte[0];
                try
                {
                    result_web_query = ds.GetNpgsqlNew(nick_shop, CryptorEngine.Encrypt(data, true, key));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }

                File.WriteAllBytes(Application.StartupPath + "/UpdateNpgsql/Npgsql.dll", result_web_query);

                try
                {
                    File.Copy(Application.StartupPath + "/Npgsql.dll", Application.StartupPath + "/PreviousNpgsql/Npgsql.dll", true);
                    if (File.ReadAllBytes(Application.StartupPath + "/UpdateNpgsql/Npgsql.dll").Length > 0)
                    {
                        File.Copy(Application.StartupPath + "/UpdateNpgsql/Npgsql.dll", Application.StartupPath + "/Npgsql.dll", true);
                        MessageBox.Show(" Библиотека Npgsql.dll успешно обновлена ");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                //                File.Copy(Application.StartupPath + "/UpdateNpgsql/Npgsql.dll", Application.StartupPath + "/Npgsql.dll", true);


                //Application.Exit();
            }
            //MessageBox.Show("check_and_update_npgsql");
        }
        public void send_sales_data_Click(object sender, EventArgs e)
        {
            if (MainStaticClass.get_unloading_interval() == 0)
            {
                return;
            }

            int documents_out_of_the_range_of_dates = MainStaticClass.get_documents_out_of_the_range_of_dates();

            if (documents_out_of_the_range_of_dates > 0 || documents_out_of_the_range_of_dates < 0)
            {
                return;
            }

            if (MainStaticClass.CashDeskNumber == 9)
            {
                return;
            }

            if (!its_sent_sertificate()) //не удалось отправить данные по сертификатам, отправка основных данных прервана
            {
                return;
            }

            if (!MainStaticClass.service_is_worker())
            {
                return;
            }

            Cash8.DS.DS ds = MainStaticClass.get_ds();
            ds.Timeout = 180000;

            //Получить параметра для запроса на сервер
            nick_shop = MainStaticClass.Nick_Shop.Trim();
            if (nick_shop.Trim().Length == 0)
            {
                return;
            }
            string code_shop = MainStaticClass.Code_Shop.Trim();

            if (code_shop.Trim().Length == 0)
            {
                return;
            }
            string count_day = CryptorEngine.get_count_day();

            salesPortions         = new SalesPortions();
            salesPortions.Shop    = nick_shop;
            salesPortions.Guid    = code_shop;
            salesPortions.Version = MainStaticClass.version().Replace(".", "");
            get_data_on_salaes();
            if (were_mistakes)//Произошли какие то ошибки при выгрузке
            {
                return;
            }
            if ((salesPortions.ListSalesPortionsHeader.Count == 0) || (salesPortions.ListSalesPortionsTable.Count == 0))
            {
                return;
            }
            string key             = nick_shop.Trim() + count_day.Trim() + code_shop.Trim();
            bool   result_web_quey = false;
            string data            = JsonConvert.SerializeObject(salesPortions, Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            string data_crypt = CryptorEngine.Encrypt(data, true, key);

            try
            {
                result_web_quey = ds.UploadDataOnSalesPortionJason(nick_shop, data_crypt);
            }
            catch (Exception ex)
            {
                write_error(ex.Message);
            }

            if (result_web_quey)
            {
                update_status_is_sent();
            }
        }
        /// <summary>
        /// Попытка отправить данные о проданных и погашенных сертификатах
        /// Получаем список документов не отправленных
        ///
        /// </summary>
        /// <returns></returns>
        private bool its_sent_sertificate()
        {
            bool result = true;

            //Заполняем спиок номеров документов которые не отправлены
            if (!get_document_list_not_sent())
            {
                result = false;
                return(result);
            }
            if (document_number_list.ToString().Length == 0)
            {
                result = false;
                return(result);
            }
            //Список нормально заполнился
            string data = get_not_sent_sertificates();

            if (data == "-1")
            {
                result = false;
                return(result);
            }
            if (data != "")// есть данные по сертификатам
            {
                if (!MainStaticClass.service_is_worker())
                {
                    result = false;
                    return(result);
                }

                Cash8.DS.DS ds = MainStaticClass.get_ds();
                ds.Timeout = 60000;

                //Получить параметра для запроса на сервер
                nick_shop = MainStaticClass.Nick_Shop.Trim();
                if (nick_shop.Trim().Length == 0)
                {
                    result = false;
                    return(result);
                }

                string code_shop = MainStaticClass.Code_Shop.Trim();
                if (code_shop.Trim().Length == 0)
                {
                    result = false;
                    return(result);
                }

                string count_day = CryptorEngine.get_count_day();

                string key              = nick_shop.Trim() + count_day.Trim() + code_shop.Trim();
                string encrypt_string   = CryptorEngine.Encrypt(data, true, key);
                string result_web_query = ds.SetStatusSertificat(nick_shop, encrypt_string);
                if (result_web_query == "-1")
                {
                    result = false;
                    return(result);
                }
            }


            return(result);
        }