/// <summary> /// Главный вызываемый метод по отправке бонусов /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void sent_Click(object sender, EventArgs e) { if (MainStaticClass.PassPromo == "") { MessageBox.Show("Эта касса не учавствует в бонусной программе "); return; } NpgsqlConnection conn = MainStaticClass.NpgsqlConn(); try { conn.Open(); string query = " SELECT document_number, client, cash_desk_number,date_time_start,bonuses_it_is_written_off,id_transaction,id_transaction_sale,check_type " + " FROM checks_header WHERE sent_to_processing_center = 0 and its_deleted=0"; NpgsqlCommand command = new NpgsqlCommand(query, conn); NpgsqlDataReader reader = command.ExecuteReader(); BuyNewRequest buyNewRequest = new BuyNewRequest(); while (reader.Read())//Здесь перебираем документы { //предварительно было отправлено buy_new, поэтому если нет оплаты бонусами то нужно отправить buycommit //if ((reader["id_transaction"].ToString().Trim() != "")&&(Convert.ToInt32(reader["bonuses_it_is_written_off"]) == 0)) if (reader["id_transaction"].ToString().Trim() != "") { BuyCommit buyCommit = new BuyCommit(); buyCommit.transactionId = reader["id_transaction"].ToString().Trim(); sent_document_buyCommit(buyCommit, reader["document_number"].ToString().Trim()); continue; } if (reader["check_type"].ToString() == "0") { buyNewRequest.cashierName = MainStaticClass.Cash_Operator; buyNewRequest.commit = "1"; buyNewRequest.date = Convert.ToDateTime(reader["date_time_start"]).ToString("yyyy-MM-dd HH:mm:ss"); //if (reader["client"].ToString().Trim().Length == 36) //{ // buyNewRequest.cardTrack2 = reader["client"].ToString(); //} if (reader["client"].ToString().Trim().Length >= 10) { buyNewRequest.cardNum = reader["client"].ToString(); } if ((Convert.ToInt32(reader["bonuses_it_is_written_off"]) != 0) && (reader["client"].ToString().Trim().Length == 10)) { buyNewRequest.charge = (Convert.ToInt32(reader["bonuses_it_is_written_off"]) * 100).ToString(); } //if (reader["client"].ToString().Trim().Length == 0) //{ // buyNewRequest.type = "6"; //} //else //{ buyNewRequest.type = "4"; //} if (fill_items(buyNewRequest, reader["document_number"].ToString(), reader["client"].ToString())) { sent_document(buyNewRequest, reader["document_number"].ToString()); } } else if (reader["check_type"].ToString() == "1") { BuyReturnRequest buyReturnRequest = new BuyReturnRequest(); buyReturnRequest.cashierName = MainStaticClass.Cash_Operator; buyReturnRequest.commit = "1"; //buyReturnRequest.date = Convert.ToDateTime(reader["date_time_start"]).ToString("yyyy-MM-dd HH:mm:ss"); buyReturnRequest.transactionId = reader["id_transaction_sale"].ToString(); if (fill_items(buyReturnRequest, reader["document_number"].ToString(), reader["client"].ToString())) { sent_documentbuyReturn(buyReturnRequest, reader["document_number"].ToString()); } } //if (fill_items(buyNewRequest, reader["document_number"].ToString(),reader["client"].ToString())) //{ // if (reader["check_type"].ToString() == "0") // { // } // else if (reader["check_type"].ToString() == "1") // { // sent_documentbuyReturn(buyNewRequest, reader["document_number"].ToString()); // } //} } reader.Close(); conn.Close(); } catch (NpgsqlException ex) { if (!run_in_the_background) { MyMessageBox mmb = new MyMessageBox(ex.Message, " Отправка неотправленных бонусов "); mmb.ShowDialog(); } } catch (Exception ex) { if (!run_in_the_background) { MyMessageBox mmb = new MyMessageBox(ex.Message, " Отправка неотправленных бонусов "); mmb.ShowDialog(); } } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } }