示例#1
0
    protected override void ExecuteAction(ActionArgs args, ActionResult result)
    {
        if (args.CommandName == "Custom" && args.CommandArgument == "SetQuoteStatusClosed")
        {
            //     args["NewStatusID"].NewValue = "OK";
            //    args["NewStatusID"].Modified = true;

            //    args["MainEquipment"].NewValue = "TRYME";
            //    args["MainEquipment"].Modified = true;

            // Result.ShowAlert("Quote closed." + " O-" + args["NewStatusID"].OldValue + " N-" + args["NewStatusID"].NewValue + " V-" + args["NewStatusID"].Value + " ID-" + args["ID"].Value);

            using (SqlText updatePrice = new SqlText(
                       "update [Quotations] set StatusID=@StatusID where ID=@ID"))
            {
                updatePrice.AddParameter("@StatusID", 5);
                updatePrice.AddParameter("@ID", args["ID"].Value);
                //   updatePrice.ExecuteNonQuery();
            }



            Result.ShowAlert("Quote closed.");
        }

        if (args.CommandName == "Custom" && args.CommandArgument == "SetQuoteStatusSuccess")
        {
            Result.ShowAlert("Quote Successful.");
        }

        if (args.CommandName == "Custom" && args.CommandArgument == "SetQuoteStatusRevision")
        {
            Result.ShowAlert("Quote Revised.");
        }
    }
示例#2
0
    protected override void BeforeSqlAction(ActionArgs args, ActionResult result)
    {
        if (args.CommandName == "Insert" && args["Number"].Value == null)
        {
            String Quote_no = null;
            using (SqlText findPrice = new SqlText(
                       "select dbo.GenerateNewQuotationNumber (@EnqID,1) as enq_no"))
            {
                findPrice.AddParameter("@EnqID", args["EnquiryID"].Value);
                Quote_no = Convert.ToString(findPrice.ExecuteScalar());
            }
            args["Number"].NewValue = Quote_no;
            args["Number"].Modified = true;

            //      args["CreatedByUserID"].NewValue = WindowsIdentity.GetCurrent().Name;
            //      args["CreatedByUserID"].Modified = true;
        }

        //   if (args["CreatedByUsername"].Value == null)

        if (args.CommandName == "Insert" && args["CreatedByUsername"].Value == null)

        {
            MembershipUser User = Membership.GetUser();
            args["CreatedByUsername"].NewValue = User.UserName;
            args["CreatedByUsername"].Modified = true;

            //     args["CreatedByUserID"].NewValue = WindowsIdentity.GetCurrent().Name;
            //      args["CreatedByUserID"].Modified = true;
        }
    }
    /// <summary>
    /// Get any manually submitted jobs.  These are on the BatchJobQueue table.
    /// They are deleted from the table once they have been selected for processing.
    /// </summary>
    /// <returns></returns>
    private static List <JobRequest> AnyManualJobsRequired()
    {
        List <JobRequest> jobs = new List <JobRequest>();

        // safely get jobs that have been manually submitted  (exclude jobs prefixed with ABLE these are processed by the ABLE Commerce site.
        using (Redi.Utility.SqlText select = new SqlText(
                   "Select DBID, RequestName, RequestedDateTimeUtc, Submitted, RequestData " +
                   "From ALL_BatchJobQueue " +
                   "Where Submitted = 0 AND DueDateTimeUtc <= @DueDateTimeUtc AND RequestName Like'ABLE%' "))
        {
            select.AddParameter("@DueDateTimeUtc", DateTime.UtcNow);
            DbDataReader myReader = select.ExecuteReader();
            while (myReader.Read())
            {
                JobRequest job = new JobRequest();
                job.RequestDBID = myReader.GetInt64(0);
                job.Name        = myReader.GetString(1);
                job.RequestedAt = myReader.GetDateTime(2);
                job.Submitted   = myReader.GetBoolean(3);
                job.RequestData = myReader.GetString(4).Trim('?');

                jobs.Add(job);
            }
        }
        return(jobs);
    }
