コード例 #1
0
        // Button 'Save'
        // Validate input and insert into database
        private void buttonNewFolioConfirm_Click(object sender, EventArgs e)
        {
            Boolean folioexists = false;

            // Validate that guest is selcted and folio has items
            if (listBoxGuest.SelectedIndex > -1 && listBoxFolioItem.Items.Count > 0)
            {
                // Reference variables
                int    guestid = Convert.ToInt32(listBoxGuest.SelectedValue);
                string adminid = UserInfo.AdminID;

                // Check -> Folio does not exist
                if (DBGetData.GetFolioExists(guestid) > 0)
                {
                    folioexists = true;
                }
                if (folioexists)
                {
                    MessageBox.Show("Guest already has an active folio, add any changes to existing.");
                }

                if (!folioexists)
                {
                    // Create new folio
                    DBSetData.FolioAdd(guestid, adminid);
                    // Fetch newly created folioid
                    MySqlDataReader getFolioid = DBGetData.GetFolioid(guestid);
                    if (getFolioid.Read())
                    {
                        // Add folio items to folio
                        int folioid = getFolioid.GetInt32(0);

                        foreach (DataRowView drv in listBoxFolioItem.Items)
                        {
                            int billingitemid = int.Parse(drv.Row[listBoxFolioItem.ValueMember].ToString());
                            DBSetData.FolioItemAdd(folioid, billingitemid, adminid);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Could not fetch newly created folioid, try again or contact administrator.");
                    }
                    getFolioid.Dispose();

                    // Refresh datagridview, close form and display new StatusMessage
                    folioForm.LoadDataFolio();
                    folioForm.Refresh();
                    this.Close();
                    new StatusMessage("Folio with " + listBoxFolioItem.Items.Count + " items added.");
                }
            }
        }