Click here to Skip to main content
15,876,805 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to print a recording Pin
OriginalGriff29-Mar-18 0:11
mveOriginalGriff29-Mar-18 0:11 
GeneralRe: How to print a recording Pin
ago248629-Mar-18 0:20
ago248629-Mar-18 0:20 
GeneralRe: How to print a recording Pin
OriginalGriff29-Mar-18 0:42
mveOriginalGriff29-Mar-18 0:42 
GeneralRe: How to print a recording Pin
ago248629-Mar-18 1:05
ago248629-Mar-18 1:05 
GeneralRe: How to print a recording Pin
OriginalGriff29-Mar-18 1:24
mveOriginalGriff29-Mar-18 1:24 
GeneralRe: How to print a recording Pin
ago248629-Mar-18 1:27
ago248629-Mar-18 1:27 
GeneralRe: How to print a recording Pin
OriginalGriff29-Mar-18 1:36
mveOriginalGriff29-Mar-18 1:36 
GeneralRe: How to print a recording Pin
ago248629-Mar-18 2:35
ago248629-Mar-18 2:35 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SQLite;

namespace Acode
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
        private SQLiteConnection sql_con;
	    private SQLiteCommand sql_cmd;
        private SQLiteDataAdapter DB;
	    private DataSet DS = new DataSet();
	    private DataTable DT = new DataTable();

        private void setConnection()
	    {
	    sql_con = new SQLiteConnection(@"Data Source=DBcode.db; Version=3;New=;Compress=True;");
	    }

        private void LoadData()
        {
            setConnection();
            sql_con.Open();
            sql_cmd = sql_con.CreateCommand();
            sql_cmd.CommandText = "select * from InfoCode";
            DB = new SQLiteDataAdapter(sql_cmd.CommandText, sql_con);
            DS.Reset();
            DB.Fill(DS);
            DT = DS.Tables[0];
            dataGridView1.DataSource = DT;
            sql_con.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            LoadData();

        }

        private void ExecuteQuery()
	    {
        setConnection();
	    sql_con.Open();
	    sql_cmd = sql_con.CreateCommand();
	    //sql_cmd.CommandText = txtQuery;
	    //sql_cmd.ExecuteNonQuery();
	    sql_con.Close();
	    }

        public static string randomstring(int length)
        {
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWYZ0123456789";
            Random random = new Random();
            return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
        }
        private void btnGenerer_Click(object sender, EventArgs e)
        {
           
            lblAffichage.Text = randomstring(4);
            txtAffichPrix.Text = "100";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            lblAffichage.Text = randomstring(5);
            txtAffichPrix.Text = "300";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            lblAffichage.Text = randomstring(6);
            txtAffichPrix.Text = "500";
        }

       
        private void btnEnregistrer_Click(object sender, EventArgs e)
        {
            if (lblAffichage.Text =="")
            {
                MessageBox.Show("Merci de bien vouloir générer le code");
            }
            else
            {
                sql_cmd.CommandText = "insert into InfoCode (Code, DateCode, PrixCode) values('" + lblAffichage.Text + "' , '" + dateTimePicker1.Text + "' , '" + txtAffichPrix.Text + "')";
                sql_cmd.ExecuteNonQuery();
                LoadData();
                MessageBox.Show("Enregistrement effectué avec succès");
                lblAffichage.Text = "";
                groupBoxGenerer.Enabled = false;
                btnEnregistrer.Enabled = false;
                this.Refresh();
            }
            
        }

        private void btnAjouter_Click(object sender, EventArgs e)
        {
            groupBoxGenerer.Enabled = true;
            btnEnregistrer.Enabled = true;
        }

        private void quitterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void codeVenduToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmCodeVendu frmcodevendu=new FrmCodeVendu();
            frmcodevendu.Show();
            this.Hide();
    
        }

        private void pointToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmPointJournalier pointQ = new FrmPointJournalier();
            pointQ.Show();
            this.Hide();
        }
    }
}
I receive an error message: Database is not open

GeneralRe: How to print a recording Pin
OriginalGriff29-Mar-18 2:46
mveOriginalGriff29-Mar-18 2:46 
GeneralRe: How to print a recording Pin
ago248629-Mar-18 4:04
ago248629-Mar-18 4:04 
GeneralRe: How to print a recording Pin
OriginalGriff29-Mar-18 4:25
mveOriginalGriff29-Mar-18 4:25 
GeneralRe: How to print a recording Pin
ago248629-Mar-18 4:33
ago248629-Mar-18 4:33 
GeneralRe: How to print a recording Pin
ago248629-Mar-18 5:15
ago248629-Mar-18 5:15 
GeneralRe: How to print a recording Pin
ago248611-Apr-18 0:35
ago248611-Apr-18 0:35 
GeneralRe: How to print a recording Pin
ago248611-Apr-18 0:37
ago248611-Apr-18 0:37 
QuestionSerialPort DataReceived Event Read Byte ? Pin
ibrahimayhans28-Mar-18 3:28
ibrahimayhans28-Mar-18 3:28 
AnswerRe: SerialPort DataReceived Event Read Byte ? Pin
Richard MacCutchan28-Mar-18 3:54
mveRichard MacCutchan28-Mar-18 3:54 
GeneralRe: SerialPort DataReceived Event Read Byte ? Pin
ibrahimayhans28-Mar-18 4:00
ibrahimayhans28-Mar-18 4:00 
GeneralRe: SerialPort DataReceived Event Read Byte ? Pin
OriginalGriff28-Mar-18 4:17
mveOriginalGriff28-Mar-18 4:17 
GeneralRe: SerialPort DataReceived Event Read Byte ? Pin
ibrahimayhans28-Mar-18 4:24
ibrahimayhans28-Mar-18 4:24 
GeneralRe: SerialPort DataReceived Event Read Byte ? Pin
OriginalGriff28-Mar-18 4:26
mveOriginalGriff28-Mar-18 4:26 
GeneralRe: SerialPort DataReceived Event Read Byte ? Pin
ibrahimayhans28-Mar-18 4:28
ibrahimayhans28-Mar-18 4:28 
GeneralRe: SerialPort DataReceived Event Read Byte ? Pin
OriginalGriff28-Mar-18 4:43
mveOriginalGriff28-Mar-18 4:43 
GeneralRe: SerialPort DataReceived Event Read Byte ? Pin
ibrahimayhans28-Mar-18 4:48
ibrahimayhans28-Mar-18 4:48 
GeneralRe: SerialPort DataReceived Event Read Byte ? Pin
OriginalGriff28-Mar-18 5:01
mveOriginalGriff28-Mar-18 5:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.