private void 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(); } } }
public Pay() { InitializeComponent(); this.cash_sum.SelectionStart = 0; this.non_cash_sum.SelectionStart = 0; this.pay_bonus.SelectionStart = 0; this.KeyPreview = true; this.Load += new EventHandler(Pay_Load); this.cash_sum.KeyPress += new KeyPressEventHandler(cash_sum_KeyPress); this.cash_sum.KeyUp += new KeyEventHandler(cash_sum_KeyUp); this.non_cash_sum.KeyPress += new KeyPressEventHandler(non_cash_KeyPress); this.non_cash_sum.KeyUp += new KeyEventHandler(non_cash_KeyUp); this.pay_bonus.KeyPress += new KeyPressEventHandler(pay_bonus_KeyPress); this.pay_bonus.KeyUp += new KeyEventHandler(pay_bonus_KeyUp); this.non_cash_sum_kop.KeyPress += new KeyPressEventHandler(non_cash_sum_kop_KeyPress); this.button_pay.Enabled = false; listView_sertificates = new ListView(); if (MainStaticClass.NumberDecimalSeparator() == ".") { this.pay_bonus_many.Text = "0.00"; } else { this.pay_bonus_many.Text = "0,00"; } }
private bool check_exists() { NpgsqlConnection conn = null; try { conn = MainStaticClass.NpgsqlConn(); conn.Open(); string query = "SELECT COUNT(*) FROM checks_header WHERE checks_header.date_time_write BETWEEN '" + DateTime.Now.Date + "' and '" + DateTime.Now.Date.AddDays(1) + "'"; NpgsqlCommand command = new NpgsqlCommand(query, conn); if (Convert.ToInt32(command.ExecuteScalar()) != 0) { conn.Close(); return(true); } } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } return(false); }
public Cash_checks() { InitializeComponent(); this.listView1.Font = new System.Drawing.Font("Microsoft Sans Serif", MainStaticClass.Font_list_view(), System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.KeyPreview = true; this.Load += new EventHandler(Cash_checks_Load); }
private void get_status_send_document() { string result = ""; string documents_not_out = MainStaticClass.get_documents_not_out().ToString(); if (documents_not_out == "-1") { result = " Произошли ошибки при получении кол-ва неотправленных документов, "; } else { result = " Не отправлено документов " + documents_not_out + ","; } 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 == -1) { result += " Не удалось получить дату с сервера "; } else if (documents_out_of_the_range_of_dates == -2) { result += " Не удалось получить количество документов вне диапазона "; } else if (documents_out_of_the_range_of_dates > 0) { result += " За диапазоном находится " + documents_out_of_the_range_of_dates.ToString(); } result += " " + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"); Invoke(new set_message_on_txtB_not_unloaded_docs(set_text_on_txtB_not_unloaded_docs), new object[] { result }); }
/// <summary> /// Возвращает ид Роли /// </summary> /// <param name="user_code"></param> /// <returns></returns> private int find_user_role(string user_code) { int rezult = 0; try { NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); conn.Open(); //string query = "SELECT users._right_,nick FROM users left join clients on users.client_code=clients.code where clients.barcode='" + user_code + "'"; string query = "SELECT users._right_,nick,client_code FROM users left join clients on users.client_code=clients.code where clients.code='" + user_code + "'"; NpgsqlCommand command = new NpgsqlCommand(query, conn); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { rezult = Convert.ToInt32(reader.GetInt16(0)); if (!not_change_Cash_Operator) { MainStaticClass.Cash_Operator = reader.GetString(1); MainStaticClass.Cash_Operator_Client_Code = reader.GetString(2); } } //object result = command.ExecuteScalar(); //if (result != null) //{ // rezult = Convert.ToInt32(result); //} conn.Close(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } return(rezult); }
private void write_error(string error) { NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { conn.Open(); string query = "INSERT INTO errors_on_send_portions(" + "time_event," + "errors_text," + ")VALUES('" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + error + "')"; NpgsqlCommand command = new NpgsqlCommand(query, conn); command.ExecuteNonQuery(); conn.Close(); } catch { } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }
private void to_change_the_document_status() { NpgsqlConnection conn = null; string myQuery = ""; string update_value = ""; try { conn = MainStaticClass.NpgsqlConn(); conn.Open(); if (listView1.Items[listView1.SelectedIndices[0]].Text == "0") { update_value = "1"; } else { update_value = "0"; } myQuery = "UPDATE checks_header SET its_deleted=" + update_value + " where date_time_write = '" + listView1.Items[listView1.SelectedIndices[0]].SubItems[1].Text + "'"; NpgsqlCommand command = new NpgsqlCommand(myQuery, conn); object result = command.ExecuteScalar(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message, "Ошибка при работе с базой данных"); } finally { conn.Close(); } }
private string get_num_doc_on_date_time_write(string date_time_write) { string result = ""; NpgsqlConnection conn = null; try { conn = MainStaticClass.NpgsqlConn(); conn.Open(); string query = "SELECT document_number FROM checks_header WHERE date_time_write='" + date_time_write + "'"; NpgsqlCommand command = new NpgsqlCommand(query, conn); result = command.ExecuteScalar().ToString(); conn.Close(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } return(result); }
/// <summary> /// Получаем строку код сертификата и его номинал /// </summary> /// <returns></returns> private string get_not_sent_sertificates() { string result = ""; NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { conn.Open(); string query = "SELECT " + " checks_table.document_number" + "," + " tovar_code" + "," + " price" + "," + " checks_header.cash_desk_number" + "," + " sertificates.code AS sertificates_code" + "," + " checks_header.date_time_write " + " FROM checks_table LEFT JOIN tovar ON checks_table.tovar_code = tovar.code " + " LEFT JOIN checks_header ON checks_header.document_number = checks_table.document_number " + " LEFT JOIN sertificates ON checks_table.tovar_code = sertificates.code_tovar " + " where checks_table.document_number in (" + document_number_list.ToString() + ") AND tovar.its_certificate = 1 AND checks_header.its_deleted = 0 ";//сертификаты только из проведенных документов NpgsqlCommand command = new NpgsqlCommand(query, conn); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { result += reader["document_number"].ToString() + "," + reader["tovar_code"].ToString() + "," + reader["price"].ToString().Replace(",", ".") + "," + reader["cash_desk_number"].ToString() + "," + reader["sertificates_code"].ToString() + "," + reader.GetDateTime(5).ToString("dd-MM-yyyy HH:mm:ss") + "|"; } if (result != "") { result = result.Substring(0, result.Length - 1); } reader.Close(); conn.Close(); } catch (NpgsqlException) { result = "-1"; } catch (Exception) { result = "-1"; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } return(result); }
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Список введённых подарков будет очищен.При следующем переходе в окно оплаты необходимо повторить их ввод, если программа предложит это сделать."); cc.cancel_action(); //записать в лог что кассир вернулся в документ MainStaticClass.write_event_in_log("Возврат в документ из окна оплата", "Документ чек", cc.numdoc.ToString()); this.Close(); }
public bool fill_items(BuyReturnRequest buyReturnRequest, string document_number, string client) { bool result = true; NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { conn.Open(); string query = "SELECT numstr, tovar_code, quantity, price,price_at_a_discount,sum_at_a_discount FROM checks_table where document_number =" + document_number + " order by numstr desc"; NpgsqlCommand command = new NpgsqlCommand(query, conn); NpgsqlDataReader reader = command.ExecuteReader(); buyReturnRequest.items = new Items(); Items items = new Items(); //List<Item> list_items= new List<Item>();// items2 = new items.item(); items.item = new List <Item>();// items2 = new items.item(); while (reader.Read()) { Item item = new Item(); item.pos = (Convert.ToInt32(reader["numstr"]) + 1).ToString(); //item.pos = Convert.ToInt32(reader["numstr"]).ToString(); item.SKU = reader["tovar_code"].ToString(); item.qty = reader["quantity"].ToString(); if (client == "") { item.price = Convert.ToInt32((Convert.ToDecimal(reader["price_at_a_discount"]) * 100)).ToString(); } else { item.price = Convert.ToInt32((Convert.ToDecimal(reader["price"]) * 100)).ToString(); } //item.discount = Convert.ToInt32(((Convert.ToDecimal(reader["sum_at_a_discount"]) - Convert.ToDecimal(reader["quantity"]) * Convert.ToDecimal(reader["price"]))*100)*-1).ToString(); //item.discount = Convert.ToInt32(((Convert.ToDecimal(reader["price_at_a_discount"])- Convert.ToDecimal(reader["price"])) * 100)*-1).ToString(); items.item.Add(item); //list_items.Add(item); //buyNewrequest.items.Add(item); } //items.item = list_items; buyReturnRequest.items = items; } catch (NpgsqlException ex) { result = false; } catch (Exception ex) { result = false; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } return(result); }
public InputePhoneClient() { InitializeComponent(); if (MainStaticClass.get_currency() == "руб.") { this.txtB_phone_number.MaxLength = 12; } this.txtB_phone_number.KeyPress += new KeyPressEventHandler(txtB_phone_number_KeyPress); this.Load += new EventHandler(InputePhoneClient_Load); this.txtB_phone_number.SelectionStart = 1; this.KeyPreview = true; }
private void btn_have_internet_Click(object sender, EventArgs e) { if (MainStaticClass.get_exists_internet()) { txtB_have_internet.Text = "Работает"; txtB_have_internet.BackColor = Color.Green; } else { txtB_have_internet.Text = "Не работает"; txtB_have_internet.BackColor = Color.Gold; } }
private void get_phone_client() { NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { conn.Open(); string query = "SELECT clients.phone AS phone, coalesce(temp_phone_clients.phone,'') AS phone1 FROM clients " + " left join temp_phone_clients ON clients.code = temp_phone_clients.barcode " + " WHERE clients.code='" + client_code + "'"; NpgsqlCommand command = new NpgsqlCommand(query, conn); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if ((reader["phone"].ToString().Trim().Length >= 10)) { txtB_phone.Text = reader["phone"].ToString().Trim(); } else if ((reader["phone1"].ToString().Trim().Length >= 10)) { txtB_phone.Text = reader["phone1"].ToString().Trim(); } } reader.Close(); conn.Close(); if (txtB_phone.Text.Trim().Length > 10) { txtB_phone.Text = txtB_phone.Text.Substring(0, 2) + " " + txtB_phone.Text.Substring(2, 3) + " " + txtB_phone.Text.Substring(5, 3) + " " + txtB_phone.Text.Substring(8, 2) + " " + txtB_phone.Text.Substring(10, 2); } else if (txtB_phone.Text.Trim().Length == 10) { txtB_phone.Text = txtB_phone.Text.Substring(0, 3) + " " + txtB_phone.Text.Substring(3, 3) + " " + txtB_phone.Text.Substring(6, 2) + " " + txtB_phone.Text.Substring(8, 2); } } catch (NpgsqlException ex) { MessageBox.Show("Ошибка при проверка наличия телефона " + ex.Message); } catch (Exception ex) { MessageBox.Show("Ошибка при проверка наличия телефона " + ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }
//public static RootObject check_last_check_print() //{ // string status = ""; // RootObject result = null; // int count = 0; string last_guid = MainStaticClass.read_last_sell_guid(); // if (last_guid.Trim().Length!=36) // { // return result; // } // while (1 == 1) // { // count++; // Thread.Sleep(1000); // result = GET(MainStaticClass.url, last_guid); // status = result.results[0].status; // if (status != "ready") // { // if (count > 14) // { // break; // } // } // else if ((status == "ready") || (status == "error")) // { // break; // } // } // return result; //} public static RootObject check_print(string type, Check check, string num_doc) { string status = ""; RootObject result = null; //Check check = new Check(); check.@operator = new FiscallPrintJason.Operator(); [email protected] = MainStaticClass.Cash_Operator; // "name";//необходимо переопределить [email protected] = MainStaticClass.cash_operator_inn; // "123654789507";//необходимо переопределить check.type = type; string _check_ = JsonConvert.SerializeObject(check, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); string json = MainStaticClass.shablon.Replace("body", _check_); guid = Guid.NewGuid().ToString(); string replace = "\"uuid\": \"" + guid + "\""; json = json.Replace("uuid", replace); //MainStaticClass.write_last_sell_guid(guid,num_doc); if (POST(MainStaticClass.url, json) == "Created") { //Здесь отметить задание, что оно принято к исполнению MainStaticClass.write_document_wil_be_printed(num_doc); int count = 0; while (1 == 1) { count++; Thread.Sleep(1000); result = GET(MainStaticClass.url, guid); status = result.results[0].status; if (status != "ready") { if (count > 14) { break; } } else if ((status == "ready") || (status == "error")) { break; } } } return(result); }
/// <summary> /// Возвращает ид Роли /// </summary> /// <param name="user_code"></param> /// <returns></returns> private int find_user_role_new(string password) { int rezult = 0; string password_Md5Hash = MainStaticClass.getMd5Hash(password).ToUpper(); try { NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); conn.Open(); string query = "SELECT rights,name,code,inn FROM users where password_m='" + password_Md5Hash.Trim() + "' or password_b='" + password_Md5Hash.Trim() + "'"; NpgsqlCommand command = new NpgsqlCommand(query, conn); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { rezult = Convert.ToInt32(reader.GetInt16(0)); if (!not_change_Cash_Operator) { MainStaticClass.Cash_Operator = reader["name"].ToString().Trim(); MainStaticClass.Cash_Operator_Client_Code = reader["code"].ToString(); MainStaticClass.cash_operator_inn = reader["inn"].ToString(); } } conn.Close(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } if (MainStaticClass.Cash_Operator.Trim().ToUpper() == "К9") { //MessageBox.Show(" "+MainStaticClass.CashDeskNumber.ToString()); //MessageBox.Show(" "+MainStaticClass.get_unloading_interval().ToString()); if ((MainStaticClass.CashDeskNumber != 9) || (MainStaticClass.get_unloading_interval() != 0))//Это пользователь для центрального компьютера 9 касса, пользователь не может зайти если стоит период синхронизации отличный от нуля или если номер кассы не 9 { rezult = 0; MainStaticClass.Cash_Operator = ""; MainStaticClass.Cash_Operator_Client_Code = ""; } } return(rezult); }
private void Constants_Load(object sender, EventArgs e) { NpgsqlConnection conn = null; try { conn = MainStaticClass.NpgsqlConn(); conn.Open(); string query = "SELECT nick_shop,cash_desk_number,use_debug,code_shop," + " path_for_web_service,currency,unloading_period,last_date_download_bonus_clients," + " envd,pass_promo,print_m,system_taxation FROM constants"; NpgsqlCommand command = new NpgsqlCommand(query, conn); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { this.nick_shop.Text = reader["nick_shop"].ToString(); this.cash_desk_number.Text = reader["cash_desk_number"].ToString(); m_cash_desk_number = Convert.ToInt32(reader["cash_desk_number"]); if (Convert.ToBoolean(reader["use_debug"])) { this.use_debug.CheckState = CheckState.Checked; } //this.code_shop.Text = reader["code_shop"].ToString(); this.path_for_web_service.Text = reader["path_for_web_service"].ToString(); this.currency.Text = reader["currency"].ToString(); this.unloading_period.Text = reader["unloading_period"].ToString(); this.txtB_last_date_download_bonus_clients.Text = (reader["last_date_download_bonus_clients"].ToString() == "" ? new DateTime(2000, 1, 1).ToString("dd-MM-yyyy") : Convert.ToDateTime(reader["last_date_download_bonus_clients"]).ToString("dd-MM-yyyy")); //this.checkBox_envd.CheckState = (reader["envd"].ToString().ToLower() == "false" ? CheckState.Unchecked : CheckState.Checked); this.checkBox_print_m.CheckState = (reader["print_m"].ToString().ToLower() == "false" ? CheckState.Unchecked : CheckState.Checked); //this.checkBox_osn_usnIncomeOutcome.CheckState = (reader["usn_income_out_come"].ToString().ToLower() == "false" ? CheckState.Unchecked : CheckState.Checked); this.comboBox_system_taxation.SelectedIndex = Convert.ToInt16(reader["system_taxation"]); } reader.Close(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } }
/// <summary> /// Обновим статусы после успешной отправки документов /// </summary> private void update_status_is_sent() { NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); NpgsqlTransaction trans = null; try { conn.Open(); trans = conn.BeginTransaction(); string query = "UPDATE checks_header SET is_sent=1 WHERE document_number in (" + document_number_list.ToString() + ")"; NpgsqlCommand command = new NpgsqlCommand(query, conn); command.Transaction = trans; command.ExecuteNonQuery(); trans.Commit(); command.Dispose(); trans.Dispose(); conn.Close(); MainStaticClass.Last_Send_Last_Successful_Sending = DateTime.Now; } catch (NpgsqlException) { if (trans != null) { trans.Rollback(); } } catch (Exception) { if (trans != null) { trans.Rollback(); } } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }
private void btn_execute_Click(object sender, EventArgs e) { NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { conn.Open(); string query = "INSERT INTO public.client_with_changed_status_to_send(client,date_change,new_phone_number)VALUES(@client,@date_change,@new_phone_number);"; NpgsqlCommand command = new NpgsqlCommand(query, conn); command.Parameters.AddWithValue("@client", client_code); command.Parameters.AddWithValue("@date_change", (DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"))); string new_phone = maskedTxtB_new_phone_number.Text.Trim().Replace(" ", "").Replace("+7", ""); if ((new_phone.Length != 10) && (new_phone.Length != 0)) { MessageBox.Show("Неверная длина номера телефона"); return; } command.Parameters.AddWithValue("@new_phone_number", maskedTxtB_new_phone_number.Text.Trim().Replace(" ", "").Replace("+7", "")); command.ExecuteNonQuery(); command.Dispose(); conn.Close(); MessageBox.Show("Заявка на изменение статуса успешно создана"); this.Close(); this.DialogResult = DialogResult.OK; } catch (NpgsqlException ex) { MessageBox.Show(" Ошибка при изменении статуса " + ex.Message); } catch (Exception ex) { MessageBox.Show(" Ошибка при изменении статуса " + ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }
private void load_actions() { NpgsqlConnection conn = null; NpgsqlCommand command = null; try { conn = MainStaticClass.NpgsqlConn(); conn.Open(); string query = "SELECT action_header.date_started, action_header.date_end, action_header.num_doc, action_header.tip, action_header.barcode, action_header.persent, action_header.sum,action_header.comment,tovar.name FROM action_header left join tovar on action_header.code_tovar=tovar.code ;"; command = new NpgsqlCommand(query, conn); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { ListViewItem lvi = new ListViewItem(reader.GetInt32(2).ToString()); lvi.Tag = reader.GetInt32(2).ToString(); lvi.SubItems.Add(reader.GetDateTime(0).ToString()); lvi.SubItems.Add(reader.GetDateTime(1).ToString()); lvi.SubItems.Add(reader.GetInt16(3).ToString()); lvi.SubItems.Add(reader.GetString(4).ToString()); lvi.SubItems.Add(reader.GetDecimal(5).ToString()); lvi.SubItems.Add(reader.GetDecimal(6).ToString()); lvi.SubItems.Add(reader.GetString(7).ToString()); //lvi.SubItems.Add(reader.GetString(8).ToString()); lvi.SubItems.Add(reader[8].ToString()); listView_doc.Items.Add(lvi); } } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }
private void btn_ofd_exchange_status_Click(object sender, EventArgs e) { txtB_ofd_exchange_status.BackColor = Color.Green; Cash8.FiscallPrintJason.RootObject result = MainStaticClass.get_ofd_exchange_status(); if (result != null) { if (result.results[0].result != null) { if (result.results[0].result.status.notSentCount > 0) { if ((DateTime.Now - result.results[0].result.status.notSentFirstDocDateTime).Days > 3) { txtB_ofd_exchange_status.Text = "Не отправлено документов " + result.results[0].result.status.notSentCount.ToString().Trim() + "\r\n" + " начиная с даты " + result.results[0].result.status.notSentFirstDocDateTime.ToString("yyyy-MM-dd HH:mm:ss"); txtB_ofd_exchange_status.BackColor = Color.Gold; } else { txtB_ofd_exchange_status.Text = "Не отправлено документов " + result.results[0].result.status.notSentCount.ToString().Trim(); } } else { txtB_ofd_exchange_status.Text = "Все отправлено"; } } else { txtB_ofd_exchange_status.Text = "Нет связи"; txtB_ofd_exchange_status.BackColor = Color.Gold; } } else { txtB_ofd_exchange_status.Text = "Нет связи"; txtB_ofd_exchange_status.BackColor = Color.Gold; } }
private bool this_check_the_last(string datetime) { bool result = false; NpgsqlConnection conn = null; try { conn = MainStaticClass.NpgsqlConn(); conn.Open(); string query = "SELECT date_time_write FROM checks_header order by date_time_write desc"; NpgsqlCommand command = new NpgsqlCommand(query, conn); //object result_query = command.ExecuteScalar(); if (datetime.Trim() == Convert.ToDateTime(command.ExecuteScalar()).ToString("yyyy-MM-dd HH:mm:ss").Trim()) { result = true; } conn.Close(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } return(result); }
private void insert_record_failed_input_phone() { bool errors = false; NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { conn.Open(); string query = "INSERT INTO failed_input_phone(client_code, datetime_input) VALUES ('" + caller.client.Tag.ToString() + "','" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "');"; NpgsqlCommand command = new NpgsqlCommand(query, conn); command.ExecuteNonQuery(); conn.Close(); command.Dispose(); } catch (NpgsqlException ex) { MessageBox.Show("Ошибка при определении количества попыток ввода неправильного номера телефона " + ex.Message); errors = true; } catch (Exception ex) { MessageBox.Show("Ошибка при определении количества попыток ввода неправильного номера телефона " + ex.Message); errors = true; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } if (errors) { this.DialogResult = DialogResult.Cancel; this.Close(); } }
private int count_users() { int rezult = 0; try { NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); conn.Open(); string query = "SELECT COUNT(*)FROM users "; NpgsqlCommand command = new NpgsqlCommand(query, conn); object result = command.ExecuteScalar(); if (result != null) { rezult = Convert.ToInt32(result); } conn.Close(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } return(rezult); }
private void print_control_check() { StringBuilder print_string = new StringBuilder(); int width_of_symbols = MainStaticClass.Width_Of_Symbols; if (width_of_symbols == 0) { MessageBox.Show("Не задана ширина печати, печать выполнена не будет ", "Ошибка настройки программы"); return; } //using (StreamWriter sw = new StreamWriter(Application.StartupPath + "/PrintCheck.txt")) //{ //sw.WriteLine("ЧИСТЫЙ ДОМ - Магазин низких цен №1"); print_string.Append("ЧИСТЫЙ ДОМ - Магазин низких цен №1" + "\r\n"); //sw.WriteLine(" << ЧИСТЫЙ ДОМ >>"); //sw.WriteLine("бытовая химия - косметика - парфюмерия"); print_string.Append("бытовая химия - косметика - парфюмерия" + "\r\n"); //sw.WriteLine("_______________________________________"); print_string.Append("---------------------------------------" + "\r\n"); print_string.Append(MainStaticClass.Nick_Shop + " К №" + MainStaticClass.CashDeskNumber + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + MainStaticClass.Cash_Operator + "\r\n"); string number = ""; NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { string query = "SELECT MAX(document_number) FROM checks_header where date_time_write<'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'"; conn.Open(); NpgsqlCommand command = new NpgsqlCommand(query, conn); number = command.ExecuteScalar().ToString(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); number = "Ошибка при получении номера"; } catch (Exception ex) { MessageBox.Show(ex.Message); number = "Ошибка при получении номера"; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } print_string.Append("Предыдущий чек № " + number + "\r\n"); //if (DialogResult.OK == MessageBox.Show("Печатать чек ?", "Печатать чек ?", MessageBoxButtons.OKCancel)) //{ PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); //pd.PrinterSettings.PrinterName = PrinterSettings.InstalledPrinters[0]; pd.PrinterSettings.PrinterName = PrinterSettings.InstalledPrinters[MainStaticClass.get_num_text_pinter()]; count_pages = -1; string TFF = print_string.ToString(); TFF = TFF.Replace("\r\n", "|"); print_data = TFF.Split('|'); pd.Print(); //} }
public void loaddocuments() { listView1.Items.Clear(); NpgsqlConnection conn = null; try { conn = MainStaticClass.NpgsqlConn(); conn.Open(); //string myQuery = "SELECT checks_header.date_time_write,clients.name,checks_header.cash,checks_header.remainder FROM checks_header left join clients ON checks_header.client=clients.code WHERE checks_header.date_time_write BETWEEN '" + data_start.Text + "' and '" + data_finish.Text + "' order by checks_header.date_time_write "; string myQuery = "SELECT checks_header.its_deleted," + "checks_header.date_time_write," + "clients.name," + "checks_header.cash," + "checks_header.remainder," + "checks_header.comment," + //"checks_header.inventory,"+ "checks_header.its_print," + "checks_header.check_type,checks_header.document_number FROM checks_header left join clients ON checks_header.client=clients.code WHERE checks_header.date_time_write BETWEEN '" + dateTimePicker1.Value.ToString("yyy-MM-dd") + " 00:00:00" + "' and '" + dateTimePicker1.Value.AddDays(1).ToString("yyy-MM-dd") + " 00:00:00" + "' AND its_deleted<2 order by checks_header.date_time_write "; if (checkBox_show_3_last_checks.CheckState == CheckState.Checked) { myQuery += " desc limit 3 "; } //MessageBox.Show(myQuery); NpgsqlCommand command = new NpgsqlCommand(myQuery, conn); NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { //ListViewItem lvi = new ListViewItem(reader.GetDateTime(0).ToString("yyy-MM-dd HH:mm:ss")); ListViewItem lvi = new ListViewItem(reader.GetDecimal(0).ToString()); lvi.SubItems.Add(reader.GetDateTime(1).ToString("yyyy-MM-dd HH:mm:ss")); lvi.SubItems.Add(reader[2].ToString()); lvi.SubItems.Add(reader.GetDecimal(3).ToString()); lvi.SubItems.Add(reader.GetDecimal(4).ToString()); lvi.SubItems.Add((reader["check_type"].ToString() == "0" ? "Продажа" : "Возврат")); lvi.SubItems.Add(reader.GetString(5)); if (MainStaticClass.Use_Fiscall_Print) { if (!Convert.IsDBNull(reader[6])) { if (!reader.GetBoolean(6)) { if (reader.GetDecimal(0) == 0) { lvi.BackColor = Color.Pink; } } } else { if (reader.GetDecimal(0) == 0) { lvi.BackColor = Color.Pink; } } } lvi.SubItems.Add(reader["document_number"].ToString()); listView1.Items.Add(lvi); } reader.Close(); conn.Close(); command.Dispose(); } catch (NpgsqlException ex) { MessageBox.Show(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } listView1.Focus(); this.listView1.Select(); if (checkBox_show_3_last_checks.CheckState == CheckState.Checked) { if (listView1.Items.Count > 0) { this.listView1.Items[0].Selected = true; this.listView1.Items[0].Focused = true; this.listView1.EnsureVisible(0); } } else { if (listView1.Items.Count > 0) { this.listView1.Items[this.listView1.Items.Count - 1].Selected = true; this.listView1.Items[this.listView1.Items.Count - 1].Focused = true; this.listView1.EnsureVisible(this.listView1.Items.Count - 1); } } }
protected override void OnClosing(CancelEventArgs e) { MainStaticClass.remove_window(this.GetType().FullName); }
void txtB_phone_number_KeyPress(object sender, KeyPressEventArgs e) { //if (e.KeyChar != 43) //{ if (!(Char.IsDigit(e.KeyChar))) { if (e.KeyChar != (char)Keys.Back) { e.Handled = true; } } //} if (e.KeyChar == (char)Keys.Enter) { //int lenght = 0; //if (MainStaticClass.get_currency() == "руб.") //{ // lenght = 12; //} //else //{ // lenght = 13; //} if (this.txtB_phone_number.Text.Trim().Length != 10) { MessageBox.Show(" Телефонный номер должен состоять из 10 цифр "); return; } //{ // MessageBox.Show(" Телефонный номер введен некорректно "); // return; //} //if (MainStaticClass.get_currency() == "руб.") //{ //if (this.txtB_phone_number.Text.Trim().Substring(0, 1) != "7") //{ // MessageBox.Show(" Телефонный номер введен некорректно, номер должен начинаться с +7 "); // return; //} //} //else //{ // if (this.txtB_phone_number.Text.Trim().Substring(0, 3) != "+38") // { // MessageBox.Show(" Телефонный номер введен некорректно, номер должен начинаться с +38 "); // return; // } //} } else { return; } NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { conn.Open(); //string query = "SELECT COUNT(*) FROM clients WHERE phone LIKE'%"+ txtB_phone_number.Text.Trim() + "%'"; string query = "SELECT COUNT(*) FROM clients where right(phone,10)='" + txtB_phone_number.Text.Trim() + "'"; NpgsqlCommand command = new NpgsqlCommand(query, conn); if (Convert.ToInt32(command.ExecuteScalar()) == 0) { query = "DELETE FROM temp_phone_clients WHERE phone='" + this.txtB_phone_number.Text.Trim() + "'"; command = new NpgsqlCommand(query, conn); command.ExecuteNonQuery(); if (barcode != "") { query = "INSERT INTO temp_phone_clients(barcode, phone)VALUES ('" + barcode + "','" + this.txtB_phone_number.Text.Trim() + "')"; } else { query = "INSERT INTO temp_phone_clients(barcode, phone)VALUES ('" + this.txtB_phone_number.Text.Trim() + "','" + this.txtB_phone_number.Text.Trim() + "')"; } command = new NpgsqlCommand(query, conn); command.ExecuteNonQuery(); conn.Close(); if (barcode == "") { cash_Check.client.Tag = this.txtB_phone_number.Text.Trim(); cash_Check.client.Text = this.txtB_phone_number.Text.Trim(); cash_Check.Discount = Convert.ToDecimal(0.05); } this.DialogResult = DialogResult.OK; } else { MessageBox.Show("У этого клиента уже есть дисконтная карта с привязанным номером телефона !!!"); //MessageBox.Show("Введите номер телефона в соответсвующее поле !!!"); this.DialogResult = DialogResult.Yes; conn.Close(); this.Close(); } } catch (NpgsqlException ex) { MessageBox.Show(" Ошибки при записи номера телефона " + ex.Message); } catch (Exception ex) { MessageBox.Show(" Ошибки при записи номера телефона " + ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } this.Close(); }
private void Cash_checks_Load(object sender, System.EventArgs e) { if (listView1.Columns.Count == 6) { return; } int result = MainStaticClass.get_unloading_interval(); if (result != 0) { //timer.Interval = 60000; timer.Start(); timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); //timer_Elapsed(null, null); get_status_send_document(); } this.num_cash.Text = "КАССА № " + MainStaticClass.CashDeskNumber.ToString(); this.txtB_cashier.Text = MainStaticClass.Cash_Operator; //this.data_start.Text = monthCalendar1.SelectionStart.ToString(); //this.data_finish.Text = monthCalendar1.SelectionStart.AddSeconds(86399).ToString(); // Set the view to show details. listView1.View = View.Details; // Allow the user to rearrange columns. listView1.AllowColumnReorder = true; // Select the item and subitems when selection is made. listView1.FullRowSelect = true; // Display grid lines. listView1.GridLines = true; listView1.Columns.Clear(); listView1.Columns.Add("Статус", 100, HorizontalAlignment.Left); listView1.Columns.Add("Дата", 200, HorizontalAlignment.Left); listView1.Columns.Add("Клиент", 200, HorizontalAlignment.Left); listView1.Columns.Add("Сумма", 100, HorizontalAlignment.Right); listView1.Columns.Add("Сдача", 100, HorizontalAlignment.Right); listView1.Columns.Add("Тип чека ", 100, HorizontalAlignment.Right); listView1.Columns.Add("Коментарий", 300, HorizontalAlignment.Right); listView1.Columns.Add("Номер", 300, HorizontalAlignment.Right); //listView1.Columns.Add("Инвентаризация", 100, HorizontalAlignment.Right); //this.WindowState = FormWindowState.Normal; this.WindowState = FormWindowState.Maximized; if (MainStaticClass.Code_right_of_user == 2) { label2.Enabled = false; dateTimePicker1.Enabled = false; fill.Enabled = false; //data_start.Visible = false; //data_finish.Visible = false; //button2.Visible = false; //button3.Visible = false; //button4.Visible = false; label2.Visible = false; this.FormBorderStyle = FormBorderStyle.None; } //tovar = new Nomenklatura(); //tovar.caller = this; //tovar.Visible = false; this.Top = 0; this.Left = 0; this.Size = new System.Drawing.Size(SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height); this.TopMost = true; loaddocuments(); if (MainStaticClass.Code_right_of_user != 1) { checkBox_show_3_last_checks.Enabled = false; } if (MainStaticClass.Code_right_of_user != 1) { this.WindowState = FormWindowState.Normal; this.BringToFront(); } }