Esempio n. 1
0
        public List <clsFruitModel> RetrieveFruits()
        {
            List <clsFruitModel> result = new List <clsFruitModel>();
            DataSet dataSet             = new DataSet();

            dataSet = masterData.RetrieveFruits();
            if (dataSet?.Tables?.Count == 0 || dataSet?.Tables[0].Rows.Count == 0)
            {
                throw new Exception(Convert.ToString((int)ErrorStatus.LoadDiscountMasterDataFail));
            }

            if (dataSet?.Tables[0]?.Rows.Count > 0)
            {
                foreach (DataRow item in dataSet.Tables[0].Rows)
                {
                    clsFruitModel discount = new clsFruitModel()
                    {
                        iFruitId   = Convert.ToInt32(item[0]),
                        sFruitName = item[1].ToString(),
                    };
                    result.Add(discount);
                }
            }

            return(result);
        }
Esempio n. 2
0
        public clsFruitModel GetFruitByFruitId(int fruitId)
        {
            clsFruitModel result = new clsFruitModel();

            DataSet data = new DataSet();

            if (fruitId == 0)
            {
                throw new Exception();
            }

            data = dataLayer.GetFruitByFruitId(fruitId);
            if (data?.Tables.Count == 0 || data?.Tables[0]?.Rows.Count == 0)
            {
                throw new Exception();
            }

            result = new clsFruitModel()
            {
                iFruitId     = Convert.ToInt32(data.Tables[0].Rows[0][0]),
                sFruitName   = data.Tables[0].Rows[0][1].ToString(),
                sDescription = data.Tables[0].Rows[0][2].ToString(),
                deQuantity   = Convert.ToDecimal(data.Tables[0].Rows[0][3].ToString()),
                eMeasurement = GetMeasurementType(Convert.ToInt32(data.Tables[0].Rows[0][4].ToString())),
                bStatus      = Convert.ToBoolean(data.Tables[0].Rows[0][5].ToString()),
                deUnitPrice  = Convert.ToDecimal(data.Tables[0].Rows[0][6].ToString())
            };

            return(result);
        }
Esempio n. 3
0
        private void LoadFruitByFruitId(int fruitId)
        {
            fruit = businessLayer.GetFruitByFruitId(fruitId);

            txtname.Text                 = fruit.sFruitName;
            txtQuatity.Text              = fruit.deQuantity.ToString();
            txtUnitPrice.Text            = fruit.deUnitPrice.ToString();
            txtDescription.Text          = fruit.sDescription;
            drpMeasureUnit.SelectedValue = Convert.ToString((int)fruit.eMeasurement);
        }
Esempio n. 4
0
        private void LoadFruitByFruitId(int fruitId)
        {
            List <clsDiscountModel> discount = new List <clsDiscountModel>();

            fruit    = BusinessLayer.GetFruitByFruitId(fruitId);
            discount = master.RetrieveDiscount();

            txtAvailable.Text = string.Format("{0} {1}", fruit.deQuantity.ToString(), fruit.eMeasurement);
            txtUnitPrice.Text = string.Format("Rs {0}/{1}", fruit.deUnitPrice.ToString(), fruit.eMeasurement);

            hidAvailable.Value   = fruit.deQuantity.ToString();
            hidUnitPrice.Value   = fruit.deUnitPrice.ToString();
            hidMeasurement.Value = fruit.eMeasurement.ToString();
            hidDiscount.Value    = JsonConvert.SerializeObject(discount);
        }
Esempio n. 5
0
        private DataSet UpsertFruit(clsFruitModel item)
        {
            DataSet   result = new DataSet();
            DataTable data   = new DataTable();

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new Exception();
            }

            connection = new SqlConnection(connectionString);
            connection.Open();
            if (connection == null)
            {
                throw new Exception();
            }

            SqlCommand command = new SqlCommand("tblFruitUpsert", connection)
            {
                CommandType = CommandType.StoredProcedure
            };

            command.Parameters.Add(new SqlParameter("@fruitId", item.iFruitId));
            command.Parameters.Add(new SqlParameter("@name", item.sFruitName));
            command.Parameters.Add(new SqlParameter("@des", item.sDescription));
            command.Parameters.Add(new SqlParameter("@measurement", (int)item.eMeasurement));
            command.Parameters.Add(new SqlParameter("@quantity", item.deQuantity));
            command.Parameters.Add(new SqlParameter("@unitPrice", item.deUnitPrice));
            command.Parameters.Add(new SqlParameter("@stat", item.bStatus));

            data.Load(command.ExecuteReader());
            if (data?.Rows.Count == 0)
            {
                throw new Exception();
            }

            result.Tables.Add(data);

            return(result);
        }
