This repository has been archived by the owner on Nov 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolay B. aka RD_AAOW
committed
May 12, 2020
1 parent
569b949
commit 85ef7e0
Showing
25 changed files
with
3,243 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Text to KKT changes log | ||
|
||
Version 2.5u: | ||
• Application namespace, icon and development environment have been unified; | ||
• Android version of application has been implemented (awaits release); | ||
• Publication on GitHub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
# TextToKKT | ||
# TextToKKT 2.5u | ||
|
||
An utility for encoding text strings to KKT codes / Утилита для преобразования строк текста в коды ККТ (54-ФЗ) | ||
|
||
# | ||
|
||
Инструмент позволяет вручную (без использования клавиатуры) программировать текстовые данные | ||
в контрольно-кассовой технике (54-ФЗ), имеющей только цифровую клавиатуру | ||
|
||
# | ||
|
||
We've formalized our [Applications development policy (ADP)](https://vk.com/@rdaaow_fupl-adp). | ||
We're strongly recommend reading it before using our products. | ||
|
||
Мы формализовали нашу [Политику разработки приложений (ADP)](https://vk.com/@rdaaow_fupl-adp). | ||
Настоятельно рекомендуем ознакомиться с ней перед использованием наших продуктов. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace RD_AAOW | ||
{ | ||
/// <summary> | ||
/// Класс обеспечивает доступ к кодам символов ККМ | ||
/// </summary> | ||
public class KKMCodes | ||
{ | ||
// Переменные | ||
private List<string> names = new List<string> (); | ||
private List<List<int>> codes = new List<List<int>> (); | ||
private List<string> presentations = new List<string> (); | ||
private List<string> descriptions = new List<string> (); | ||
|
||
/// <summary> | ||
/// Код, возвращаемый при указании некорректных параметров в методах GetErrorCode | ||
/// и GetErrorText | ||
/// </summary> | ||
public const string EmptyCode = "\x7"; | ||
|
||
/// <summary> | ||
/// Конструктор. Инициализирует таблицы кодов | ||
/// </summary> | ||
public KKMCodes () | ||
{ | ||
// Получение файла ошибок | ||
byte[] s = Properties.TextToKKMResources.Codes; | ||
string buf = Encoding.GetEncoding (1251).GetString (s); | ||
StringReader SR = new StringReader (buf); | ||
|
||
// Формирование массива | ||
string str; | ||
uint line = 0; | ||
try | ||
{ | ||
while ((str = SR.ReadLine ()) != null) | ||
{ | ||
// Чтение имени ККМ | ||
line++; | ||
names.Add (str); | ||
|
||
// Чтение кодов | ||
codes.Add (new List<int> ()); | ||
if (str != "——————————") | ||
{ | ||
for (int i = 0; i < 0x100; i++) | ||
{ | ||
str = SR.ReadLine (); // Любое недопустимое значение в этой строке вызовет исключение в следующей | ||
codes[codes.Count - 1].Add (int.Parse (str)); | ||
line++; | ||
} | ||
|
||
// Чтение представления | ||
presentations.Add (SR.ReadLine ()); | ||
line++; | ||
|
||
// Чтение примечания | ||
descriptions.Add (SR.ReadLine ()); | ||
line++; | ||
} | ||
else | ||
{ | ||
for (int i = 0; i < 0x100; i++) | ||
{ | ||
codes[codes.Count - 1].Add (-1); | ||
} | ||
|
||
presentations.Add ("D1"); | ||
descriptions.Add ("—"); | ||
} | ||
} | ||
|
||
if ((codes.Count != names.Count) || (names.Count != descriptions.Count) || | ||
(descriptions.Count != presentations.Count)) | ||
{ | ||
throw new Exception (); | ||
} | ||
} | ||
catch | ||
{ | ||
throw new Exception ("База кодов программы повреждена. Работа программы невозможна.\n" + | ||
"Ошибка встречена в строке " + line.ToString ()); | ||
} | ||
|
||
// Завершено | ||
SR.Close (); | ||
} | ||
|
||
/// <summary> | ||
/// Метод возвращает код указанного символа | ||
/// </summary> | ||
/// <param name="KKMType">Модель ККМ</param> | ||
/// <param name="CodeNumber">Порядковый номер символа в таблице</param> | ||
/// <returns>Возвращает код (сообщение) ошибки или \x7 в случае, если входные параметры некорректны</returns> | ||
public string GetCode (uint KKMType, byte CodeNumber) | ||
{ | ||
if ((int)KKMType < names.Count) | ||
{ | ||
if (codes[(int)KKMType][CodeNumber] < 0) | ||
{ | ||
return EmptyCode; | ||
} | ||
|
||
return codes[(int)KKMType][CodeNumber].ToString (presentations[(int)KKMType]); | ||
} | ||
else | ||
{ | ||
return EmptyCode; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Возвращает количество доступных типов ККМ | ||
/// </summary> | ||
public uint KKMTypesCount | ||
{ | ||
get | ||
{ | ||
return (uint)names.Count; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Возвращает список названий ККМ | ||
/// </summary> | ||
public string[] KKMTypeNames | ||
{ | ||
get | ||
{ | ||
return names.ToArray (); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Метод возвращает пояснение к способу ввода текста в ККМ по её типу | ||
/// </summary> | ||
/// <param name="KKMType">Модель ККМ</param> | ||
/// <returns>Возвращает пояснение или \x7 в случае, если входные параметры некорректны</returns> | ||
public string GetKKMTypeDescription (uint KKMType) | ||
{ | ||
if ((int)KKMType < names.Count) | ||
return descriptions[(int)KKMType]; | ||
else | ||
return EmptyCode; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Windows.Forms; | ||
|
||
namespace RD_AAOW | ||
{ | ||
/// <summary> | ||
/// Êëàññ îáåñïå÷èâàåò ïðåîáðàçîâàíèå òàáëèöû â ïðèãîäíûé äëÿ èìïîðòà â ïðîãðàììó âèä | ||
/// </summary> | ||
public static class TablesInterpreter | ||
{ | ||
/// <summary> | ||
/// Çàïóñêàåò òðàíñëÿöèþ âûáðàííîé òàáëèöû | ||
/// </summary> | ||
public static int Interpretate () | ||
{ | ||
FileStream FI = null, FO = null; | ||
List<int> codes = new List<int> (); | ||
for (int i = 0; i < 256; i++) | ||
codes.Add (-1); | ||
|
||
string kkm = "Îðèîí100Ô"; | ||
|
||
try | ||
{ | ||
FI = new FileStream (kkm + ".txt", FileMode.Open); | ||
} | ||
catch | ||
{ | ||
MessageBox.Show ("Íå óäàëîñü îòêðûòü âõîäíîé ôàéë", ProgramDescription.AssemblyTitle, | ||
MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
return -1; | ||
} | ||
|
||
try | ||
{ | ||
FO = new FileStream (kkm + ".dat", FileMode.Create); | ||
} | ||
catch | ||
{ | ||
MessageBox.Show ("Íå óäàëîñü ñîçäàòü âûõîäíîé ôàéë", ProgramDescription.AssemblyTitle, | ||
MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
return -2; | ||
} | ||
|
||
Encoding enc = Encoding.GetEncoding (1251); | ||
StreamReader SR = new StreamReader (FI, enc); | ||
StreamWriter SW = new StreamWriter (FO, enc); | ||
|
||
string line; | ||
SW.WriteLine (kkm); | ||
while ((line = SR.ReadLine ()) != null) | ||
{ | ||
try | ||
{ | ||
byte[] b = enc.GetBytes (line.ToCharArray (), 0, 1); | ||
codes[b[0]] = byte.Parse (line.Substring (1)); | ||
} | ||
catch | ||
{ | ||
MessageBox.Show ("Ñáîé èíòåðïðåòàöèè ñòðîêè", ProgramDescription.AssemblyTitle, | ||
MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
} | ||
} | ||
|
||
SR.Close (); | ||
FI.Close (); | ||
|
||
for (int i = 0; i < codes.Count; i++) | ||
SW.WriteLine (codes[i]); | ||
|
||
SW.WriteLine ("D2"); | ||
SW.WriteLine ("16 ñèìâîëîâ â ñòðîêå"); | ||
|
||
SW.Close (); | ||
FO.Close (); | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
using System.Text; | ||
using System.Windows.Forms; | ||
|
||
namespace RD_AAOW | ||
{ | ||
/// <summary> | ||
/// Класс описывает главную форму программы | ||
/// </summary> | ||
public partial class TextToKKMForm:Form | ||
{ | ||
// Переменные | ||
private KKMCodes kkmc = null; | ||
|
||
/// <summary> | ||
/// Конструктор. Запускает главную форму | ||
/// </summary> | ||
public TextToKKMForm () | ||
{ | ||
// Функция, используемая для добавления новых моделей | ||
//TablesInterpreter.Interpretate (); | ||
|
||
// Инициализация | ||
InitializeComponent (); | ||
|
||
// Загрузка списка ККМ | ||
kkmc = new KKMCodes (); | ||
|
||
// Формирование списка ККМ | ||
KKMList.Items.AddRange (kkmc.KKMTypeNames); | ||
KKMList.SelectedIndex = 0; | ||
|
||
// Настройка контролов | ||
this.Text = ProgramDescription.AssemblyTitle; | ||
} | ||
|
||
// Завершение работы | ||
private void BExit_Click (object sender, EventArgs e) | ||
{ | ||
this.Close (); | ||
} | ||
|
||
// Изменение текста и его кодировка | ||
private void TextToConvert_TextChanged (object sender, EventArgs e) | ||
{ | ||
ResultText.Text = ""; | ||
|
||
ErrorLabel.Visible = !Decode (); | ||
|
||
TextLabel.Text = "Текст (" + TextToConvert.Text.Length + "):"; | ||
|
||
DescriptionLabel.Text = kkmc.GetKKMTypeDescription ((uint)KKMList.SelectedIndex); | ||
} | ||
|
||
// Функция трансляции строки в набор кодов | ||
private bool Decode () | ||
{ | ||
bool res = true; | ||
char[] text = TextToConvert.Text.ToCharArray (); | ||
|
||
for (int i = 0; i < TextToConvert.Text.Length; i++) | ||
{ | ||
string s; | ||
byte[] b = Encoding.GetEncoding (1251).GetBytes (text, i, 1); | ||
|
||
if ((s = kkmc.GetCode ((uint)KKMList.SelectedIndex, b[0])) == KKMCodes.EmptyCode) | ||
{ | ||
ResultText.Text += "xxx\t"; | ||
res = false; | ||
} | ||
else | ||
{ | ||
ResultText.Text += (s + "\t"); | ||
} | ||
} | ||
|
||
// Означает успех/ошибку преобразования | ||
return res; | ||
} | ||
|
||
// Выбор ККМ | ||
private void KKMList_SelectedIndexChanged (object sender, EventArgs e) | ||
{ | ||
// Обработка делимитера | ||
if (KKMList.Text == "——————————") | ||
{ | ||
if (KKMList.SelectedIndex == KKMList.Items.Count - 1) | ||
KKMList.SelectedIndex = 0; | ||
else | ||
KKMList.SelectedIndex++; | ||
|
||
return; | ||
} | ||
|
||
// Обработка текста | ||
TextToConvert_TextChanged (sender, e); | ||
} | ||
|
||
// Отображение справки | ||
private void MainForm_HelpButtonClicked (object sender, System.ComponentModel.CancelEventArgs e) | ||
{ | ||
// Отмена обработки события вызова справки | ||
e.Cancel = true; | ||
|
||
// Отображение | ||
ProgramDescription.ShowAbout (); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Windows.Forms; | ||
|
||
namespace RD_AAOW | ||
{ | ||
/// <summary> | ||
/// Класс описывает точку входа приложения | ||
/// </summary> | ||
public static class TextToKKMProgram | ||
{ | ||
/// <summary> | ||
/// Главная точка входа для приложения. | ||
/// </summary> | ||
[STAThread] | ||
public static void Main () | ||
{ | ||
Application.EnableVisualStyles (); | ||
Application.SetCompatibleTextRenderingDefault (false); | ||
Application.Run (new TextToKKMForm ()); | ||
} | ||
} | ||
} |
Oops, something went wrong.