private void AddRecordInDatabase()
        {
            Params.spI_tblCustomer Param = new Params.spI_tblCustomer(false);

            switch (this.lastKnownConnectionType)
            {
            case OlymarsDemo.DataClasses.ConnectionType.ConnectionString:
                Param.SetUpConnection(this.connectionString);
                break;

            case OlymarsDemo.DataClasses.ConnectionType.SqlConnection:
                Param.SetUpConnection(this.sqlConnection);
                break;
            }

            if (Control_Cus_StrLastName.Text.Trim() != String.Empty)
            {
                Param.Param_Cus_StrLastName = (System.Data.SqlTypes.SqlString)Control_Cus_StrLastName.GetSqlTypesValue;
            }

            if (Control_Cus_StrFirstName.Text.Trim() != String.Empty)
            {
                Param.Param_Cus_StrFirstName = (System.Data.SqlTypes.SqlString)Control_Cus_StrFirstName.GetSqlTypesValue;
            }

            if (Control_Cus_StrEmail.Text.Trim() != String.Empty)
            {
                Param.Param_Cus_StrEmail = (System.Data.SqlTypes.SqlString)Control_Cus_StrEmail.GetSqlTypesValue;
            }

            SPs.spI_tblCustomer SP = new SPs.spI_tblCustomer(false);

            if (SP.Execute(ref Param))
            {
                this.parameter       = Param;
                this.errorHasOccured = false;
            }
            else
            {
                this.errorHasOccured = true;
                if (Param.SqlException != null && Param.SqlException.Number == 2627)
                {
                    MessageBox.Show(this, "Unable to add this record:\r\n\r\n" + Param.SqlException.Message, "Error");
                }
                else
                {
                    throw new OlymarsDemo.DataClasses.CustomException(Param, "OlymarsDemo.Windows.Forms.WinForm_tblCustomer", "AddRecordInDatabase");
                }
            }
        }
        public void Execute(WSInt32 Cus_LngID, WSString Cus_StrLastName, WSString Cus_StrFirstName, WSString Cus_StrEmail)
        {
            Params.spI_tblCustomer param = new Params.spI_tblCustomer(true);
            param.SetUpConnection(string.Empty);

            if (Cus_LngID == null || Cus_LngID.UseNull)
            {
                param.Param_Cus_LngID = SqlInt32.Null;
            }
            else if (!Cus_LngID.UseDefault)
            {
                param.Param_Cus_LngID = Cus_LngID.Value;
            }

            if (Cus_StrLastName == null || Cus_StrLastName.UseNull)
            {
                param.Param_Cus_StrLastName = SqlString.Null;
            }
            else if (!Cus_StrLastName.UseDefault)
            {
                param.Param_Cus_StrLastName = Cus_StrLastName.Value;
            }

            if (Cus_StrFirstName == null || Cus_StrFirstName.UseNull)
            {
                param.Param_Cus_StrFirstName = SqlString.Null;
            }
            else if (!Cus_StrFirstName.UseDefault)
            {
                param.Param_Cus_StrFirstName = Cus_StrFirstName.Value;
            }

            if (Cus_StrEmail == null || Cus_StrEmail.UseNull)
            {
                param.Param_Cus_StrEmail = SqlString.Null;
            }
            else if (!Cus_StrEmail.UseDefault)
            {
                param.Param_Cus_StrEmail = Cus_StrEmail.Value;
            }

            using (SPs.spI_tblCustomer sp = new SPs.spI_tblCustomer(true)) {
                sp.Execute(ref param);
                param.Dispose();
            }
        }
