// INSERT:
        public static int Insert(CT_DonTraHangDTO p)
        {
            try
            {
                // B1: Create object to connect CSDL and open connection:
                _connection = new SqlConnection(_connectionString);
                _connection.Open();

                // B2: Build sql command:
                String procName = "spInsertNewCTDTH";
                //  private string _maDTH, _maMH;
                //private int _soLuong, _lyDoTra;
                // B3: Create object to execute sql command:
                _command             = new SqlCommand(procName);
                _command.CommandType = CommandType.StoredProcedure;
                _command.Connection  = _connection;

                // Transmission parameters into PROC:
                _command.Parameters.Add("@maDTH", SqlDbType.VarChar);
                _command.Parameters.Add("@maMH", SqlDbType.VarChar);
                _command.Parameters.Add("@soLuong", SqlDbType.Int);
                _command.Parameters.Add("@lyDo", SqlDbType.Int);

                // Transmission value for parameter:
                _command.Parameters["@maDTH"].Value   = p.MaDTH;
                _command.Parameters["@maMH"].Value    = p.MaMH;
                _command.Parameters["@soLuong"].Value = p.SoLuong;
                _command.Parameters["@lyDo"].Value    = p.LyDoTra; //-- 0: Hết hạn, 1: Hỏng, 2: Bán không chạy.

                // B4: Execute sql command and get returned value:
                int n  = _command.ExecuteNonQuery();
                int id = -1;
                if (n > 0)
                {
                    id = 1;
                }

                // B5:
                _connection.Close();
                return(id);
            }
            catch
            {
                return(-1);
            }
        }
Пример #2
0
        private void btnThemCT_DTH_Click(object sender, EventArgs e)
        {
            CT_DonTraHangDTO p = new CT_DonTraHangDTO();

            p.MaDTH = maDTH;
            MessageBox.Show("p.MaDTH = " + maDTH);
            p.MaMH    = cbbMaMH.Text;
            p.SoLuong = int.Parse(txtSoLuong.Text);
            p.LyDoTra = int.Parse(txtLyDo.Text);

            // Handle BUS class to add data:
            int n = CT_DonTraHangBUS.Insert(p);

            if (n > 0)
            {
                MessageBox.Show("Insert successfully!!!");
            }
            else
            {
                MessageBox.Show("Failed !!!");
            }
        }
Пример #3
0
        public static int Insert(CT_DonTraHangDTO p)
        {
            int n = CT_DonTraHangDAO.Insert(p);

            return(n);
        }