private void UpdateRecordInDatabase()
        {
            Params.spU_tblCustomer Param = new Params.spU_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;
            }

            Param.Param_Cus_LngID = this.currentID;

            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.spU_tblCustomer SP = new SPs.spU_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 update this record:\r\n\r\n" + Param.SqlException.Message, "Error");
                }
                else
                {
                    throw new OlymarsDemo.DataClasses.CustomException(Param, "OlymarsDemo.Windows.Forms.WinForm_tblCustomer", "UpdateRecordInDatabase");
                }
            }
        }
Exemplo n.º 2
0
        public void Edit_tblCustomer_Record(Tables.tblCustomer_Record record)
        {
            Params.spU_tblCustomer param = new Params.spU_tblCustomer(false);

            param.SetUpConnection(string.Empty);

            param.Param_Cus_LngID = record.Col_Cus_LngID.Value;

            if (record.Customer_Surname == null || record.Customer_Surname.UseNull)
            {
                param.Param_ConsiderNull_Cus_StrLastName = true;
                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_ConsiderNull_Cus_StrFirstName = true;
                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_ConsiderNull_Cus_StrEmail = true;
                param.Param_Cus_StrEmail = SqlString.Null;
            }
            else if (!record.Col_Cus_StrEmail.UseDefault)
            {
                param.Param_Cus_StrEmail = record.Col_Cus_StrEmail.Value;
            }


            using (SPs.spU_tblCustomer sp = new SPs.spU_tblCustomer(true)) {
                sp.Execute(ref param);
                param.Dispose();
            }
        }
Exemplo n.º 3
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;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Execute(WSInt32 Cus_LngID, WSString Cus_StrLastName, WSBoolean ConsiderNull_Cus_StrLastName, WSString Cus_StrFirstName, WSBoolean ConsiderNull_Cus_StrFirstName, WSString Cus_StrEmail, WSBoolean ConsiderNull_Cus_StrEmail)
        {
            Params.spU_tblCustomer param = new Params.spU_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 (ConsiderNull_Cus_StrLastName == null || ConsiderNull_Cus_StrLastName.UseNull)
            {
                param.Param_ConsiderNull_Cus_StrLastName = SqlBoolean.Null;
            }
            else if (!ConsiderNull_Cus_StrLastName.UseDefault)
            {
                param.Param_ConsiderNull_Cus_StrLastName = ConsiderNull_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 (ConsiderNull_Cus_StrFirstName == null || ConsiderNull_Cus_StrFirstName.UseNull)
            {
                param.Param_ConsiderNull_Cus_StrFirstName = SqlBoolean.Null;
            }
            else if (!ConsiderNull_Cus_StrFirstName.UseDefault)
            {
                param.Param_ConsiderNull_Cus_StrFirstName = ConsiderNull_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;
            }

            if (ConsiderNull_Cus_StrEmail == null || ConsiderNull_Cus_StrEmail.UseNull)
            {
                param.Param_ConsiderNull_Cus_StrEmail = SqlBoolean.Null;
            }
            else if (!ConsiderNull_Cus_StrEmail.UseDefault)
            {
                param.Param_ConsiderNull_Cus_StrEmail = ConsiderNull_Cus_StrEmail.Value;
            }

            using (SPs.spU_tblCustomer sp = new SPs.spU_tblCustomer(true)) {
                sp.Execute(ref param);
                param.Dispose();
            }
        }
        /// <summary>
        /// [To be supplied.]
        /// </summary>
        public void Update()
        {
            if (!this.recordWasLoadedFromDB)
            {
                throw new ArgumentException("No record was loaded from the database. No update is possible.");
            }

            bool ChangesHaveBeenMade = false;

            ChangesHaveBeenMade = (ChangesHaveBeenMade || col_Cus_StrLastNameWasUpdated);
            ChangesHaveBeenMade = (ChangesHaveBeenMade || col_Cus_StrFirstNameWasUpdated);
            ChangesHaveBeenMade = (ChangesHaveBeenMade || col_Cus_StrEmailWasUpdated);

            if (!ChangesHaveBeenMade)
            {
                return;
            }

            bool alreadyOpened = false;

            Params.spU_tblCustomer Param = new Params.spU_tblCustomer(true);
            Param.CommandTimeOut = this.updateCommandTimeOut;
            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 = this.col_Cus_LngID;

            if (this.col_Cus_StrLastNameWasUpdated)
            {
                Param.Param_Cus_StrLastName = this.col_Cus_StrLastName;
                Param.Param_ConsiderNull_Cus_StrLastName = true;
            }
            else
            {
                Param.Param_Cus_StrLastName = SqlString.Null;
                Param.Param_ConsiderNull_Cus_StrLastName = false;
            }

            if (this.col_Cus_StrFirstNameWasUpdated)
            {
                Param.Param_Cus_StrFirstName = this.col_Cus_StrFirstName;
                Param.Param_ConsiderNull_Cus_StrFirstName = true;
            }
            else
            {
                Param.Param_Cus_StrFirstName = SqlString.Null;
                Param.Param_ConsiderNull_Cus_StrFirstName = false;
            }

            if (this.col_Cus_StrEmailWasUpdated)
            {
                Param.Param_Cus_StrEmail = this.col_Cus_StrEmail;
                Param.Param_ConsiderNull_Cus_StrEmail = true;
            }
            else
            {
                Param.Param_Cus_StrEmail = SqlString.Null;
                Param.Param_ConsiderNull_Cus_StrEmail = false;
            }

            SPs.spU_tblCustomer Sp = new SPs.spU_tblCustomer(false);
            if (Sp.Execute(ref Param))
            {
                this.col_Cus_StrLastNameWasUpdated  = false;
                this.col_Cus_StrFirstNameWasUpdated = false;
                this.col_Cus_StrEmailWasUpdated     = false;
            }
            else
            {
                throw new OlymarsDemo.DataClasses.CustomException(Param, "OlymarsDemo.BusinessComponents.tblCustomer_Record", "Update");
            }
            CloseConnection(Sp.Connection, alreadyOpened);
        }