Пример #3
0
        public Int32 Add_tblCustomer_Record(Tables.tblCustomer_Record record)
        {
            Params.spI_tblCustomer param = new Params.spI_tblCustomer(true);

            param.SetUpConnection(string.Empty);

            if (record.Customer_Surname == null || record.Customer_Surname.UseNull)
            {
                param.Param_Cus_StrLastName = SqlString.Null;
            }
            else if (!record.Customer_Surname.UseDefault)
            {
                param.Param_Cus_StrLastName = record.Customer_Surname.Value;
            }

            if (record.Col_Cus_StrFirstName == null || record.Col_Cus_StrFirstName.UseNull)
            {
                param.Param_Cus_StrFirstName = SqlString.Null;
            }
            else if (!record.Col_Cus_StrFirstName.UseDefault)
            {
                param.Param_Cus_StrFirstName = record.Col_Cus_StrFirstName.Value;
            }

            if (record.Col_Cus_StrEmail == null || record.Col_Cus_StrEmail.UseNull)
            {
                param.Param_Cus_StrEmail = SqlString.Null;
            }
            else if (!record.Col_Cus_StrEmail.UseDefault)
            {
                param.Param_Cus_StrEmail = record.Col_Cus_StrEmail.Value;
            }


            using (SPs.spI_tblCustomer sp = new SPs.spI_tblCustomer(true)) {
                sp.Execute(ref param);
                Int32 id = param.Param_Cus_LngID.Value;
                param.Dispose();

                return(id);
            }
        }
