Ejemplo n.º 1
0
        private void UpdateRecordInDatabase()
        {
            Params.spU_tblProduct Param = new Params.spU_tblProduct(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_Pro_GuidID = this.currentID;

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

            if (Control_Pro_CurPrice.Text.Trim() != String.Empty)
            {
                Param.Param_Pro_CurPrice = (System.Data.SqlTypes.SqlMoney)Control_Pro_CurPrice.GetSqlTypesValue;
            }

            if (Control_Pro_LngCategoryID.SelectedIndex != -1)
            {
                Param.Param_Pro_LngCategoryID = (System.Int32)Control_Pro_LngCategoryID.SelectedValue;
            }

            SPs.spU_tblProduct SP = new SPs.spU_tblProduct(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_tblProduct", "UpdateRecordInDatabase");
                }
            }
        }
Ejemplo n.º 2
0
        public void Edit_Product(Tables.Product record)
        {
            Params.spU_tblProduct param = new Params.spU_tblProduct(false);

            param.SetUpConnection(string.Empty);

            param.Param_Pro_GuidID = record.Col_Pro_GuidID.Value;

            if (record.Name == null || record.Name.UseNull)
            {
                param.Param_ConsiderNull_Pro_StrName = true;
                param.Param_Pro_StrName = SqlString.Null;
            }
            else if (!record.Name.UseDefault)
            {
                param.Param_Pro_StrName = record.Name.Value;
            }

            if (record.Col_Pro_CurPrice == null || record.Col_Pro_CurPrice.UseNull)
            {
                param.Param_ConsiderNull_Pro_CurPrice = true;
                param.Param_Pro_CurPrice = SqlMoney.Null;
            }
            else if (!record.Col_Pro_CurPrice.UseDefault)
            {
                param.Param_Pro_CurPrice = record.Col_Pro_CurPrice.Value;
            }

            if (record.CategoryID == null || record.CategoryID.UseNull)
            {
                param.Param_ConsiderNull_Pro_LngCategoryID = true;
                param.Param_Pro_LngCategoryID = SqlInt32.Null;
            }
            else if (!record.CategoryID.UseDefault)
            {
                param.Param_Pro_LngCategoryID = record.CategoryID.Value;
            }


            using (SPs.spU_tblProduct sp = new SPs.spU_tblProduct(true)) {
                sp.Execute(ref param);
                param.Dispose();
            }
        }
