Beispiel #1
0
        protected ResultExec execute(string query, CommandType type, params SqlParameter[] param)
        {
            ResultExec rs = new ResultExec();

            OpenConnection();

            try
            {
                SqlCommand cmd = new SqlCommand(query, con);
                cmd.CommandType = type;
                if (type == CommandType.StoredProcedure)
                {
                    cmd.Parameters.AddRange(param);
                }
                rs.resultNumber = cmd.ExecuteNonQuery();

                rs.resultText = rs.resultNumber + " row(s) affected";

                cmd.Dispose();
            }
            catch (Exception ex) {
                rs.resultText = "Lỗi: " + ex.Message;
            }
            con.Close();
            return(rs);
        }
Beispiel #2
0
        protected bool execDeleteA(string query)
        {
            ResultExec rs = execute(query, System.Data.CommandType.Text);

            if (rs.resultNumber > 0)
            {
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        protected void execUpdate(string query, T entity, CommandType type = CommandType.Text, params SqlParameter[] param)
        {
            lblMessage.Text = "...Processing...";
            ResultExec rs = execute(query, type, param);

            if (rs.resultNumber > 0)
            {
                UpdateRow(entity);
            }

            lblMessage.Text = rs.resultText;
        }
Beispiel #4
0
        protected void execDelete(string query, CommandType type = CommandType.Text, params SqlParameter[] param)
        {
            lblMessage.Text = "...Processing...";
            ResultExec rs = execute(query, type, param);

            if (rs.resultNumber > 0)
            {
                DeleteRow();
            }

            lblMessage.Text = rs.resultText;
            cellclick(dtGrid.CurrentRow);
        }
Beispiel #5
0
        protected void execInsert(string query, T entity, CommandType type = CommandType.Text, params SqlParameter[] param)
        {
            lblMessage.Text = "...Processing...";
            ResultExec rs = execute(query, type, param);

            if (rs.resultNumber > 0)
            {
                InsertNewRow(entity);
                rs.resultText = "Insert Successfully";
            }

            lblMessage.Text = rs.resultText;
        }
Beispiel #6
0
        protected int execInsert(string query, params SqlParameter[] param)
        {
            lblMessage.Text = "...Processing...";
            ResultExec rs = executeReturnValue(query, param);

            if (rs.resultNumber > 0)
            {
                lblMessage.Text = "Insert Successfully";

                return(rs.resultNumber);
            }

            lblMessage.Text = rs.resultText;
            return(-1);
        }
Beispiel #7
0
        private ResultExec executeReturnValue(string query, params SqlParameter[] param)
        {
            ResultExec rs = new ResultExec();

            OpenConnection();

            try
            {
                SqlCommand cmd = new SqlCommand(query, con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddRange(param);
                rs.resultNumber = int.Parse(cmd.ExecuteScalar().ToString());

                rs.resultText = rs.resultNumber + " row(s) affected";

                cmd.Dispose();
            }
            catch (Exception ex)
            {
                rs.resultText = "Lỗi: " + ex.Message;
            }
            con.Close();
            return(rs);
        }
Beispiel #8
0
        public int XoaTN(string MaQHGD)
        {
            ResultExec result = execute("delete QUAN_HE_GIA_DINH where MAQHGD=" + MaQHGD, System.Data.CommandType.Text);

            return(result.resultNumber);
        }