Пример #4
0
        private void cmdUpdate_Click(object sender, System.EventArgs e)
        {
            if (!CheckValues())
            {
                return;
            }

            if (Action == ActionEnum.Edit)
            {
                Params.spU_tblCustomer Param = null;
                SPs.spU_tblCustomer    SP    = null;

                Param = new Params.spU_tblCustomer();

                Param.SetUpConnection(ConnectionString);

                Param.Param_Cus_LngID = CurrentID;

                if (txt_Cus_StrLastName.Text.Trim() != String.Empty)
                {
                    Param.Param_Cus_StrLastName = new System.Data.SqlTypes.SqlString(txt_Cus_StrLastName.Text);
                }

                if (txt_Cus_StrFirstName.Text.Trim() != String.Empty)
                {
                    Param.Param_Cus_StrFirstName = new System.Data.SqlTypes.SqlString(txt_Cus_StrFirstName.Text);
                }

                if (txt_Cus_StrEmail.Text.Trim() != String.Empty)
                {
                    Param.Param_Cus_StrEmail = new System.Data.SqlTypes.SqlString(txt_Cus_StrEmail.Text);
                }

                SP = new SPs.spU_tblCustomer();

                if (SP.Execute(ref Param))
                {
                    if (ReturnURL.Visible)
                    {
                        Response.Redirect(String.Format("WebForm_tblCustomer.aspx?Action=Edit&ID={0}&ReturnToUrl={1}&ReturnToDisplay={2}", CurrentID.ToString(), ReturnURL.NavigateUrl, ReturnURL.Text));
                    }
                    else
                    {
                        Response.Redirect(String.Format("WebForm_tblCustomer.aspx?Action=Edit&ID={0}", CurrentID.ToString()));
                    }
                    return;
                }
                else
                {
                    if (Param.SqlException != null)
                    {
                        throw Param.SqlException;
                    }

                    if (Param.OtherException != null)
                    {
                        throw Param.OtherException;
                    }
                }
            }

            else
            {
                Params.spI_tblCustomer Param = null;
                SPs.spI_tblCustomer    SP    = null;

                Param = new Params.spI_tblCustomer();

                Param.SetUpConnection(ConnectionString);

                if (txt_Cus_StrLastName.Text.Trim() != String.Empty)
                {
                    Param.Param_Cus_StrLastName = new System.Data.SqlTypes.SqlString(txt_Cus_StrLastName.Text);
                }

                if (txt_Cus_StrFirstName.Text.Trim() != String.Empty)
                {
                    Param.Param_Cus_StrFirstName = new System.Data.SqlTypes.SqlString(txt_Cus_StrFirstName.Text);
                }

                if (txt_Cus_StrEmail.Text.Trim() != String.Empty)
                {
                    Param.Param_Cus_StrEmail = new System.Data.SqlTypes.SqlString(txt_Cus_StrEmail.Text);
                }

                SP = new SPs.spI_tblCustomer();

                if (SP.Execute(ref Param))
                {
                    if (ReturnURL.Visible)
                    {
                        Response.Redirect(String.Format("WebForm_tblCustomer.aspx?Action=Edit&ID={0}&ReturnToUrl={1}&ReturnToDisplay={2}", Param.Param_Cus_LngID.ToString(), ReturnURL.NavigateUrl, ReturnURL.Text));
                    }
                    else
                    {
                        Response.Redirect(String.Format("WebForm_tblCustomer.aspx?Action=Edit&ID={0}", Param.Param_Cus_LngID.ToString()));
                    }
                    return;
                }
                else
                {
                    if (Param.SqlException != null)
                    {
                        throw Param.SqlException;
                    }

                    if (Param.OtherException != null)
                    {
                        throw Param.OtherException;
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// [To be supplied.]
        /// </summary>
        /// <param name="record">[To be supplied.]</param>
        /// <returns>[To be supplied.]</returns>
        public IBusinessComponentRecord Add(IBusinessComponentRecord record)
        {
            tblCustomer_Record recordToAdd = record as tblCustomer_Record;

            if (recordToAdd == null)
            {
                throw new ArgumentException("Invalid record type. Must be 'OlymarsDemo.BusinessComponents.tblCustomer_Record'.", "record");
            }

            bool alreadyOpened = false;

            Params.spI_tblCustomer Param = new Params.spI_tblCustomer(true);
            Param.CommandTimeOut = this.insertCommandTimeOut;
            switch (this.lastKnownConnectionType)
            {
            case OlymarsDemo.DataClasses.ConnectionType.ConnectionString:
                Param.SetUpConnection(this.connectionString);
                break;

            case OlymarsDemo.DataClasses.ConnectionType.SqlConnection:
                Param.SetUpConnection(this.sqlConnection);
                alreadyOpened = (this.sqlConnection.State == System.Data.ConnectionState.Open);
                break;

            case OlymarsDemo.DataClasses.ConnectionType.SqlTransaction:
                Param.SetUpConnection(this.sqlTransaction);
                break;
            }

            Param.Param_Cus_LngID        = recordToAdd.Col_Cus_LngID;
            Param.Param_Cus_StrLastName  = recordToAdd.Customer_Surname;
            Param.Param_Cus_StrFirstName = recordToAdd.Col_Cus_StrFirstName;
            Param.Param_Cus_StrEmail     = recordToAdd.Col_Cus_StrEmail;

            SPs.spI_tblCustomer Sp = new SPs.spI_tblCustomer(false);
            if (Sp.Execute(ref Param))
            {
                tblCustomer_Record newRecord = null;

                switch (this.lastKnownConnectionType)
                {
                case OlymarsDemo.DataClasses.ConnectionType.ConnectionString:
                    newRecord = new tblCustomer_Record(this.connectionString, Param.Param_Cus_LngID);
                    break;

                case OlymarsDemo.DataClasses.ConnectionType.SqlConnection:
                    newRecord = new tblCustomer_Record(this.sqlConnection, Param.Param_Cus_LngID);
                    break;

                case OlymarsDemo.DataClasses.ConnectionType.SqlTransaction:
                    newRecord = new tblCustomer_Record(this.sqlTransaction, Param.Param_Cus_LngID);
                    break;
                }

                CloseConnection(Sp.Connection, alreadyOpened);

                if (internalRecords != null)
                {
                    internalRecords.Add(newRecord);
                }

                if (this.addedRecords == null)
                {
                    this.addedRecords = new System.Collections.ArrayList();
                }
                this.addedRecords.Add(newRecord);

                return(newRecord);
            }
            else
            {
                throw new OlymarsDemo.DataClasses.CustomException(Param, "OlymarsDemo.BusinessComponents.tblCustomer_Collection", "Add");
            }
        }