Exemple #1
0
        /// <summary>
        /// Commits the SystemEstimate objects contained in the provided list to the database.
        /// </summary>
        /// <param name="systemEstimateList"></param>
        public void Commit(List <SystemEstimate> systemEstimateList)
        {
            //Convert the systemEstimateLIst into EstimateTransaction form, ready for database commit.
            List <EstimateTransaction> transactionData = ConvertToEstimateTransaction(systemEstimateList);

            if (transactionData != null && transactionData.Count != 0)
            {
                try
                {
                    //Insert a new header entry into the database.
                    SQLControl sql = new SQLControl(ConnectionStringService.GetConnectionString("Estimate"));
                    sql.AddParam("@jobNumber", _jobNumber);
                    sql.AddOutputParam("@estimateID", SqlDbType.Int, 4);
                    int nextEstimateID = (int)sql.GetReturnValueFromStoredProcedure("spInsertEstimateHeader", "@estimateID");

                    //If the new estimate header was successfully added, continue with the process.
                    if (nextEstimateID > 0)
                    {
                        //Assign the estimate ID to the transaction objects.
                        //int newEstimateID = 12;
                        foreach (EstimateTransaction t in transactionData)
                        {
                            t.EstimateID = nextEstimateID;
                        }

                        //Send the transaction list to be inserted in the database.
                        InsertMultipleRecords(transactionData);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message.ToString());
                    throw;
                }
            }
            else
            {
                throw new Exception("Estimate commit aborted because transaction data list failed to populate correctly.");
            }
        }