public Productbll GetProductIDFromName(string ProductName)
        {
            Productbll p = new Productbll();

            SqlConnection conn = new SqlConnection(myconstring);

            DataTable dt = new DataTable();

            try
            {
                string sql = "Select id from Products where name = '" + ProductName + "'";

                SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);

                conn.Open();


                adapter.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    p.id = int.Parse(dt.Rows[0]["id"].ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
            }

            return(p);
        }
        public bool Delete(Productbll p)
        {
            bool          isSuccess = false;
            SqlConnection con       = new SqlConnection(myconstring);

            try
            {
                string     query = "Delete From Products where id=@id";
                SqlCommand cmd   = new SqlCommand(query, con);

                cmd.Parameters.AddWithValue("@id", p.id);
                con.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(isSuccess);
        }
示例#3
0
        protected void Upload_Click(object sender, EventArgs e)
        {
            try
            {
                Productbll  pBll = new Productbll();
                ProductInfo oPro = new ProductInfo();
                oPro.ProductName     = txtPName.Text;
                oPro.Specification   = txtSpec.Text;
                oPro.DealID          = Convert.ToInt32(dDeals.SelectedValue);
                oPro.SupplierID      = Convert.ToInt32(dSupplier.SelectedValue);
                oPro.CategoryID      = Convert.ToInt32(dCategory.SelectedValue);
                oPro.ExpiryDate      = txtExpDate.Text;
                oPro.RegularPrice    = int.Parse(txtRegPrice.Text);
                oPro.DiscountedPrice = int.Parse(txtDiscPrice.Text);

                //xml load
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Server.MapPath("ProductUpdate.xml"));
                XmlNode rootNode        = xmlDoc.SelectSingleNode("product");
                XmlNode valueNode       = rootNode.FirstChild;
                int     productUploadNo = int.Parse(valueNode.InnerText);

                if (fileUpload.HasFile)
                {
                    string fileExtension = Path.GetExtension(fileUpload.PostedFile.FileName);
                    uploadedImage.ImageUrl = "~/UploadedImages/" + "product" + productUploadNo + fileExtension;
                    var ImagePath = Server.MapPath("~/UploadedImages/") + "product" + productUploadNo + fileExtension;
                    fileUpload.PostedFile.SaveAs(ImagePath);
                    productUploadNo++;
                    valueNode.InnerText = productUploadNo.ToString();
                    //Response.Redirect(Request.Url.AbsoluteUri);
                }
                pBll.SaveProduct(oPro);

                //save xml
                xmlDoc.Save(Server.MapPath("ProductUpdate.xml"));

                txtPName.Text = "";
                txtSpec.Text  = "";
                //txtImagePath.Text = "";



                Response.Write("Product Saved Succesfully");
                DataSet ds = new DataSet();
            }
            catch (Exception ex)
            {
                Response.Write(ex);
            }
        }
        public bool update(Productbll p)
        {
            bool          isSuccess = false;
            SqlConnection con       = new SqlConnection(myconstring);

            try
            {
                String     sql = "Update Products set name = @name,category = @category, description = @description,rate = @rate,quantity = @quantity,added_by = @added_by where id=@id";
                SqlCommand cmd = new SqlCommand(sql, con);


                cmd.Parameters.AddWithValue("@name", p.name);
                cmd.Parameters.AddWithValue("@category", p.category);
                cmd.Parameters.AddWithValue("@description", p.description);
                cmd.Parameters.AddWithValue("@rate", p.rate);
                cmd.Parameters.AddWithValue("@quantity", p.qty);
                cmd.Parameters.AddWithValue("@added_date", p.added_date);
                cmd.Parameters.AddWithValue("@added_by", p.added_by);
                cmd.Parameters.AddWithValue("@id", p.id);



                con.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }

                else
                {
                    isSuccess = false;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally
            {
                con.Close();
            }

            return(isSuccess);
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet    ds;
            Productbll pro = new Productbll();

            try
            {
                //load xml
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Server.MapPath("ProductUpdate.xml"));
                XmlNode rootNode  = xmlDoc.SelectSingleNode("product");
                XmlNode valueNode = rootNode.FirstChild;
                int     productNo = int.Parse(valueNode.InnerText);


                for (int i = 1; i < productNo; i++)
                {
                    //load data from database

                    ds = pro.GetProduct(i);
                    DataTable dt             = ds.Tables[0];
                    DataRow   dr             = dt.Rows[0];
                    string    productName    = Convert.ToString(dr["ProductName"]);
                    string    specs          = Convert.ToString(dr["Specification"]);
                    string    expDate        = Convert.ToString(dr["ExpiryDate"]);
                    int       price          = Convert.ToInt16(dr["DiscountedPrice"]);
                    string    specifications = specs.Replace(";", "</br>");

                    itemcollection.InnerHtml += "<div class='col-xs-3 iteminfo'>" +
                                                "<a href='/Details.aspx?productno=" + i + "'>" +
                                                "<img class='img-circle' src='UploadedImages/product" + i + ".jpg' width='100' height='100' /></a><h2>" + productName + "</h2>" +
                                                "<p>" + specifications + "</br>" +
                                                "Price: Rs." + price + "</br>" +
                                                "Expires On: " + expDate + "</p>" +

                                                "<p><a class='btn btn-default' href='/Details.aspx?productno=" + i + "' role='button'>View details &raquo;</a></p>" +
                                                "</div>";
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex);
            }
        }
