Beispiel #1
0
        public static int Add(Product obj)
        {
            ProductDataMapper objCaller = new ProductDataMapper();

            return objCaller.Add(obj);
        }
Beispiel #2
0
        public static void Update(Product obj)
        {
            ProductDataMapper objCaller = new ProductDataMapper();

            objCaller.Update(obj);
        }
        private void EditMode()
        {
            if (ObjectID > 0)
            {
                Product _pro = new Product();
                _pro = ProductManager.GetByID(ObjectID);
                if (null == _pro)
                    return;

                txtName.Text = _pro.Name;
                txtSerial.Text = _pro.Serial;
                txtValue.Text = _pro.Value;
                txtPrivatePrice.Text = _pro.PrivatePrice.ToString();
                txtPublicprice.Text = _pro.PublicPrice.ToString();
                ddlCategory.SelectedValue = _pro.CategoryID.ToString();
                dtProductionDate.DbSelectedDate = _pro.ProducingDate;
                txtTax.Text = _pro.Tax.ToString();
                txtDscount.Text = _pro.Discount.ToString();

                plcControls.Visible = true;
            }
        }
Beispiel #4
0
 public void PopulateProduct(SqlDataReader _dtr, Product obj)
 {
     int columnIndex = 0;
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_ID);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.ID = _dtr.GetInt32((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_NAME);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Name = _dtr.GetString((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_SERIAL);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Serial = _dtr.GetString((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_PUBLICPRICE);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.PublicPrice = _dtr.GetDouble((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_PRIVATEPRICE);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.PrivatePrice = _dtr.GetDouble((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_CATEGORYID);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.CategoryID = _dtr.GetInt32((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_PRODUCINGDATE);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.ProducingDate = _dtr.GetString((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_EXPIRYDATE);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.ExpiryDate = _dtr.GetString((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_VALUE);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Value = _dtr.GetString((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_TAX);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Tax = _dtr.GetDouble((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_PICTURE1);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Picture1 = _dtr.GetString((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_PICTURE2);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Picture2 = _dtr.GetString((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_WEIGHT);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Weight = _dtr.GetDouble((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_HEIGHT);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Height = _dtr.GetDouble((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_TAX);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Tax = _dtr.GetDouble((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_DISCOUNT);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Discount = _dtr.GetDouble((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_ISDELETED);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.IsDeleted = _dtr.GetBoolean((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_QUANTITY);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Quantity = _dtr.GetInt32((columnIndex));
     }
     columnIndex = _dtr.GetOrdinal(ProductDataMapper.CN_PRODUCT_PROVIDER);
     if (!_dtr.IsDBNull(columnIndex))
     {
         obj.Provider = _dtr.GetInt32((columnIndex));
     }
 }
Beispiel #5
0
        public int Add(Product obj)
        {
            _connection.ConnectionString = _ConnectionString;
            _command.Connection = _connection;
            _command.CommandType = CommandType.StoredProcedure;
            _command.CommandText = PCN_PRODUCT_ADD;

            #region [Parameters]
            SqlParameter parameterID = new SqlParameter(PN_PRODUCT_ID, SqlDbType.Int);
            parameterID.Value = obj.ID;
            parameterID.Direction = ParameterDirection.Output;
            _command.Parameters.Add(parameterID);
            SqlParameter parameterName = new SqlParameter(PN_PRODUCT_NAME, SqlDbType.NVarChar);
            parameterName.Value = obj.Name;
            parameterName.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterName);
            SqlParameter parameterSerial = new SqlParameter(PN_PRODUCT_SERIAL, SqlDbType.NVarChar);
            parameterSerial.Value = obj.Serial;
            parameterSerial.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterSerial);
            SqlParameter parameterPublicPrice = new SqlParameter(PN_PRODUCT_PUBLICPRICE, SqlDbType.Decimal);
            parameterPublicPrice.Value = obj.PublicPrice;
            parameterPublicPrice.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterPublicPrice);
            SqlParameter parameterPrivatePrice = new SqlParameter(PN_PRODUCT_PRIVATEPRICE, SqlDbType.Decimal);
            parameterPrivatePrice.Value = obj.PrivatePrice;
            parameterPrivatePrice.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterPrivatePrice);
            SqlParameter parameterCategoryID = new SqlParameter(PN_PRODUCT_CATEGORYID, SqlDbType.Int);
            parameterCategoryID.Value = obj.CategoryID;
            parameterCategoryID.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterCategoryID);
            SqlParameter parameterProducingDate = new SqlParameter(PN_PRODUCT_PRODUCINGDATE, SqlDbType.NVarChar);
            parameterProducingDate.Value = obj.ProducingDate;
            parameterProducingDate.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterProducingDate);
            SqlParameter parameterExpiryDate = new SqlParameter(PN_PRODUCT_EXPIRYDATE, SqlDbType.NVarChar);
            parameterExpiryDate.Value = obj.ExpiryDate;
            parameterExpiryDate.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterExpiryDate);
            SqlParameter parameterValue = new SqlParameter(PN_PRODUCT_VALUE, SqlDbType.NVarChar);
            parameterValue.Value = obj.Value;
            parameterValue.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterValue);
            SqlParameter parameterTax = new SqlParameter(PN_PRODUCT_TAX, SqlDbType.Decimal);
            parameterTax.Value = obj.Tax;
            parameterTax.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterTax);
            SqlParameter parameterPicture1 = new SqlParameter(PN_PRODUCT_PICTURE1, SqlDbType.NVarChar);
            parameterPicture1.Value = obj.Picture1;
            parameterPicture1.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterPicture1);
            SqlParameter parameterPicture2 = new SqlParameter(PN_PRODUCT_PICTURE2, SqlDbType.NVarChar);
            parameterPicture2.Value = obj.Picture2;
            parameterPicture2.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterPicture2);
            SqlParameter parameterWeight = new SqlParameter(PN_PRODUCT_WEIGHT, SqlDbType.Decimal);
            parameterWeight.Value = obj.Weight;
            parameterWeight.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterWeight);
            SqlParameter parameterHeight = new SqlParameter(PN_PRODUCT_HEIGHT, SqlDbType.Decimal);
            parameterHeight.Value = obj.Height;
            parameterHeight.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterHeight);
         
            SqlParameter parameterDiscount = new SqlParameter(PN_PRODUCT_DISCOUNT, SqlDbType.Decimal);
            parameterDiscount.Value = obj.Discount;
            parameterDiscount.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterDiscount);
            SqlParameter parameterIsDeleted = new SqlParameter(PN_PRODUCT_ISDELETED, SqlDbType.Bit);
            parameterIsDeleted.Value = obj.IsDeleted;
            parameterIsDeleted.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterIsDeleted);
            SqlParameter parameterQuantity = new SqlParameter(PN_PRODUCT_QUANTITY, SqlDbType.Int);
            parameterQuantity.Value = obj.Quantity;
            parameterQuantity.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterQuantity);
            SqlParameter parameterProvider = new SqlParameter(PN_PRODUCT_PROVIDER, SqlDbType.Int);
            parameterProvider.Value = obj.Provider;
            parameterProvider.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterProvider);
            #endregion;

            _connection.Open();
            _command.ExecuteNonQuery();
            _connection.Close();
            obj.ID = Convert.ToInt32(parameterID.Value);
            return obj.ID;
        }
        void btnSaveUpdate_Click(object sender, EventArgs e)
        {

            Product pro = new Product();
            if (ObjectID <= 0)
            {
                try
                {
                    pro.IsDeleted = false;
                    pro.IsDeleted = false;
                    pro.Name = txtName.Text;
                    pro.CategoryID = Convert.ToInt32(ddlCategory.SelectedValue);
                    pro.Discount = Convert.ToDouble(txtDscount.Text);
                    pro.ExpiryDate = rtExpiryDate.SelectedDate.Value.ToShortDateString();
                    pro.Height = 0;
                    pro.PrivatePrice = Convert.ToDouble(txtPrivatePrice.Text);
                    pro.ProducingDate = dtProductionDate.SelectedDate.Value.ToShortDateString();
                    pro.Provider = 0;
                    pro.PublicPrice = Convert.ToDouble(txtPublicprice.Text);
                    pro.Quantity = 0;
                    pro.Serial = txtSerial.Text;
                    pro.Tax = Convert.ToDouble(txtTax.Text);
                    pro.Value = txtValue.Text;
                    pro.Weight = 0;
                    ProductManager.Add(pro);
                    AddMode();
                    dvProblems.InnerText = "Saved Successfully";
                }
                catch (Exception ex)
                {
                    dvProblems.InnerText = ex.ToString();
                }

            }
            else
            {
                try
                {
                    pro = ProductManager.GetByID(ObjectID);
                    if (null == pro)
                    {
                        dvProblems.InnerText = Resources.ExpressCMS.ResourceManager.GetString(ConstantsManager.UnknowErronOccures);
                        return;
                    }
                    pro.IsDeleted = false;
                    pro.Name = txtName.Text;
                    pro.CategoryID = Convert.ToInt32(ddlCategory.SelectedValue);
                    pro.Discount = Convert.ToDouble(txtDscount.Text);
                    pro.ExpiryDate = rtExpiryDate.SelectedDate.Value.ToShortDateString();
                    pro.Height = 0;
                    pro.PrivatePrice = Convert.ToDouble(txtPrivatePrice.Text);
                    pro.ProducingDate = dtProductionDate.SelectedDate.Value.ToShortDateString();
                    pro.Provider = 0;
                    pro.PublicPrice = Convert.ToDouble(txtPublicprice.Text);
                    pro.Quantity = 0;
                    pro.Serial = txtSerial.Text;
                    pro.Tax = Convert.ToDouble(txtTax.Text);
                    pro.Value = txtValue.Text;
                    pro.Weight = 0;

                    ProductManager.Update(pro);
                    EditMode();
                    dvProblems.InnerText = "Saved Successfully";
                }
                catch (Exception ex)
                {
                    dvProblems.InnerText = ex.ToString();
                }
            }
            BindGrid();
        }