示例#4
0
    //
    protected override void ExecuteAction(ActionArgs args, ActionResult result)
    {
        // Added for project page oes not go well with page name
        if (args.CommandName == "Custom" && args.CommandArgument == "SetProjectStatusClosed")
        {
            using (SqlText updatePrice = new SqlText(
                       "update [Projects] set StatusID=@StatusID where ID=@ID"))
            {
                updatePrice.AddParameter("@StatusID", 2);
                updatePrice.AddParameter("@ID", args["ID"].Value);
                updatePrice.ExecuteNonQuery();
            }


            result.ClientScript = "this.set_lastCommandName(null);" + "this.goToView('grid1');";
            Result.ShowAlert("Project Closed.");
        }
    }
示例#5
0
    private static void SaveEnquiryItems(Order order, Int32 jobId, Store store)
    {
        // Insert each Order Item
        using (SqlText insertItem = new SqlText(
                   "Insert Into [ALL_EnquiryItems] " +
                   "(JobId, ProductId, ProductCode, ProductLink, ProductSupplierName, ProductSupplierPublicUrl, Quantity ) " +
                   "Values (@JobId, @ProductId, @ProductCode, @ProductLink, @ProductSupplierName, @ProductSupplierPublicUrl, @Quantity )", crmConnectionStringName))
        {
            Int16 itemCount = 0;
            // Database connection is held open whilst each item is inserted
            foreach (OrderItem item in order.Items)
            {
                string prodCode = "";
                if (!string.IsNullOrEmpty(item.Sku))
                {
                    prodCode = item.Sku;
                }
                else
                {
                    prodCode = item.Product.ModelNumber;
                }

                string supplierLink = "";
                if (item.Product.CustomFields != null && item.Product.CustomFields.Count > 0)
                {
                    foreach (ProductCustomField fld in item.Product.CustomFields)
                    {
                        if (fld.FieldName == "SupplierPublicURL")
                        {
                            supplierLink = fld.FieldValue;
                        }
                    }
                }

                insertItem.AddParameter("@JobId", jobId);
                insertItem.AddParameter("@ProductId", item.ProductId);
                insertItem.AddParameter("@ProductCode", prodCode);
                insertItem.AddParameter("@ProductLink", store.StoreUrl.Trim() + item.Product.NavigateUrl.Substring(2));
                if (item.Product.Manufacturer != null && item.Product.Manufacturer.Name != null)
                {
                    insertItem.AddParameter("@ProductSupplierName", item.Product.Manufacturer.Name);
                }
                else
                {
                    insertItem.AddParameter("@ProductSupplierName", System.Data.SqlTypes.SqlString.Null);
                }
                insertItem.AddParameter("@ProductSupplierPublicUrl", supplierLink);
                insertItem.AddParameter("@Quantity", item.Quantity);

                int x = insertItem.ExecuteNonQuery();
                insertItem.ClearParameters();
            } // end foreach
        }
    }