Esempio n. 6
0
        private void RetriveFruit()
        {
            List <clsFruitModel> fruitsId  = new List <clsFruitModel>();
            List <clsFruitModel> fruits    = new List <clsFruitModel>();
            DataTable            dataTable = new DataTable();

            fruitsId = master.RetrieveFruits();

            if (fruitsId.Count > 0)
            {
                foreach (var item in fruitsId)
                {
                    clsFruitModel fruit = new clsFruitModel();
                    fruit = businessLayer.GetFruitByFruitId(item.iFruitId);
                    fruits.Add(fruit);
                }
            }

            dataTable = GenerateCustomColumn(fruits);
            grdInventory.DataSource = dataTable;
            grdInventory.DataBind();
        }
Esempio n. 7
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                clsFruitModel fruitResult = new clsFruitModel()
                {
                    bStatus      = true,
                    deQuantity   = string.IsNullOrWhiteSpace(txtQuatity.Text.Trim()) ? 0 : Convert.ToDecimal(txtQuatity.Text.Trim()),
                    deUnitPrice  = string.IsNullOrWhiteSpace(txtUnitPrice.Text.Trim()) ? 0 : Convert.ToDecimal(txtUnitPrice.Text.Trim()),
                    eMeasurement = clsCommon.GetMeasurementType(Convert.ToInt32(drpMeasureUnit.SelectedValue)),
                    iFruitId     = Convert.ToInt32(drpFruit.SelectedValue),
                    sDescription = txtDescription.Text.Trim(),
                    sFruitName   = txtname.Text.Trim()
                };

                StockSummaryModel result = new StockSummaryModel()
                {
                    objFruit = fruitResult,
                    lstStock = new List <clsStockModel>()
                };

                businessLayer.UpsertInventory(result);
                pnlError.Visible   = false;
                pnlSuccess.Visible = true;

                drpFruit.Items.Clear();
                List <clsFruitModel> fruits = new List <clsFruitModel>();
                fruits = master.RetrieveFruits();

                foreach (var item in fruits)
                {
                    ListItem list = new ListItem(item.sFruitName, item.iFruitId.ToString(), true);
                    drpFruit.Items.Add(list);
                }

                drpFruit.SelectedIndex = 0;
                LoadFruitByFruitId(Convert.ToInt32(drpFruit.SelectedValue));
            }
            catch (FormatException ex)
            {
                pnlError.Visible   = true;
                pnlSuccess.Visible = false;

                switch (Convert.ToInt32(ex.Message))
                {
                case (int)ErrorStatus.InventoryInvalidModel:
                    pnlError.Visible     = true;
                    lblErrorDetails.Text = "Invalid fruit details";
                    break;

                case (int)ErrorStatus.InventoryInvalidFruitName:
                    pnlError.Visible     = true;
                    lblErrorDetails.Text = "Invalid fruit name";
                    break;

                case (int)ErrorStatus.InventoryInvalidQuantity:
                    pnlError.Visible     = true;
                    lblErrorDetails.Text = "Invalid quantity";
                    break;

                case (int)ErrorStatus.InventoryInvalidUnitPrice:
                    pnlError.Visible     = true;
                    lblErrorDetails.Text = "Invalid unit price";
                    break;

                case (int)ErrorStatus.InventorySupplierDetails:
                    pnlError.Visible     = false;
                    lblErrorDetails.Text = "invalid supplier details";
                    break;

                case (int)ErrorStatus.InventoryInvalidDeliveryDate:
                    pnlError.Visible     = false;
                    lblErrorDetails.Text = "Invalid delivery date";
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Response.Redirect(string.Format("~/Error.aspx?stat={0}", (int)ErrorStatus.InventoryConfigurationFail));
            }
        }