示例#6
0
        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            string keyword = textBox6.Text;


            if (keyword == "")
            {
                txt_productnname.Text = "";
                txt_inventory.Text    = "";
                txt_rate.Text         = "";
                txt_qty.Text          = "";
                return;
            }
            Productbll d = Pl.searchproductforTransaction(keyword);

            txt_productnname.Text = d.name;
            txt_inventory.Text    = d.qty.ToString();;
            txt_rate.Text         = d.rate.ToString();;
        }
示例#7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //string[] filePaths = Directory.GetFiles(Server.MapPath("~/Images/"));
                //List<ListItem> files = new List<ListItem>();
                //foreach (string filePath in filePaths)
                //{
                //    string fileName = Path.GetFileName(filePath);
                //    files.Add(new ListItem(fileName, "~/Images/" + fileName));
                //}

                DataSet    ds   = new DataSet();
                Productbll vBll = new Productbll();
                Dealsbll   oDel = new Dealsbll();
                ds = oDel.GetDeals();
                DataTable dt = ds.Tables[0];
                dDeals.DataSource     = dt;
                dDeals.DataTextField  = "Description";
                dDeals.DataValueField = "DealID";
                dDeals.DataBind();

                DataSet     das;
                Supplierbll oSup = new Supplierbll();
                das = oSup.GetSupplier();
                DataTable dat = das.Tables[0];
                dSupplier.DataSource     = dat;
                dSupplier.DataTextField  = "BusinessName";
                dSupplier.DataValueField = "SupplierID";
                dSupplier.DataBind();

                DataSet     dbs;
                Categorybll oCat = new Categorybll();
                dbs = oCat.GetCategory();
                DataTable dbt = dbs.Tables[0];
                dCategory.DataSource     = dbt;
                dCategory.DataTextField  = "Description";
                dCategory.DataValueField = "CategoryID";
                dCategory.DataBind();
            }
        }
        public Productbll searchproductforTransaction(string keyword)
        {
            Productbll dc = new Productbll();

            SqlConnection conn = new SqlConnection(myconstring);



            DataTable dt = new DataTable();

            try
            {
                string sql = "Select name,rate,quantity from Products where id like '%" + keyword + "%' or name Like '%" + keyword + "%' ";

                SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);

                conn.Open();

                adapter.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    dc.name = dt.Rows[0]["name"].ToString();
                    dc.rate = decimal.Parse(dt.Rows[0]["rate"].ToString());
                    dc.qty  = decimal.Parse(dt.Rows[0]["quantity"].ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(dc);
        }
示例#9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Productbll product = new Productbll();
            DataSet    ds;

            //load xml
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(Server.MapPath("ProductUpdate.xml"));
            XmlNode rootNode  = xmlDoc.SelectSingleNode("product");
            XmlNode valueNode = rootNode.FirstChild;
            int     products  = int.Parse(valueNode.InnerText);



            for (int i = 1; i < 4; i++)
            {
                //load data from database

                ds = product.GetProduct(i);
                DataTable dt = ds.Tables[0];
                DataRow   dr = dt.Rows[0];

                string nameProduct   = Convert.ToString(dr["ProductName"]);
                string specs         = Convert.ToString(dr["Specification"]);
                string expDate       = Convert.ToString(dr["ExpiryDate"]);
                int    price         = Convert.ToInt16(dr["DiscountedPrice"]);
                string specification = specs.Replace(";", "</br>");

                itemsDisplay.InnerHtml += "<div class='col-lg-4'>" +
                                          "<img class='img-circle' src='UploadedImages/product" + i + ".jpg' alt='Generic placeholder image' width='140' height='140' />" +
                                          "<h2>" + nameProduct + "</h2>" +
                                          "<p>" + specification +
                                          "Price: Rs." + price + "</p>" +
                                          "<p><a class='btn btn-default' href='/Details.aspx?productno=" + i + "' role='button'>View details &raquo;</a></p>" +
                                          "</div>";
            }
        }
