Пример #1
0
        public void LoadProduct(string productID)
        {
            //Display specific product
            try
            {
                Accessory = handler.selectAccessory(productID);
                Treatment = handler.selectTreatment(productID);

                tblProducts.Visible = true;

                #region Header
                int count = 0;
                //displaythe table headers
                //create a new row in the table and set the height
                TableRow newRow = new TableRow();
                newRow.Height = 50;
                tblProducts.Rows.Add(newRow);
                //create a header row and set cell widths

                //create a header row and set cell widths
                TableHeaderCell newHeaderCell = new TableHeaderCell();
                tblProducts.Rows.Add(newRow);
                //create a header row and set cell widths
                newHeaderCell       = new TableHeaderCell();
                newHeaderCell.Text  = "Product Description: ";
                newHeaderCell.Width = 300;
                tblProducts.Rows[count].Cells.Add(newHeaderCell);
                count++;

                newRow = new TableRow();
                tblProducts.Rows.Add(newRow);
                newHeaderCell       = new TableHeaderCell();
                newHeaderCell.Text  = "Price: ";
                newHeaderCell.Width = 100;
                tblProducts.Rows[count].Cells.Add(newHeaderCell);
                count++;

                if (Accessory != null)
                {
                    newRow = new TableRow();
                    tblProducts.Rows.Add(newRow);
                    newHeaderCell       = new TableHeaderCell();
                    newHeaderCell.Text  = "Colour: ";
                    newHeaderCell.Width = 100;
                    tblProducts.Rows[count].Cells.Add(newHeaderCell);
                    count++;
                }

                if (cookie != null)
                {
                    if (cookie["UT"] == "M" || cookie["UT"] == "R")
                    {
                        newRow = new TableRow();
                        tblProducts.Rows.Add(newRow);
                        //create a header row and set cell widths
                        newHeaderCell       = new TableHeaderCell();
                        newHeaderCell.Text  = "Brand: ";
                        newHeaderCell.Width = 300;
                        tblProducts.Rows[count].Cells.Add(newHeaderCell);

                        count++;

                        newRow = new TableRow();
                        tblProducts.Rows.Add(newRow);
                        newHeaderCell       = new TableHeaderCell();
                        newHeaderCell.Text  = "Supplier: ";
                        newHeaderCell.Width = 100;
                        tblProducts.Rows[count].Cells.Add(newHeaderCell);
                        count++;

                        //edit BTN Row
                        newRow = new TableRow();
                        tblProducts.Rows.Add(newRow);
                        newHeaderCell       = new TableHeaderCell();
                        newHeaderCell.Width = 100;
                        tblProducts.Rows[count].Cells.Add(newHeaderCell);
                        count++;
                    }
                }
                #endregion

                //track row count & number of products count
                if (Accessory != null)
                {
                    phProductImage.Controls.Add(new LiteralControl
                                                    ("<img width='400' height='400' src='http://sict-iis.nmmu.ac.za/beauxdebut/Theam/img/" + productID + ".jpg'/>"));

                    count           = 0;
                    lblHeadera.Text = Accessory.Name.ToString();

                    TableCell cell = new TableCell();
                    cell.Text = Accessory.ProductDescription.ToString();
                    tblProducts.Rows[count].Cells.Add(cell);
                    count++;

                    cell      = new TableCell();
                    cell.Text = "R" + string.Format("{0:#.00}", Accessory.Price);
                    tblProducts.Rows[count].Cells.Add(cell);
                    count++;

                    cell      = new TableCell();
                    cell.Text = Accessory.Colour;
                    tblProducts.Rows[count].Cells.Add(cell);
                    count++;

                    if (cookie != null)
                    {
                        if (cookie["UT"] == "M" || cookie["UT"] == "R")
                        {
                            cell      = new TableCell();
                            cell.Text = Accessory.Brandname.ToString();
                            tblProducts.Rows[count].Cells.Add(cell);
                            count++;

                            cell      = new TableCell();
                            cell.Text = Accessory.supplierName.ToString();
                            tblProducts.Rows[count].Cells.Add(cell);
                            count++;

                            EditProductBtn.Text = "<a class= 'btn btn-primary' href = '?Action=EditProd&" +
                                                  "ProductID=" + productID.ToString().Replace(" ", string.Empty) +
                                                  "' >Edit Product</a>";
                        }
                    }
                }
                else if (Treatment != null)
                {
                    phProductImage.Controls.Add(new LiteralControl
                                                    ("<img width='400' height='400' src='http://sict-iis.nmmu.ac.za/beauxdebut/Theam/img/portfolio/thumbnails/fullsize/" + productID + ".jpg'/>"));

                    count           = 0;
                    lblHeadera.Text = Treatment.Name.ToString();

                    TableCell cell = new TableCell();
                    cell.Text = Treatment.ProductDescription.ToString();
                    tblProducts.Rows[count].Cells.Add(cell);
                    count++;

                    cell      = new TableCell();
                    cell.Text = "R" + string.Format("{0:#.00}", Treatment.Price);
                    tblProducts.Rows[count].Cells.Add(cell);
                    count++;

                    if (cookie != null)
                    {
                        if (cookie["UT"] == "M" || cookie["UT"] == "R")
                        {
                            cell      = new TableCell();
                            cell.Text = Treatment.Brandname.ToString();
                            tblProducts.Rows[count].Cells.Add(cell);
                            count++;

                            cell      = new TableCell();
                            cell.Text = Treatment.supplierName.ToString();
                            tblProducts.Rows[count].Cells.Add(cell);
                            count++;

                            EditProductBtn.Text = "<a class= 'btn btn-primary' href = '?Action=EditProd&" +
                                                  "ProductID=" + productID.ToString().Replace(" ", string.Empty) +
                                                  "' >Edit Product</a>";
                        }
                    }
                }

                #region Gauge
                if (cookie != null)
                {
                    if (cookie["UT"] == "M" || cookie["UT"] == "R")
                    {
                        #region stock
                        Stock_Management settings = handler.getStockSettings();
                        int lowStockTier          = settings.LowStock;
                        int middelTier            = lowStockTier * 2;
                        int UpperlTier            = middelTier * 2;

                        Dictionary <string, string> chartConfig = new Dictionary <string, string>();
                        chartConfig.Add("caption", "Qty On Hand");
                        chartConfig.Add("lowerLimit", "0");
                        chartConfig.Add("upperLimit", UpperlTier.ToString());
                        chartConfig.Add("showValue", "1");
                        chartConfig.Add("numberSuffix", "Units");
                        chartConfig.Add("theme", "fusion");
                        chartConfig.Add("showToolTip", "0");

                        List <ColorRange> color = new List <ColorRange>();
                        color.Add(new ColorRange(0, lowStockTier, "#F2726F"));
                        color.Add(new ColorRange(lowStockTier, middelTier, "#FFC533"));
                        color.Add(new ColorRange(middelTier, UpperlTier, "#62B58F"));

                        //store dial configuration

                        var dial = new List <KeyValuePair <string,
                                                           string> >();
                        if (Accessory != null)
                        {
                            dial.Add(new KeyValuePair <string, string>("value", Accessory.Qty.ToString()));
                        }
                        else if (Treatment != null)
                        {
                            dial.Add(new KeyValuePair <string, string>("value", Treatment.Qty.ToString()));
                        }

                        // json data to use as chart data source
                        StringBuilder jsonData = new StringBuilder();
                        //build chart config object
                        jsonData.Append("{'chart':{");
                        foreach (var config in chartConfig)
                        {
                            jsonData.AppendFormat("'{0}':'{1}',", config.Key, config.Value);
                        }
                        jsonData.Replace(",", "},", jsonData.Length - 1, 1);

                        StringBuilder range = new StringBuilder();
                        //build colorRange object
                        range.Append("'colorRange':{");
                        range.Append("'color':[");
                        foreach (ColorRange clr in color)
                        {
                            range.AppendFormat("{{'minValue':'{0}','maxValue':'{1}','code':'{2}'}},", clr.Min, clr.Max, clr.ColorCode);
                        }
                        range.Replace(",", "]},", range.Length - 1, 1);
                        //build dials object
                        StringBuilder dials = new StringBuilder();
                        dials.Append("'dials':{");
                        dials.Append("'dial':[");
                        foreach (var dialCnf in dial)
                        {
                            dials.AppendFormat("{{'{0}':'{1}'}},", dialCnf.Key, dialCnf.Value);
                        }
                        dials.Replace(",", "]}", dials.Length - 1, 1);

                        jsonData.Append(range.ToString());
                        jsonData.Append(dials.ToString());
                        jsonData.Append("}");

                        //Create gauge instance
                        // charttype, chartID, width, height, data format, data

                        Chart MyFirstGauge = new Chart("angulargauge", "first_gauge", "400", "250", "json", jsonData.ToString());
                        //render gauge
                        Literal1.Text = MyFirstGauge.Render();
                        #endregion
                    }
                }
                #endregion
            }
            catch (Exception Err)
            {
                function.logAnError(" An error occurred retrieving list of products external products page. Error: " + Err);
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //check query string
            productID = Request.QueryString["ProductID"];
            string action = Request.QueryString["Action"];

            //access Contorl
            cookie = Request.Cookies["CheveuxUserID"];

            if (cookie != null)
            {
                if (action == null && productID == null && (cookie["UT"] == "M" || cookie["UT"] == "R"))
                {
                    Response.Redirect("../Manager/Products.aspx");
                }
            }

            //load all products
            if (action == null)
            {
                if (productID == null)
                {
                    phProducts.Visible    = true;
                    addandedit.Visible    = false;
                    phSpecProduct.Visible = false;
                    lblHeadera.Text       = "Products";

                    loadProductList('X');
                }
                else if (productID != null)             //load specific product
                {
                    lblHeadera.Text        = "Product"; //later make this display the specific products name or image
                    phProducts.Visible     = false;
                    addandedit.Visible     = false;
                    phSpecProduct.Visible  = true;
                    DisplayProduct.Visible = true;
                    LoadProduct(productID);
                }
            }
            else if (cookie != null)
            {
                if (action == "Add" && (cookie["UT"] == "M" || cookie["UT"] == "R"))
                {
                    phProducts.Visible    = false;
                    addandedit.Visible    = true;
                    phSpecProduct.Visible = false;

                    if (!IsPostBack)
                    {
                        productTypes = handler.getProductTypes();
                        foreach (ProductType pType in productTypes)
                        {
                            if (pType.ProductOrService == 'P')
                            {
                                drpProductType.Items.Add(new ListItem(pType.name,
                                                                      pType.typeID.ToString()));
                            }
                        }
                        brandList = handler.getBrandsForProductType(drpProductType.SelectedItem.Text.ToCharArray()[0]);
                        foreach (SP_GetBrandsForProductType brand in brandList)
                        {
                            drpBrandList.DataSource     = brandList;
                            drpBrandList.DataTextField  = "Name";
                            drpBrandList.DataValueField = "BrandID";
                            drpBrandList.DataBind();
                        }
                        loadSupplier();
                    }
                }
                else if (action == "EditProd" && (cookie["UT"] == "M" || cookie["UT"] == "R"))
                {
                    phProducts.Visible    = false;
                    addandedit.Visible    = true;
                    phSpecProduct.Visible = false;

                    if (!IsPostBack)
                    {
                        productTypes = handler.getProductTypes();
                        foreach (ProductType pType in productTypes)
                        {
                            if (pType.ProductOrService == 'P')
                            {
                                drpProductType.Items.Add(new ListItem(pType.name,
                                                                      pType.typeID.ToString()));
                            }
                        }
                        brandList = handler.getBrandsForProductType(drpProductType.SelectedItem.Text.ToCharArray()[0]);
                        foreach (SP_GetBrandsForProductType brand in brandList)
                        {
                            drpBrandList.DataSource     = brandList;
                            drpBrandList.DataTextField  = "Name";
                            drpBrandList.DataValueField = "BrandID";
                            drpBrandList.DataBind();
                        }
                        loadSupplier();
                        lblHeadera.Text    = "Edit Product";
                        btnAddProduct.Text = "Save";
                        Accessory          = handler.selectAccessory(productID);
                        Treatment          = handler.selectTreatment(productID);

                        //track row count & number of products count
                        if (Accessory != null)
                        {
                            txtName.Text = Accessory.Name.ToString();
                            txtProductDescription.Text = Accessory.ProductDescription.ToString();
                            txtPrice.Text = Accessory.Price.ToString();

                            drpProductType.SelectedIndex  = 0;
                            drpProductType.Visible        = false;
                            lbleditProdType.Text          = "Accessory";
                            drpBrandList.SelectedValue    = Accessory.BrandID;
                            drpBrandList.Visible          = false;
                            lblEditProdBrand.Text         = drpBrandList.SelectedItem.Text;
                            drpListSupplier.SelectedValue = Accessory.supplierID;
                            drpListSupplier.Visible       = false;
                            lbleditProdSupp.Text          = drpListSupplier.SelectedItem.Text;
                            txtcolour.Visible             = false;
                            lblEditProdCol.Text           = Accessory.Colour.ToString();
                        }
                        //display accessories
                        else if (Treatment != null)
                        {
                            txtName.Text = Treatment.Name.ToString();
                            txtProductDescription.Text = Treatment.ProductDescription.ToString();
                            txtPrice.Text                = Treatment.Price.ToString();
                            drpProductType.Visible       = false;
                            drpProductType.SelectedIndex = 1;
                            lbleditProdType.Text         = "Treatment";
                            drpProductType_Change(sender, e);
                            drpBrandList.SelectedValue    = Treatment.BrandID;
                            drpBrandList.Visible          = false;
                            lblEditProdBrand.Text         = drpBrandList.SelectedItem.Text;
                            drpListSupplier.SelectedValue = Treatment.supplierID;
                            drpListSupplier.SelectedValue = Treatment.supplierID;
                            drpListSupplier.Visible       = false;
                            lbleditProdSupp.Text          = drpListSupplier.SelectedItem.Text;
                            txtcolour.Visible             = false;
                            lblEditProdCol.Text           = Treatment.TreatmentType;
                        }
                    }
                }
            }
        }
Пример #3
0
        public void autoPurchOrders()
        {
            Stock_Management stockSettings = new Stock_Management();
            List <SP_GetAuto_Purchase_Products> AutoPurchProds = new List <SP_GetAuto_Purchase_Products>();
            List <PRODUCT> allProducts = null;
            string         success     = "Err";

            try
            {
                stockSettings = Handler.getStockSettings();
                if (stockSettings.AutoPurchase == true)
                {
                    if (stockSettings.NxtOrderdDate < DateTime.Now)
                    {
                        if (stockSettings.AutoPurchaseProducts == true)
                        {
                            AutoPurchProds = Handler.getAutoPurchOrdProds();
                        }
                        else
                        {
                            allProducts = Handler.getAllProducts();
                            foreach (PRODUCT prod in allProducts)
                            {
                                SP_GetAuto_Purchase_Products purchProd = new SP_GetAuto_Purchase_Products();
                                purchProd.ProductID   = prod.ProductID;
                                purchProd.Name        = prod.Name;
                                purchProd.ProductType = prod.ProductType;
                                purchProd.Qty         = stockSettings.PurchaseQty;
                                AutoPurchProds.Add(purchProd);
                            }
                        }

                        List <Supplier> supps = Handler.getSuppliers();
                        foreach (Supplier sup in supps)
                        {
                            Order order = new Order();
                            order.supplierID = sup.supplierID;
                            List <Order_DTL>      orderDTLs = new List <Order_DTL>();
                            List <OrderViewModel> outOrders = Handler.getOutStandingOrders();

                            foreach (SP_GetAuto_Purchase_Products prod in AutoPurchProds)
                            {
                                bool add = true;

                                //check if the product is not alread on order
                                foreach (OrderViewModel outOrder in outOrders)
                                {
                                    List <OrderViewModel> outOrderProducts = Handler.getProductOrderDL(outOrder.OrderID.ToString());
                                    foreach (OrderViewModel outOrderDL in outOrderProducts)
                                    {
                                        if (outOrderDL.ProductID == prod.ProductID)
                                        {
                                            add = false;
                                        }
                                    }
                                }

                                if (add == true)
                                {
                                    if (prod.ProductType == "A")
                                    {
                                        SP_GetAllAccessories prodDetails = Handler.selectAccessory(prod.ProductID);
                                        if (prodDetails.supplierID == sup.supplierID &&
                                            prodDetails.Qty < stockSettings.LowStock)
                                        {
                                            Order_DTL newOrderProduct = new Order_DTL();
                                            newOrderProduct.Qty       = prod.Qty;
                                            newOrderProduct.ProductID = prod.ProductID;
                                            orderDTLs.Add(newOrderProduct);
                                        }
                                    }
                                    else if (prod.ProductType == "T")
                                    {
                                        SP_GetAllTreatments prodDetails = Handler.selectTreatment(prod.ProductID);
                                        if (prodDetails.supplierID == sup.supplierID &&
                                            prodDetails.Qty < stockSettings.LowStock)
                                        {
                                            Order_DTL newOrderProduct = new Order_DTL();
                                            newOrderProduct.Qty       = prod.Qty;
                                            newOrderProduct.ProductID = prod.ProductID;
                                            orderDTLs.Add(newOrderProduct);
                                        }
                                    }
                                }
                            }

                            if (orderDTLs.Count > 0)
                            {
                                success = newPurchaseOrder(order, orderDTLs);

                                if (success != "Err")
                                {
                                    stockSettings.NxtOrderdDate = updateAutoOrderDate(stockSettings.AutoPurchaseFrequency);
                                    Handler.updateStockSettings(stockSettings);

                                    //send manager confirmation email
                                    Supplier supp = Handler.getSupplier(order.supplierID);
                                    //send an email notification
                                    var body = new System.Text.StringBuilder();
                                    body.AppendFormat("Hello Mnager,");
                                    body.AppendLine(@"");
                                    body.AppendLine(@"Please review the auto purchase order request sent to " + sup.supplierName + " at the link below");
                                    body.AppendLine(@"");
                                    body.AppendLine(@"http://sict-iis.nmmu.ac.za/beauxdebut/Manager/Products.aspx?Action=ViewOrder&OrderID=" + success);
                                    body.AppendLine(@"");
                                    body.AppendLine(@"The Next Auto Purchase request will occur on " + stockSettings.NxtOrderdDate.ToString("dd MMM yyyy"));
                                    body.AppendLine(@"");
                                    body.AppendLine(@"Regards,");
                                    body.AppendLine(@"");
                                    body.AppendLine(@"The Cheveux Team");
                                    sendEmailAlert(Handler.getManagerContact().Email, "Manager",
                                                   "New Auto Purchase Order Request",
                                                   body.ToString(),
                                                   "Cheveux");
                                }
                                else
                                {
                                    stockSettings.NxtOrderdDate = updateAutoOrderDate(stockSettings.AutoPurchaseFrequency);
                                    Handler.updateStockSettings(stockSettings);

                                    //send manager error email
                                    Supplier supp = Handler.getSupplier(order.supplierID);
                                    //send an email notification
                                    var body = new System.Text.StringBuilder();
                                    body.AppendFormat("Hello Mnager,");
                                    body.AppendLine(@"");
                                    body.AppendLine(@"A failed  auto purchase order request for supplier " + sup.supplierName + " occurred at " + DateTime.Now.ToString("HH:mm dd MMM yyyy"));
                                    body.AppendLine(@"");
                                    body.AppendLine(@"Please contact admin");
                                    body.AppendLine(@"");
                                    body.AppendLine(@"The Next Auto Purchase request will occur on " + stockSettings.NxtOrderdDate.ToString("dd MMM yyyy"));
                                    body.AppendLine(@"");
                                    body.AppendLine(@"Regards,");
                                    body.AppendLine(@"");
                                    body.AppendLine(@"The Cheveux Team");
                                    sendEmailAlert(Handler.getManagerContact().Email, "Manager",
                                                   "New Auto Purchase Order Request",
                                                   body.ToString(),
                                                   "Cheveux");

                                    logAnError("Error making Auto Purchse Order");

                                    success = "";
                                }
                            }
                        }
                    }
                    else
                    {
                        success = "";
                    }
                }
                else
                {
                    success = "";
                }
            }
            catch (Exception err)
            {
                logAnError("Error making Auto Purchse Order: " + err);
            }

            if (success == "Err")
            {
                logAnError("Error making Auto Purchse Order");
                //send an email notification
                var body = new System.Text.StringBuilder();
                body.AppendFormat("Hello Mnager,");
                body.AppendLine(@"");
                body.AppendLine(@"A faild auto purchase order request ocourde at " + DateTime.Now.ToString("HH:mm dd MMM yyyy"));
                body.AppendLine(@"");
                body.AppendLine(@"Please contact admin");
                body.AppendLine(@"");
                body.AppendLine(@"Regards,");
                body.AppendLine(@"");
                body.AppendLine(@"The Cheveux Team");
                sendEmailAlert(Handler.getManagerContact().Email, "Manager",
                               "New Auto Purchase Order Request",
                               body.ToString(),
                               "Cheveux");
            }
        }