示例#6
0
    /// <summary>
    /// Send a request to be processed in the background.
    /// </summary>
    /// <param name="requestName"></param>
    /// <param name="requestData"></param>
    /// <returns></returns>
    public static Boolean RequestBackgroundProcess(BackgroundRequestName requestName, string requestData)
    {
        using (Redi.Utility.SqlText insert = new SqlText(
                   "Insert Into ALL_BatchJobQueue (RequestName, RequestedDateTimeUtc, Submitted, RequestData ) " +
                   "Values (@RequestName, @RequestedDateTimeUtc, @Submitted, @RequestData ) "))
        {
            insert.AddParameter("@RequestName", requestName.ToString("G"));
            insert.AddParameter("@RequestedDateTimeUtc", DateTime.UtcNow);
            insert.AddParameter("@Submitted", 0);
            insert.AddParameter("@RequestData", requestData.TrimStart('?'));

            Int32 wkCount = insert.ExecuteNonQuery();
            if (wkCount == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
示例#7
0
    protected override void BeforeSqlAction(ActionArgs args, ActionResult result)
    {
        if (args.CommandName == "Insert" && args["Number"].Value == null)
        {
            String Enq_no      = null;
            String type_prefix = null;
            using (SqlText findPrice = new SqlText(
                       "select dbo.GenerateNewEnquiryNumber(@ID) as enq_no"))
            {
                findPrice.AddParameter("@ID", args["TypeID"].Value);
                Enq_no = Convert.ToString(findPrice.ExecuteScalar());
            }


            args["Number"].NewValue = Enq_no;
            args["Number"].Modified = true;

            //      args["CreatedByUserID"].NewValue = WindowsIdentity.GetCurrent().Name;
            //      args["CreatedByUserID"].Modified = true;
        }

        //   if (args["CreatedByUsername"].Value == null)

        if (args.CommandName == "Insert" && args["CreatedByUsername"].Value == null)

        {
            MembershipUser User = Membership.GetUser();
            args["CreatedByUsername"].NewValue = User.UserName;
            args["CreatedByUsername"].Modified = true;

            //     args["CreatedByUserID"].NewValue = WindowsIdentity.GetCurrent().Name;
            //      args["CreatedByUserID"].Modified = true;
        }

/*
 *   if (args.CommandName == "Update" && args["ChangedByUsername"].Value == null)
 *
 *      {
 *          MembershipUser User = Membership.GetUser();
 *          args["ChangedByUsername"].NewValue = User.UserName;
 *          args["ChangedByUsername"].Modified = true;
 *
 *          //     args["CreatedByUserID"].NewValue = WindowsIdentity.GetCurrent().Name;
 *          //      args["CreatedByUserID"].Modified = true;
 *
 *      }
 */
    }
 private static Boolean CheckRunManualJob(JobRequest job)
 {
     using (Redi.Utility.SqlText delete = new SqlText(
                "Delete From ALL_BatchJobQueue " +
                "Where DBID = @DBID AND Submitted = 0 "))
     {
         delete.AddParameter("@DBID", job.RequestDBID);
         Int32 wkDelCnt = delete.ExecuteNonQuery();
         if (wkDelCnt == 0)
         {
             return(false);  // no row deleted, so don't run job (another server must have run it)
         }
         else
         {
             return(true);  // row deleted so run job.
         }
     }
 }
        public void r101Implementation(TournamentRegisterMemberModel instance)
        {
            // This is the placeholder for method implementation.

            int     pMemberGroupID = 0, pMemberID = 0;
            decimal pMemberFee = 0m, @SpouseFee = 0m, @ChildrenFee = 0m;
            int     pCaddieID = 0, pBallBoyIDID = 0, pHoleTypeID = 0, pHandiCap = 0;
            int     pMemberCategoryID = 0, pMemberStatusID = 0;
            string  pMemberOfType = "";
            decimal pCaddieFee = 0m, pChildrenBallBoySubsidy = 0m, pSpouseBallBoySubsidy = 0m;
            decimal pBallBoySubsiDy = 0m, pBallBoyFee = 0m, pCildrenCaddieSubsidy = 0m, pSpouseCaddieSubsidy = 0m;
            decimal pCaddieSubsidy = 0m, pGreenFee = 0m, pGolfCartFee = 0m;

            if (instance.MemberID != null)
            {
                pMemberID = Convert.ToInt32(instance.MemberID);
            }
            if (instance.CaddieID != null)
            {
                pCaddieID = Convert.ToInt32(instance.CaddieID);
            }
            if (instance.BallBoyID != null)
            {
                pBallBoyIDID = Convert.ToInt32(instance.BallBoyID);
            }
            if (instance.HoleTypeID != null)
            {
                pHoleTypeID = Convert.ToInt32(instance.HoleTypeID);
            }
            instance.BallBoySubsidy = 0;
            instance.BallBoyFee     = 0;
            instance.CaddieFee      = 0;
            instance.CaddieSubsidy  = 0;
            instance.GameFeeAmount  = 0;
            instance.GolfCartFee    = 0;
            instance.GreenFee       = 0;
            instance.GameFeeAmount  = 0;
            instance.RegDate        = DateTime.Now;

            string strSelect = "";

            if (!String.IsNullOrEmpty(instance.MemberID.ToString()))
            {
                object total = null;
                using (SqlText memInfo = new SqlText(@"select MemberID,MemberCategoryID,MemberStatusID,MemberOfType,HandiCap from MemberInfo where MemberID= @MemberID"))
                {
                    #region [Read Data]
                    memInfo.AddParameter("@MemberID", instance.MemberID);
                    if (memInfo.Read())
                    {
                        if (memInfo["MemberCategoryID"] != DBNull.Value)
                        {
                            pMemberCategoryID = Convert.ToInt32(memInfo["MemberCategoryID"].ToString());
                        }
                        if (memInfo["MemberStatusID"] != DBNull.Value)
                        {
                            pMemberStatusID = Convert.ToInt32(memInfo["MemberStatusID"].ToString());
                        }
                        if (memInfo["MemberOfType"] != DBNull.Value)
                        {
                            pMemberOfType = Convert.ToString(memInfo["MemberOfType"].ToString());
                        }
                        if (memInfo["HandiCap"] != DBNull.Value)
                        {
                            pHandiCap = Convert.ToInt32(memInfo["HandiCap"].ToString());
                        }
                    }
                    #endregion
                    ///UpdateFieldValue("ShipName", findCustomer["ContactName"]);
                    ///
                    #region [Game Fees]
                    //object total = null;
                    using (SqlText Fees = new SqlText(@"select " +
                                                      "    GreenFee,CaddieFee,CaddieSubsidy,SpouseCaddieSubsidy,CildrenCaddieSubsidy, " +
                                                      "    BallBoyFee,BallBoySubsiDy,SpouseBallBoySubsidy,ChildrenBallBoySubsidy, " +
                                                      "    GolfCartFee from dbo.GameFee " +
                                                      "   where  " +
                                                      "    MemberCategoryID = @MemberCategoryID " +
                                                      "    And MemberStatusID = @MemberStatusID " +
                                                      "    And HoleTypeID = @HoleTypeID "
                                                      ))
                    {
                        #region [Read Data]
                        Fees.AddParameter("@MemberCategoryID", pMemberCategoryID);
                        Fees.AddParameter("@MemberStatusID", pMemberStatusID);
                        Fees.AddParameter("@HoleTypeID", pHoleTypeID);
                        if (Fees.Read())
                        {
                            if (Fees["GolfCartFee"] != DBNull.Value)
                            {
                                pGolfCartFee = Convert.ToDecimal(Fees["GolfCartFee"].ToString());
                            }
                            if (Fees["ChildrenBallBoySubsidy"] != DBNull.Value)
                            {
                                pChildrenBallBoySubsidy = Convert.ToDecimal(Fees["ChildrenBallBoySubsidy"].ToString());
                            }
                            if (Fees["SpouseBallBoySubsidy"] != DBNull.Value)
                            {
                                pSpouseBallBoySubsidy = Convert.ToDecimal(Fees["SpouseBallBoySubsidy"].ToString());
                            }
                            if (Fees["BallBoySubsiDy"] != DBNull.Value)
                            {
                                pBallBoySubsiDy = Convert.ToDecimal(Fees["BallBoySubsiDy"].ToString());
                            }
                            if (Fees["BallBoyFee"] != DBNull.Value)
                            {
                                pBallBoyFee         = Convert.ToDecimal(Fees["BallBoyFee"].ToString());
                                instance.BallBoyFee = pBallBoyFee;
                            }


                            if (Fees["GreenFee"] != DBNull.Value)
                            {
                                pGreenFee         = Convert.ToDecimal(Fees["GreenFee"].ToString());
                                instance.GreenFee = pGreenFee;
                            }
                            if (Fees["CaddieFee"] != DBNull.Value)
                            {
                                pCaddieFee         = Convert.ToDecimal(Fees["CaddieFee"].ToString());
                                instance.CaddieFee = pCaddieFee;
                            }
                            if (Fees["CaddieSubsidy"] != DBNull.Value)
                            {
                                pCaddieSubsidy         = Convert.ToDecimal(Fees["CaddieSubsidy"].ToString());
                                instance.CaddieSubsidy = pCaddieSubsidy;
                            }
                            if (Fees["SpouseCaddieSubsidy"] != DBNull.Value)
                            {
                                pSpouseCaddieSubsidy = Convert.ToDecimal(Fees["SpouseCaddieSubsidy"].ToString());
                            }
                            if (Fees["CildrenCaddieSubsidy"] != DBNull.Value)
                            {
                                pCildrenCaddieSubsidy = Convert.ToDecimal(Fees["CildrenCaddieSubsidy"].ToString());
                            }
                            #region [BallBoy Fee]
                            if (pBallBoyIDID > 0)
                            {
                                instance.BallBoyFee = pBallBoyFee;
                                if (pMemberOfType == "Full Member")
                                {
                                    instance.BallBoySubsidy = pBallBoySubsiDy;
                                }
                                if (pMemberOfType == "Spouse Of Member")
                                {
                                    instance.BallBoySubsidy = pSpouseBallBoySubsidy;
                                }
                                if (pMemberOfType == "Children Of Member")
                                {
                                    instance.BallBoySubsidy = pChildrenBallBoySubsidy;
                                }
                            }
                            #endregion
                            #region [Caddie Fee]
                            if (pCaddieID > 0)
                            {
                                instance.CaddieFee = pCaddieFee;
                                if (pMemberOfType == "Full Member")
                                {
                                    instance.CaddieSubsidy = pCaddieSubsidy;
                                }
                                if (pMemberOfType == "Spouse Of Member")
                                {
                                    instance.CaddieSubsidy = pSpouseCaddieSubsidy;
                                }
                                if (pMemberOfType == "Children Of Member")
                                {
                                    instance.CaddieSubsidy = pCildrenCaddieSubsidy;
                                }
                            }
                            if (pMemberOfType == "Full Member")
                            {
                                instance.TotalAmount = (pCaddieFee + pGreenFee + pBallBoyFee + pGolfCartFee) - (pCaddieSubsidy + pBallBoySubsiDy);
                            }
                            if (pMemberOfType == "Spouse Of Member")
                            {
                                instance.TotalAmount = (pCaddieFee + pGreenFee + pBallBoyFee + pGolfCartFee) - (pSpouseCaddieSubsidy + pSpouseBallBoySubsidy);
                            }
                            if (pMemberOfType == "Children Of Member")
                            {
                                instance.TotalAmount = (pCaddieFee + pGreenFee + pBallBoyFee + pGolfCartFee) - (pCildrenCaddieSubsidy + pChildrenBallBoySubsidy);
                            }
                            #endregion
                        }
                        #endregion
                        ///UpdateFieldValue("ShipName", findCustomer["ContactName"]);
                    }
                    #endregion
                }
            }
        }
示例#10
0
    protected override void ExecuteAction(ActionArgs args, ActionResult result)
    {
        if (args.CommandName == "Custom" && args.CommandArgument == "SetQuoteStatusClosed")
        {
            //     args["NewStatusID"].NewValue = "OK";
            //    args["NewStatusID"].Modified = true;

            //    args["MainEquipment"].NewValue = "TRYME";
            //    args["MainEquipment"].Modified = true;

            // Result.ShowAlert("Quote closed." + " O-" + args["NewStatusID"].OldValue + " N-" + args["NewStatusID"].NewValue + " V-" + args["NewStatusID"].Value + " ID-" + args["ID"].Value);

            using (SqlText updatePrice = new SqlText(
                       "update [Quotations] set StatusID=@StatusID where ID=@ID"))
            {
                updatePrice.AddParameter("@StatusID", 7);
                updatePrice.AddParameter("@ID", args["ID"].Value);
                updatePrice.ExecuteNonQuery();
            }

            result.ClientScript = "this.set_lastCommandName(null);" + "this.goToView('grid1');";
            Result.ShowAlert("Quote closed.");
        }

        if (args.CommandName == "Custom" && args.CommandArgument == "SetQuoteStatusSuccess")
        {
            using (SqlText updatePrice = new SqlText(
                       "update [Quotations] set StatusID=@StatusID where ID=@ID"))
            {
                updatePrice.AddParameter("@StatusID", 4);
                updatePrice.AddParameter("@ID", args["ID"].Value);
                updatePrice.ExecuteNonQuery();
            }


            result.ClientScript = "this.set_lastCommandName(null);" + "this.goToView('grid1');";
            Result.ShowAlert("Quote Successful.");
        }

        if (args.CommandName == "Custom" && args.CommandArgument == "SetQuoteStatusRevision")
        {
            using (SqlText updatePrice = new SqlText(
                       "update [Quotations] set StatusID=@StatusID where ID=@ID"))
            {
                updatePrice.AddParameter("@StatusID", 6);
                updatePrice.AddParameter("@ID", args["ID"].Value);
                updatePrice.ExecuteNonQuery();
            }


            result.ClientScript = "this.set_lastCommandName(null);" + "this.goToView('grid1');";
            Result.ShowAlert("Quote Revised.");
        }

        // Added for project page oes not go well with page name
        if (args.CommandName == "Custom" && args.CommandArgument == "SetProjectStatusClosed")
        {
            using (SqlText updatePrice = new SqlText(
                       "update [Projects] set StatusID=@StatusID where ID=@ID"))
            {
                updatePrice.AddParameter("@StatusID", 2);
                updatePrice.AddParameter("@ID", args["ID"].Value);
                updatePrice.ExecuteNonQuery();
            }


            result.ClientScript = "this.set_lastCommandName(null);" + "this.goToView('grid1');";
            Result.ShowAlert("Project Closed.");
        }
    }
示例#11
0
        public void r101Implementation(MemberCardTransactionDepositModel instance)
        {
            // This is the placeholder for method implementation.

            string  pMessage          = string.Empty;
            int     pMemberCardID     = Convert.ToInt32(instance.MemberCardID.ToString());
            int     MemberID          = Convert.ToInt32(instance.MemberID.ToString());
            int     pMemberCardTranID = Convert.ToInt32(instance.MemberCardTranID.ToString());
            decimal dDepositedAmount  = 0;

            dDepositedAmount = Convert.ToInt32(instance.DepositAmount.ToString());
            string memMobileNo = "";
            string MemberName  = "";
            string strSelect   = "";

            if (!String.IsNullOrEmpty(instance.MemberID.ToString()))
            {
                object total = null;
                using (SqlText memInfo = new SqlText(@"select MemberID,NameOfMember from MemberInfo where MemberID= @MemberID"))
                {
                    try
                    {
                        #region [Read Data]
                        memInfo.AddParameter("@MemberID", instance.MemberID);
                        if (memInfo.Read())
                        {
                            if (memInfo["NameOfMember"] != DBNull.Value)
                            {
                                MemberName = Convert.ToString(memInfo["NameOfMember"].ToString());
                            }
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                    }
                }
                using (SqlText memInfo = new SqlText(@"select MemberID,MobileNo from Membercard where MemberID= @MemberID and MemberCardID=@MemberCardID"))
                {
                    try
                    {
                        #region [Read Data]
                        memInfo.AddParameter("@MemberID", MemberID);
                        memInfo.AddParameter("@MemberCardID", pMemberCardID);
                        if (memInfo.Read())
                        {
                            if (memInfo["MobileNo"] != DBNull.Value)
                            {
                                memMobileNo = Convert.ToString(memInfo["MobileNo"].ToString());
                            }
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            string[] strmobile;
            if (memMobileNo.Length <= 11)
            {
            }
            strmobile = FormatMobileNo(memMobileNo);
            if (strmobile[0] == "0")
            {
                memMobileNo = strmobile[1].ToString();
                pMessage    = "Please dodnot disclose these pin number.";
                //int iRet = SendSMSTo(MemberCardID, memMobileNo, MemberName, pMessage);
            }
            pMessage = " Received with Thanks. " + dDepositedAmount.ToString() + " Taka";
            SendSMSTo(pMemberCardTranID, memMobileNo, MemberName, pMessage, pMemberCardID, dDepositedAmount);
        }
示例#12
0
    private static void GetCompanyAndClient(Order order, out Int32?companyId, out Int32?clientId)
    {
        companyId = null;
        clientId  = null;

        // See if the client exists
        using (SqlText select = new SqlText(
                   "Select ClientId, FullName, FirstName, LastName, EmailAddress, [ALL_Company].CompanyId, [ALL_Company].CompanyName " +
                   "From [ALL_Client] " +
                   "Left Outer Join [ALL_Company] ON [ALL_Company].CompanyId = [ALL_Client].CompanyId " +
                   "Where EmailAddress = @EmailAddress AND [ALL_Client].Deleted=0 ", crmConnectionStringName))
        {
            select.AddParameter("@EmailAddress", order.BillToEmail.Trim());
            DbDataReader myReader = select.ExecuteReader();
            while (myReader.Read())
            {
                Int32  wkClientId = myReader.GetInt32(0);
                string wkName     = myReader.GetString(1);
                //string wkFirstName = myReader.GetString(2);
                //string wkLastname = myReader.GetString(3);
                string wkEmail     = myReader.GetString(4);
                Int32? wkCompanyId = null;
                if (!myReader.IsDBNull(5))
                {
                    wkCompanyId = myReader.GetInt32(5);
                }
                string wkCompanyName = "";
                if (!myReader.IsDBNull(6))
                {
                    wkCompanyName = myReader.GetString(6);
                }

                clientId  = wkClientId;
                companyId = wkCompanyId;
            }
        }

        if (clientId != null)
        {
            // Found a record so exit.
            return;
        }

        if (!string.IsNullOrEmpty(order.BillToCompany) && companyId == null && clientId == null)
        {
            // See if the company exists
            using (SqlText select = new SqlText(
                       "Select CompanyId, CompanyName " +
                       "From [ALL_Company] " +
                       "Where CompanyName = @CompanyName AND Deleted=0 AND DepartmentName is null ", crmConnectionStringName))
            {
                select.AddParameter("@CompanyName", order.BillToCompany.Trim());
                DbDataReader myReader = select.ExecuteReader();
                while (myReader.Read())
                {
                    companyId = myReader.GetInt32(0);
                }
            }

            if (companyId == null)
            {
                // Not found so create a new company record.
                using (Redi.Utility.SqlText insert = new Redi.Utility.SqlText(
                           "Insert Into ALL_Company (CompanyName, CreatedOn, CreatedByName) " +
                           "Values (@CompanyName, @CreatedOn, @CreatedByName) " +
                           "SELECT SCOPE_IDENTITY(); ", crmConnectionStringName))
                {
                    insert.AddParameter("@CompanyName", order.BillToCompany.Trim());
                    insert.AddParameter("@CreatedOn", GetCurrentStandardTime());
                    insert.AddParameter("@CreatedByName", createdBy);

                    companyId = Convert.ToInt32(insert.ExecuteScalar());
                }
            }
        }

        string wkMobile   = "";
        string wkPhone    = "";
        string wkFax      = "";
        string wkFullName = "";

        if (!string.IsNullOrEmpty(order.BillToFirstName))
        {
            wkFullName = order.BillToFirstName.Trim() + ' ';
        }
        if (!string.IsNullOrEmpty(order.BillToLastName))
        {
            wkFullName = wkFullName + order.BillToLastName.Trim();
        }

        if (!string.IsNullOrEmpty(order.BillToPhone))
        {
            if (order.BillToPhone.Length > 2 && order.BillToPhone.Substring(0, 2) == "04")
            {
                wkMobile = order.BillToPhone;
            }
            else
            {
                wkPhone = order.BillToPhone;
            }
        }

        if (!string.IsNullOrEmpty(order.BillToFax))
        {
            wkFax = order.BillToFax;
        }

        // Not an existing client so create a new record.
        using (Redi.Utility.SqlText insert = new Redi.Utility.SqlText(
                   "Insert Into ALL_Client (FullName, FirstName, LastName, Phone, Fax, MobilePhone, CreatedOn, CreatedByName, EmailAddress, CompanyId ) " +
                   "Values (@FullName, @FirstName, @LastName, @Phone, @Fax, @MobilePhone, @CreatedOn, @CreatedByName, @EmailAddress, @CompanyId) " +
                   "SELECT SCOPE_IDENTITY(); ", crmConnectionStringName))
        {
            insert.AddParameter("@FullName", wkFullName);
            insert.AddParameter("@FirstName", order.BillToFirstName);
            insert.AddParameter("@LastName", order.BillToLastName);
            insert.AddParameter("@Phone", wkPhone);
            insert.AddParameter("@Fax", wkFax);
            insert.AddParameter("@MobilePhone", wkMobile);
            if (companyId != null)
            {
                insert.AddParameter("@CompanyId", companyId);
            }
            else
            {
                insert.AddParameter("@CompanyId", System.Data.SqlTypes.SqlInt32.Null);
            }
            insert.AddParameter("@CreatedOn", GetCurrentStandardTime());
            insert.AddParameter("@CreatedByName", createdBy);
            insert.AddParameter("@EmailAddress", order.BillToEmail);

            clientId = Convert.ToInt32(insert.ExecuteScalar());
        }
    }