示例#10
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                TransactionBll transaction = new TransactionBll();

                transaction.type = lblPurchaseandsales.Text;

                string deacustman = txt_name.Text;

                CustomerBll dc = dl.GetCustomerIDFromname(deacustman);

                transaction.dea_cust_id      = dc.id;
                transaction.grandTotal       = decimal.Parse(txt_grand.Text);
                transaction.transaction_date = DateTime.Now;
                transaction.tax      = decimal.Parse(txt_vat.Text);
                transaction.discount = decimal.Parse(txt_discount.Text);

                string loggedUser = Login.loggein;
                usebll usr        = Dal.GetIDFromUsername(loggedUser);
                transaction.added_by = usr.id;

                transaction.transactionDetails = transactionDT;

                bool success = false;

                using (TransactionScope scope = new TransactionScope())
                {
                    int transactionID = -1;

                    bool w = tdal.Insert_transaction(transaction, out transactionID);


                    for (int i = 0; i < transactionDT.Rows.Count; i++)
                    {
                        TransactionDetailsBll transactiondetails = new TransactionDetailsBll();

                        string     Productname = txt_productnname.Text;
                        Productbll p           = Pl.GetProductIDFromName(Productname);


                        string transactionType = lblPurchaseandsales.Text;


                        transactiondetails.ProductID   = p.id;
                        transactiondetails.rate        = decimal.Parse(transactionDT.Rows[i][1].ToString());
                        transactiondetails.qty         = decimal.Parse(transactionDT.Rows[i][2].ToString());
                        transactiondetails.total       = decimal.Parse(transactionDT.Rows[i][3].ToString());
                        transactiondetails.dea_cust_id = dc.id;
                        transactiondetails.added_date  = DateTime.Now;
                        transactiondetails.added_by    = usr.id;
                        bool x = false;
                        if (transactionType == "Purchase")
                        {
                            x = Pl.IncreaseProduct(transactiondetails.ProductID, transactiondetails.qty);
                        }
                        else if (transactionType == "Sales")
                        {
                            x = Pl.DecreaseProduct(transactiondetails.ProductID, transactiondetails.qty);
                        }


                        bool y = tdetailDAL.insertTransactionDetails(transactiondetails);

                        success = w & y;

                        if (success == true)
                        {
                            scope.Complete();


                            MessageBox.Show("Transaction Completed Successfully");
                        }
                        else
                        {
                            MessageBox.Show("Transaction Failed");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Productbll product= new Productbll();
            DataSet ds;
            int productNo;

            //extract querystring
            if(!string.IsNullOrEmpty(Request.QueryString["productno"]))
            {
                productNo = int.Parse(Request.QueryString["productno"]);
            }
            else
            {
                productNo = 0;
            }

            //load data
            ds = product.GetProduct(productNo);
            DataTable dt = ds.Tables[0];
            DataRow dr = dt.Rows[0];
            string nameProduct = Convert.ToString(dr["ProductName"]);
            string specs = Convert.ToString(dr["Specification"]);
            string expDate = Convert.ToString(dr["ExpiryDate"]);
            DateTime addedDate = (Convert.ToDateTime(dr["CreateDate"])).Date;
            int dPrice = Convert.ToInt16(dr["DiscountedPrice"]);
            int rPrice = Convert.ToInt16(dr["RegularPrice"]);
            string spec1 = specs.Replace(":", ":</p></div><div class='col-xs-4'><p>");
            string specification = spec1.Replace(";", "</p></div><div class='col-xs-6'><p>");
            int cat = Convert.ToInt16(dr["CategoryID"]);

            image.Src = "UploadedImages/product" + productNo +".jpg";
            productName.InnerText = nameProduct;
            discPrice.InnerText = dPrice.ToString();
            orgPrice.InnerText = rPrice.ToString();
            float discount = ((((float)rPrice - (float)dPrice) / (float)rPrice) * 100);
            discPerc.InnerText = discount.ToString() + "%";
            specifications.InnerHtml="<div class='col-xs-6'><p>"+ specification +"</div>";
            addDate.InnerText = addedDate.ToString("d");
            expireDate.InnerText = expDate;

            //load xml
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath("ProductUpdate.xml"));
            XmlNode rootNode = xmlDoc.SelectSingleNode("product");
            XmlNode valueNode = rootNode.FirstChild;
            int products = int.Parse(valueNode.InnerText);
            

            //more products part
            for (int i = 1; i < products; i++)
            {


                //load data from database

                ds = product.GetProduct(i);
                dt = ds.Tables[0];
                dr = dt.Rows[0];
                int category = Convert.ToInt16(dr["CategoryID"]);
                if (category == cat)
                {


                    nameProduct = Convert.ToString(dr["ProductName"]);
                    specs = Convert.ToString(dr["Specification"]);
                    expDate = Convert.ToString(dr["ExpiryDate"]);
                    int price = Convert.ToInt16(dr["DiscountedPrice"]);
                    specification = specs.Replace(";", "</br>");

                    additionalItems.InnerHtml += "<div class='col-xs-3 iteminfo'>" +
                        "<a href='/Details.aspx?productno=" + i + "'>" +
                            "<img class='img-circle' src='UploadedImages/product" + i + ".jpg' width='100' height='100' /></a><h2>" + nameProduct + "</h2>" +
                            "<p>" + specification + "</br>" +
                            "Price: Rs." + price + "</br>" +
                            "Expires On: " + expDate + "</p>" +

                            "<p><a class='btn btn-default' href='/Details.aspx?productno=" + i + "' role='button'>View details &raquo;</a></p>" +
                    "</div>";
                }
            }
        }