Beispiel #7
0
 public Product GetProduct(SqlDataReader _dtr, IList<Product> colobj)
 {
     Product obj = colobj.Where(t => t.ID == Convert.ToInt32(_dtr[CN_PRODUCT_ID].ToString())).SingleOrDefault();
     if (null == obj)
     {
         obj = new Product();
         colobj.Add(obj);
     }
     return obj;
 }
Beispiel #8
0
        public IList<Product> GetByCategoryID(int catID)
        {

            Product obj = null;

            IList<Product> colobj = null;
            _connection.ConnectionString = _ConnectionString;
            _command.Connection = _connection;
            _command.CommandType = CommandType.StoredProcedure;
            _command.CommandText = PCN_PRODUCT_GETBYCATEGORY;

            SqlParameter parameterCategoryID = new SqlParameter(PN_PRODUCT_CATEGORYID, SqlDbType.Int);
            parameterCategoryID.Value = obj.CategoryID;
            parameterCategoryID.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterCategoryID);

            _connection.Open();
            try
            {
                using (_dtreader = _command.ExecuteReader())
                {
                    if (_dtreader != null && _dtreader.HasRows)
                    {
                        obj = new Product();
                        colobj = new List<Product>();
                        while (_dtreader.Read())
                        {
                            obj = GetProduct(_dtreader, colobj);
                            GetEntityFromReader(_dtreader, obj);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                _dtreader.Close();
                _connection.Close();
            }

            return colobj;
        }
Beispiel #9
0
        public IList<Product> GetAll()
        {

            Product obj = null;

            IList<Product> colobj = null;
            _connection.ConnectionString = _ConnectionString;
            _command.Connection = _connection;
            _command.CommandType = CommandType.StoredProcedure;
            _command.CommandText = PCN_PRODUCT_GETBYID;

            _connection.Open();
            try
            {
                using (_dtreader = _command.ExecuteReader())
                {
                    if (_dtreader != null && _dtreader.HasRows)
                    {
                        obj = new Product();
                        colobj = new List<Product>();
                        while (_dtreader.Read())
                        {
                            obj = GetProduct(_dtreader, colobj);
                            GetEntityFromReader(_dtreader, obj);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                _dtreader.Close();
                _connection.Close();
            }

            return colobj;
        }
Beispiel #10
0
 private void GetEntityFromReader(SqlDataReader _dtr, Product obj)
 {
     PopulateProduct(_dtr, obj);
 }
Beispiel #11
0
        public Product GetByID(int ID)
        {

            Product obj = null;
            _connection.ConnectionString = _ConnectionString;
            _command.Connection = _connection;
            _command.CommandType = CommandType.StoredProcedure;
            _command.CommandText = PCN_PRODUCT_GETBYID;

            #region [Parameters]
            SqlParameter parameterID = new SqlParameter(PN_PRODUCT_ID, SqlDbType.Int);
            parameterID.Value = ID;
            parameterID.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterID);
            #endregion;

            _connection.Open();
            try
            {
                using (_dtreader = _command.ExecuteReader())
                {
                    if (_dtreader != null && _dtreader.HasRows)
                    {
                        obj = new Product();
                        if (_dtreader.Read())
                            GetEntityFromReader(_dtreader, obj);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                _dtreader.Close();
                _connection.Close();
            }

            return obj;
        }