Пример #1
0
        //tự động tăng ID nhân viên khi insert
        public string tangIDNV()
        {
            DAL.SQLConnect conn = new DAL.SQLConnect();
            conn.OpenConnect();
            string         sql = "select * from tbEmployees";
            SqlCommand     cmd = new SqlCommand(sql, conn.Connection);//sqlconnection
            SqlDataAdapter da  = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();

            da.Fill(dt);
            string id = "";

            if (dt.Rows.Count <= 0)
            {
                id = "NV01";
            }
            else
            {
                int k = 0;
                id = "NV";
                k  = Convert.ToInt32(dt.Rows[dt.Rows.Count - 1][0].ToString().Substring(2, 2));
                k += 1;
                if (k < 10)
                {
                    id += "0";
                }
                id += k.ToString();
            }
            return(id);
        }
Пример #2
0
        private void btnDeleteMenu_Click(object sender, EventArgs e)
        {
            DAL.SQLConnect conn = new DAL.SQLConnect();
            conn.OpenConnect();
            string     sqlDelete = "delete from tbDish where ID_dish=@ID_dish";
            SqlCommand cmd       = new SqlCommand(sqlDelete, conn.Connection);//sqlconnection

            cmd.Parameters.AddWithValue("ID_dish", txtIDDish.Text);
            cmd.Parameters.AddWithValue("Name_dish", txtNameDish.Text);
            cmd.Parameters.AddWithValue("Unit_price", txtUnitPrice.Text);
            cmd.ExecuteNonQuery();
            showListMenu();
        }
Пример #3
0
        private void btnAddMenu_Click(object sender, EventArgs e)
        {
            DAL.SQLConnect conn = new DAL.SQLConnect();
            conn.OpenConnect();
            string     sqlAdd = "insert into tbDish values(@ID_dish,@Name_dish,@Unit_price)";
            SqlCommand cmd    = new SqlCommand(sqlAdd, conn.Connection);//sqlconnection

            cmd.Parameters.AddWithValue("ID_dish", txtIDDish.Text);
            cmd.Parameters.AddWithValue("Name_dish", txtNameDish.Text);
            cmd.Parameters.AddWithValue("Unit_price", txtUnitPrice.Text);
            cmd.ExecuteNonQuery();
            showListMenu();
        }
Пример #4
0
        private void btnSearchDish_Click(object sender, EventArgs e)
        {
            DAL.SQLConnect conn = new DAL.SQLConnect();
            conn.OpenConnect();
            string     sqlSearchID = "select* from tbDish where ID_dish=@ID_dish";
            SqlCommand cmd         = new SqlCommand(sqlSearchID, conn.Connection);//sqlconnection

            cmd.Parameters.AddWithValue("ID_dish", txtSearchDish.Text);
            cmd.ExecuteNonQuery();
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable     dt = new DataTable();

            dt.Load(dr);
            dGvMenu.DataSource = dt;
        }