Beispiel #1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (validateLoanSpecies())
            {
                MessageBoxResult response = MessageBox.Show("Do you want to Process this Loan Transaction?",
                                                            "Confirm Transaction",
                                                            MessageBoxButton.YesNo,
                                                            MessageBoxImage.Question);
                if (response == MessageBoxResult.Yes)
                {
                    int                status;
                    string             loanStatus = (StaticData.role == "STUDENT ASSISTANT") ? "Requesting" : "Approved";
                    string             loanNumber = "";
                    DatabaseConnection connection = new DatabaseConnection();

                    connection.setStoredProc("dbo.procProcessLoan");
                    connection.addSprocParameter("@collectorName", SqlDbType.VarChar, lblCollector.Text);
                    connection.addSprocParameter("@startDate", SqlDbType.Date, loanDate);
                    connection.addSprocParameter("@endDate", SqlDbType.Date, returnDate);
                    connection.addSprocParameter("@purpose", SqlDbType.VarChar, lblPurpose.Text);
                    connection.addSprocParameter("@status", SqlDbType.VarChar, loanStatus);
                    status = connection.executeProcedure();

                    if (status == 0)
                    {
                        connection.setQuery("SELECT strLoanNumber " +
                                            "FROM viewPlantLoans " +
                                            "WHERE strCollector = @collector AND dateLoan = @startdate AND dateReturning = @enddate");
                        connection.addParameter("@collector", SqlDbType.VarChar, lblCollector.Text);
                        connection.addParameter("@startdate", SqlDbType.Date, loanDate);
                        connection.addParameter("@enddate", SqlDbType.Date, returnDate);

                        SqlDataReader sqlData = connection.executeResult();
                        while (sqlData.Read())
                        {
                            loanNumber = sqlData[0].ToString();
                        }
                        connection.closeResult();

                        foreach (ListSpecies list in dgrTaxonSpecies.Items)
                        {
                            if (list.IsChecked)
                            {
                                connection.setStoredProc("dbo.procLoanPlants");
                                connection.addSprocParameter("@loanNumber", SqlDbType.VarChar, loanNumber);
                                connection.addSprocParameter("@taxonName", SqlDbType.VarChar, list.TaxonName);
                                connection.addSprocParameter("@copies", SqlDbType.Int, list.Copies);
                                status = connection.executeProcedure();

                                if (status == 1)
                                {
                                    break;
                                }
                            }
                        }

                        switch (status)
                        {
                        case 0:
                            MessageBox.Show("Plant Deposit Transaction Processed Successfully");
                            break;

                        case 1:
                            MessageBox.Show("Plant Deposit Transaction Processed with Some Error Records");
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("The System had run to an Error");
                    }
                }

                pnlPlantLoaningForm.Visibility = Visibility.Hidden;
                getLoanTable();
            }
        }
Beispiel #2
0
        private void btnClassify_Click(object sender, RoutedEventArgs e)
        {
            getAvailableBoxes();

            // Database - Program Declaration
            DatabaseConnection connection     = new DatabaseConnection();
            HerbariumSheet     herbariumSheet = dgrHerbariumSheets.SelectedValue as HerbariumSheet;

            // Query Command Setting
            connection.setQuery("SELECT strAccessionNumber, strReferenceAccession, picHerbariumSheet, " +
                                "strFamilyName, strScientificName, strCommonName, CONVERT(VARCHAR, dateCollected, 107), " +
                                "CONVERT(VARCHAR, dateDeposited, 107), CONVERT(VARCHAR, dateVerified, 107), strFullLocality, " +
                                "strCollector, strValidator, strDescription " +
                                "FROM viewHerbariumSheet " +
                                "WHERE strAccessionNumber = @accessionNo");
            connection.addParameter("@accessionNo", SqlDbType.VarChar, herbariumSheet.AccessionNumber);

            // Query Execution
            SqlDataReader sqlData = connection.executeResult();

            // Query Result
            while (sqlData.Read())
            {
                string family = sqlData[3].ToString();

                var result = from box in availableBoxes
                             where box.Family == family
                             where box.BoxLimit > 0
                             select box.BoxNumber;

                if (result.Count() == 0)
                {
                    MessageBox.Show("No Available Family Box for this Herbarium Sheet");
                }
                else
                {
                    try
                    {
                        byte[] tempBlob = (byte[])sqlData[2];
                        picHerbariumSheet.Source = getHerbariumSheet(tempBlob);
                    } catch (Exception) { }

                    lblAccessionNumber.Text = sqlData[0].ToString();
                    lblReferenceNumber.Text = sqlData[1].ToString();
                    lblScientificName.Text  = sqlData[4].ToString();
                    lblCommonName.Text      = sqlData[5].ToString();
                    lblDateCollected.Text   = sqlData[6].ToString();
                    lblDateDeposited.Text   = sqlData[7].ToString();
                    lblDateVerified.Text    = sqlData[8].ToString();
                    lblLocality.Text        = sqlData[9].ToString();
                    lblCollector.Text       = sqlData[10].ToString();
                    lblValidator.Text       = sqlData[11].ToString();
                    lblDescription.Text     = sqlData[12].ToString();

                    lblBox.Text        = result.First();
                    lblFamilyName.Text = "  [" + sqlData[3].ToString() + "]";

                    pnlPlantDeposit.Visibility = Visibility.Visible;
                }
            }
            connection.closeResult();
        }