コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="purchasing"></param>
        /// <returns></returns>
        internal static bool AddItems(Purchasing purchasing)
        {
            var rowsAffected = 0;

            using (OleDbCommand dbCommand = new OleDbCommand())
            {
                // Set the command object properties
                dbCommand.Connection  = new OleDbConnection(ConnectionString);
                dbCommand.CommandType = CommandType.Text;
                dbCommand.CommandText = "Insert Into [Purchasing$] (SlNo, ItemName, Purchased, DateCreated, DateModified)" +
                                        " Values (@slno, @itemName, @purchased, @dateCreated, @dateModified)";

                // Update the input parameters to the parameter collection
                dbCommand.Parameters.AddWithValue("@slno", purchasing.SlNo);
                dbCommand.Parameters.AddWithValue("@itemName", purchasing.ItemName);
                dbCommand.Parameters.AddWithValue("@purchased", purchasing.Purchased);
                dbCommand.Parameters.AddWithValue("@dateCreated", purchasing.DateCreated.ToShortDateString());
                dbCommand.Parameters.AddWithValue("@dateModified", purchasing.DateModified.ToShortDateString());


                // Open the connection, execute the query and close the connection
                dbCommand.Connection.Open();
                rowsAffected = dbCommand.ExecuteNonQuery();
                dbCommand.Connection.Close();
            }
            return(rowsAffected > 0);
        }
コード例 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DataTable data = DataAccess.GetLastId();

            {
                slno = int.Parse(data.Rows[0]["Expr1000"].ToString()) + 1;
            }
            if (txtItemName.Text.Trim() != string.Empty)
            {
                itemname     = txtItemName.Text;
                purchased    = false;
                dateCreated  = DateTime.Now;
                dateModified = DateTime.Now;

                Purchasing purchasing = new Purchasing()
                {
                    SlNo         = slno,
                    ItemName     = itemname,
                    Purchased    = purchased,
                    DateCreated  = dateCreated,
                    DateModified = dateModified
                };
                var success = DataAccess.AddItems(purchasing);
                if (success)
                {
                    //MessageBox.Show("Items Added Successfully");
                    LoadDataGridView(DataAccess.GetAllItems());
                }
                txtItemName.Text = "";
                txtItemName.Focus();
            }
            else
            {
                MessageBox.Show("Item Name cannot be empty");
                txtItemName.Focus();
            }
        }