Ejemplo n.º 3
0
        private void cmdUpdate_Click(object sender, System.EventArgs e)
        {
            if (!CheckValues())
            {
                return;
            }

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

                Param = new Params.spU_tblProduct();

                Param.SetUpConnection(ConnectionString);

                Param.Param_Pro_GuidID = CurrentID;

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

                if (txt_Pro_CurPrice.Text.Trim() != String.Empty)
                {
                    Param.Param_Pro_CurPrice = new System.Data.SqlTypes.SqlMoney(System.Convert.ToDecimal(txt_Pro_CurPrice.Text));
                }

                Param.Param_Pro_LngCategoryID = Convert.ToInt32(com_Pro_LngCategoryID.SelectedItem.Value);

                SP = new SPs.spU_tblProduct();

                if (SP.Execute(ref Param))
                {
                    if (ReturnURL.Visible)
                    {
                        Response.Redirect(String.Format("WebForm_tblProduct.aspx?Action=Edit&ID={0}&ReturnToUrl={1}&ReturnToDisplay={2}", CurrentID.ToString(), ReturnURL.NavigateUrl, ReturnURL.Text));
                    }
                    else
                    {
                        Response.Redirect(String.Format("WebForm_tblProduct.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_tblProduct Param = null;
                SPs.spI_tblProduct    SP    = null;

                Param = new Params.spI_tblProduct();

                Param.SetUpConnection(ConnectionString);

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

                if (txt_Pro_CurPrice.Text.Trim() != String.Empty)
                {
                    Param.Param_Pro_CurPrice = new System.Data.SqlTypes.SqlMoney(System.Convert.ToDecimal(txt_Pro_CurPrice.Text));
                }

                Param.Param_Pro_LngCategoryID = Convert.ToInt32(com_Pro_LngCategoryID.SelectedItem.Value);

                SP = new SPs.spI_tblProduct();

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

                    if (Param.OtherException != null)
                    {
                        throw Param.OtherException;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <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_Pro_StrNameWasUpdated);
            ChangesHaveBeenMade = (ChangesHaveBeenMade || col_Pro_CurPriceWasUpdated);
            ChangesHaveBeenMade = (ChangesHaveBeenMade || col_Pro_LngCategoryIDWasUpdated);

            if (!ChangesHaveBeenMade)
            {
                return;
            }

            bool alreadyOpened = false;

            Params.spU_tblProduct Param = new Params.spU_tblProduct(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_Pro_GuidID = this.col_Pro_GuidID;

            if (this.col_Pro_StrNameWasUpdated)
            {
                Param.Param_Pro_StrName = this.col_Pro_StrName;
                Param.Param_ConsiderNull_Pro_StrName = true;
            }
            else
            {
                Param.Param_Pro_StrName = SqlString.Null;
                Param.Param_ConsiderNull_Pro_StrName = false;
            }

            if (this.col_Pro_CurPriceWasUpdated)
            {
                Param.Param_Pro_CurPrice = this.col_Pro_CurPrice;
                Param.Param_ConsiderNull_Pro_CurPrice = true;
            }
            else
            {
                Param.Param_Pro_CurPrice = SqlMoney.Null;
                Param.Param_ConsiderNull_Pro_CurPrice = false;
            }

            if (this.col_Pro_LngCategoryIDWasUpdated)
            {
                Param.Param_Pro_LngCategoryID = this.col_Pro_LngCategoryID;
                Param.Param_ConsiderNull_Pro_LngCategoryID = true;
            }
            else
            {
                Param.Param_Pro_LngCategoryID = SqlInt32.Null;
                Param.Param_ConsiderNull_Pro_LngCategoryID = false;
            }

            SPs.spU_tblProduct Sp = new SPs.spU_tblProduct(false);
            if (Sp.Execute(ref Param))
            {
                this.col_Pro_StrNameWasUpdated       = false;
                this.col_Pro_CurPriceWasUpdated      = false;
                this.col_Pro_LngCategoryIDWasUpdated = false;
            }
            else
            {
                throw new OlymarsDemo.DataClasses.CustomException(Param, "OlymarsDemo.BusinessComponents.Product", "Update");
            }
            CloseConnection(Sp.Connection, alreadyOpened);
        }
Ejemplo n.º 5
0
        public void Execute(WSGuid Pro_GuidID, WSString Pro_StrName, WSBoolean ConsiderNull_Pro_StrName, WSDecimal Pro_CurPrice, WSBoolean ConsiderNull_Pro_CurPrice, WSInt32 Pro_LngCategoryID, WSBoolean ConsiderNull_Pro_LngCategoryID)
        {
            Params.spU_tblProduct param = new Params.spU_tblProduct(true);
            param.SetUpConnection(string.Empty);

            if (Pro_GuidID == null || Pro_GuidID.UseNull)
            {
                param.Param_Pro_GuidID = SqlGuid.Null;
            }
            else if (!Pro_GuidID.UseDefault)
            {
                param.Param_Pro_GuidID = Pro_GuidID.Value;
            }

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

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

            if (Pro_CurPrice == null || Pro_CurPrice.UseNull)
            {
                param.Param_Pro_CurPrice = SqlMoney.Null;
            }
            else if (!Pro_CurPrice.UseDefault)
            {
                param.Param_Pro_CurPrice = Pro_CurPrice.Value;
            }

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

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

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

            using (SPs.spU_tblProduct sp = new SPs.spU_tblProduct(true)) {
                sp.Execute(ref param);
                param.Dispose();
            }
        }