Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("=== ArrayList ===");
            AL arrayList = new AL();

            for (int i = 0; i < 255; i++)
            {
                arrayList.Add(i);
            }
            Console.WriteLine("Count: {0}", arrayList.Count);
            Console.WriteLine("Binsearch for int 7: {0}", arrayList.BinarySearch(7));
            arrayList.Remove(7);
            Console.WriteLine("Count: {0}", arrayList.Count);
            Console.WriteLine("Binsearch for int 7: {0}", arrayList.BinarySearch(7));

            Console.WriteLine("=== Stack ===");
            int   n;
            Stack stack = new Stack();

            Console.WriteLine("Enter number of elements: ");
            while (!int.TryParse(Console.ReadLine(), out n))
            {
                ;
            }
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("Enter elememt[{0}]: ", i);
                stack.Push(Console.ReadLine());
            }
            while (stack.Count > 0)
            {
                Console.WriteLine("Pop: {0}", stack.Pop());
            }

            Console.WriteLine("=== Queue ===");
            Random rnd   = new Random();
            Queue  queue = new Queue();

            for (int i = 0; i < 20; i++)
            {
                queue.Enqueue(rnd.NextDouble() * rnd.Next(100));
            }
            for (int i = 0; i < 20; i++)
            {
                Console.WriteLine("queue[{0}] = {1}", i, string.Format("{0:0.00}", queue.Dequeue()));
            }

            Console.WriteLine("=== Hashtable ===");
            Hashtable hashTable = new Hashtable();

            for (int i = 0; i < 20; i++)
            {
                hashTable.Add(i, rnd.Next(40));
            }
            Console.WriteLine("Is contains value 5? {0}", hashTable.ContainsValue(5).ToString());
            Console.WriteLine("Done!");
            Console.ReadKey();
        }
Beispiel #2
0
            public override void AddEdge(object node1, object node2)
            {
                //create a new index if not already there
                if (!AL.ContainsKey(node1))
                {
                    AL.Add(node1, new HashSet <object>());
                }
                if (!AL.ContainsKey(node2))
                {
                    AL.Add(node2, new HashSet <object>());
                }

                AL[node1].Add(node2);
                AL[node2].Add(node1);
            }
Beispiel #3
0
        /// <summary>
        /// Aggiunge i textbox al tab e li riempie con i valori trovati in value
        /// </summary>
        /// <param name="value">stinga codificata</param>
        /// <param name="MFKind">tabella multifieldkind</param>
        /// <param name="Fields">inventorytreemultifieldkind filtrata per idinv</param>
        void FillMultifieldTab(string value, DataTable MFKind, DataRow[] Fields)
        {
            TabControl FT = new TabControl();

            FT.Dock = DockStyle.Fill;

            Dictionary <string, List <DataRow> > HL = new Dictionary <string, List <DataRow> >();
            ArrayList TabNameList = new ArrayList();

            foreach (DataRow Fk0 in MFKind.Select(null, "ordernumber"))
            {
                DataRow F = null;
                foreach (DataRow FF in Fields)
                {
                    if (FF["idmultifieldkind"].ToString() == Fk0["idmultifieldkind"].ToString())
                    {
                        F = FF;
                        break;
                    }
                }
                if (F == null)
                {
                    continue;
                }
                string         tabname = Fk0["tabname"].ToString();
                List <DataRow> AL;
                if (HL.ContainsKey(tabname))
                {
                    AL = HL[tabname] as List <DataRow>;
                }
                else
                {
                    AL          = new List <DataRow>();
                    HL[tabname] = AL;
                    TabNameList.Add(tabname);
                }
                AL.Add(F);
            }



            tabPageInfoAgg.Controls.Clear();
            tabPageInfoAgg.Controls.Add(FT);

            Hashtable H = new Hashtable();

            string[] allmf = value.Split(new char[] { '§' });
            foreach (string coppia in allmf)
            {
                if (coppia == "")
                {
                    continue;
                }
                string[] cc   = coppia.Split(new char[] { '|' });
                string   code = cc[0].ToLower();
                string   val  = cc[1];
                H[code] = val;
            }
            //allfields= array di stringhe del tipo chiave§valore
            allfields = new mfield[Fields.Length];

            //if (value == "") allfields = new mfield[0];
            TabNameList.Sort();
            int maincount = 1;

            foreach (string tabname in TabNameList)
            {
                TabPage TP = new TabPage(tabname == "null" ? "" : tabname);
                TP.AutoScroll = true;

                int x = 0;
                int y = 0;

                int tabcount = 1;
                foreach (DataRow Field in HL[tabname])
                {
                    DataRow[] Fks = MFKind.Select(QHC.CmpEq("idmultifieldkind", Field["idmultifieldkind"]));
                    if (Fks.Length == 0)
                    {
                        continue;
                    }
                    DataRow R = Fks[0];

                    string fieldcode = R["fieldcode"].ToString();
                    object XX        = H[fieldcode.ToLower()];
                    if (XX == null)
                    {
                        XX = "";
                    }
                    mfield MF = new mfield();
                    MF.fieldname = R["fieldname"].ToString();
                    MF.allownull = (R["allownull"].ToString().ToUpper() == "S");
                    MF.systype   = R["systype"].ToString();
                    MF.tag       = R["tag"].ToString();
                    MF.fieldcode = fieldcode;
                    AddMultiFieldToForm(TP, MF, x, y, tabcount); //inizio


                    if (R["len"] != DBNull.Value)
                    {
                        MF.T.MaxLength = CfgFn.GetNoNullInt32(R["len"]);
                    }
                    MF.T.Text = XX.ToString();
                    if (MF.systype.ToLower() == "string")
                    {
                        MF.T.TextAlign = HorizontalAlignment.Left;
                    }
                    else
                    {
                        MF.T.TextAlign = HorizontalAlignment.Right;
                    }

                    allfields[maincount - 1] = MF;

                    tabcount++;
                    maincount++;
                    y += 52;
                    if (tabcount == 10)
                    {
                        x += 350;
                        y  = 0;
                    }
                }

                FT.TabPages.Add(TP);
                FT.Refresh();
            }

            ////Legenda campi obbligatori
            //if (Fields.Length > 0) {
            //    Label L = new Label();
            //    tabPageInfoAgg.Controls.Add(L);
            //    L.Text = "I campi contrassegnati da (*) sono obbligatori";
            //    L.AutoSize = true;
            //    L.Location = new Point(10 + x, 15 + y);
            //}
        }
Beispiel #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string    action = Request.QueryString["action"];
        ArrayList AL;
        //Hashtable HT;
        XmlTextWriter myXmlWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
        string        htmltext    = "";

        Page.Response.ContentType = "text/xml";
        Page.Response.Charset     = "utf-8";

        /* Pagina che gestisce le chiamate AJAX provenienti dal client
         * invocate da vetrina_default.aspx.
         * utilizza i seguenti parametri URL:
         * - idlist: id dell'articolo in listino
         * - idstore: id magazzino
         * - idstock: id stock
         * - units: numero di unità da prenotare.
         * - action: azione da effetturare. Ha tre valori:
         *   * add: aggiunge al carrello;
         *   * show: mostra il contenuto attuale del carrello;
         *   * empty: svuota il carrello.
         */
        switch (action)
        {
        case "add":
        {
            /* Aggiunge articoli al carrello
             * necessita dei parametri idlist (id articolo), units (quantità),
             * idstore (id magazzino). Restituisce un XML che contiene
             * il messaggio di notifica di avvenuto inserimento dell'articolo nel carrello.
             */

            int     idlist   = CfgFn.GetNoNullInt32(Request.QueryString["idlist"]);
            int     quantity = CfgFn.GetNoNullInt32(Request.QueryString["units"]);
            int     idstore  = CfgFn.GetNoNullInt32(Request.QueryString["idstore"]);
            int     idstock  = CfgFn.GetNoNullInt32(Request.QueryString["idstock"]);
            decimal price    = CfgFn.GetNoNullDecimal(HelpForm.GetObjectFromString(typeof(decimal), Request.QueryString["price"], "x.y.n"));
            if (idlist == null)
            {
                return;
            }
            if (quantity == null)
            {
                return;
            }

            if (Session["Cart"] == null)
            {
                AL = new ArrayList();
            }
            else
            {
                AL = (ArrayList)Session["Cart"];
            }

            // Find if an item with same idlist and idstore exists in arraylist
            cartitem CI;
            bool     found = false;
            int      index;
            int      previousquantity = 0;
            for (index = 0; index < AL.Count; index++)
            {
                CI = (cartitem)AL[index];
                if (CI.idlist == idlist && CI.idstore == idstore && CI.price == price && CI.idstock == idstock)
                {
                    found            = true;
                    previousquantity = CI.quantity;
                    break;
                }
            }

            if (found)
            {
                CI          = new cartitem();
                CI.idlist   = idlist;
                CI.idstore  = idstore;
                CI.quantity = quantity + previousquantity;
                CI.price    = price;
                CI.idstock  = idstock;
                AL[index]   = CI;
            }
            else
            {
                CI          = new cartitem();
                CI.idlist   = idlist;
                CI.idstore  = idstore;
                CI.quantity = quantity;
                CI.price    = price;
                CI.idstock  = idstock;
                AL.Add(CI);
            }

            Session["Cart"] = AL;
            myXmlWriter.WriteStartDocument();
            myXmlWriter.WriteStartElement("datagrid");
            myXmlWriter.WriteStartElement("htmlcode");
            htmltext += "<fieldset>";
            htmltext += "<legend style=\"text-align :center\">Operazione Effettuata</legend>";

            htmltext += "<div class=\"row\">";
            htmltext += "<div class=\"col-md-5\"></div>";
            htmltext += "<div class=\"col-md-4\">";
            htmltext += "<label>Gli articoli da Lei scelti sono stati aggiunti al carrello</label>";
            htmltext += "</div>";
            htmltext += "<div class=\"col-md-3\"></div>";
            htmltext += "</div>";        //chiude la rows

            htmltext += "</fieldset>";


            myXmlWriter.WriteCData(htmltext);
            myXmlWriter.WriteEndElement();
            myXmlWriter.WriteStartElement("meta");
            myXmlWriter.WriteStartElement("totalpages");
            myXmlWriter.WriteValue("0");
            myXmlWriter.WriteEndElement();
            myXmlWriter.WriteStartElement("title");

            myXmlWriter.WriteValue("");
            myXmlWriter.WriteEndElement();
            myXmlWriter.WriteEndElement();
            myXmlWriter.WriteEndElement();

            myXmlWriter.Flush();
            myXmlWriter.Close();


            break;
        }

        case "show":
        {
            /* Mostra il carrello corrente (se contiene articoli).
             * Restituisce un XML contenente il contenuto
             * del carrello corrente se esso contiene elementi,
             * altrimenti un XML contenente un messaggio di
             * "Carrello Vuoto"
             */
            if (Session["Cart"] == null)
            {
                // Carrello vuoto

                myXmlWriter.WriteStartDocument();
                myXmlWriter.WriteStartElement("datagrid");
                myXmlWriter.WriteStartElement("htmlcode");
                htmltext += "<div class=\"row\">";
                htmltext += "<div class=\"col-md-5\"></div>";
                htmltext += "<div class=\"col-md-4\">";
                htmltext += "<label>Il suo carrello è vuoto.</label>";
                htmltext += "</div>";
                htmltext += "<div class=\"col-md-3\"></div>";
                htmltext += "</div>";        //chiude la rows

                myXmlWriter.WriteCData(htmltext);
                myXmlWriter.WriteEndElement();
                myXmlWriter.WriteStartElement("meta");
                myXmlWriter.WriteStartElement("totalpages");
                myXmlWriter.WriteValue("0");
                myXmlWriter.WriteEndElement();
                myXmlWriter.WriteStartElement("title");

                myXmlWriter.WriteValue("");
                myXmlWriter.WriteEndElement();
                myXmlWriter.WriteEndElement();
                myXmlWriter.WriteEndElement();

                myXmlWriter.Flush();
                myXmlWriter.Close();
            }
            else
            {
                // Visualizza il riepilogo
                // In base agli id nella HT si prelevano dal DB i codici e le descrizioni degli articoli.
                // E si visualizza il riepilogo
                AL = (ArrayList)Session["Cart"];
                if (AL.Count == 0)
                {
                    return;
                }

                DataAccess  Conn = GetVars.GetUserConn(Page);
                QueryHelper QHS  = Conn.GetQueryHelper();

                cartitem CI;
                //htmltext += "<fieldset style=\"background-color: #eeeeee;\">";
                htmltext += "<div class=\"row\">";
                htmltext += "<div class=\"col-md-4\"></div>";
                htmltext += "<div class=\"col-md-4\">";
                htmltext += "<label>Articoli attualmente nel carrello</label>";
                htmltext += "</div>";
                htmltext += "<div class=\"col-md-4\"></div>";
                htmltext += "</div>";        //chiude la rows

                htmltext += "<div class=\"row\">";
                htmltext += "<div class=\"col-md-12\">";
                htmltext += "<table class=\"table table-striped\";>";
                //htmltext += "<thead><tr style=\"background-color:#d9edf7;color:#000000;\">";
                htmltext += "<thead><tr>";

                htmltext += "<thead><tr><th>Articolo</th><th>Class.Merceologica</th>";
                htmltext += "<th>Quantità</th></tr></thead><tbody>";

                int    counter;
                string bgcolor = "";
                for (counter = 0; counter < AL.Count; counter++)
                {
                    CI = (cartitem)AL[counter];
                    //if (counter % 2 == 0)
                    //    bgcolor = "#d9edf7;";//bgcolor = "#eaeaea;";
                    //else
                    //    bgcolor = "#c4e3f3;";//bgcolor = "#bababa;";
                    bgcolor = "#FFFFFF";
                    string storedescription;
                    string itemdescription;
                    string filter;
                    string listclass;
                    string idlistclass;

                    filter = QHS.CmpEq("idlist", CI.idlist);
                    DataTable T;
                    T = Conn.RUN_SELECT("list", "description,idlistclass", null, filter, null, false);
                    itemdescription = T.Rows[0]["description"].ToString();

                    idlistclass = T.Rows[0]["idlistclass"].ToString();
                    filter      = QHS.CmpEq("idlistclass", idlistclass);
                    T           = Conn.RUN_SELECT("listclass", "title", null, filter, null, false);
                    listclass   = T.Rows[0]["title"].ToString();

                    /*
                     * filter = QHS.CmpEq("idstore", CI.idstore);
                     * T = Conn.RUN_SELECT("store", "description", null, filter, null, false);
                     * storedescription=T.Rows[0]["description"].ToString();
                     */

                    htmltext += "<tr style=\"background-color:" + bgcolor + "\">";
                    htmltext += "<td><style=\"text-align: justify;\">" + itemdescription + "</td>";
                    htmltext += "<td><style=\"text-align: left;\">" + listclass + "</td>";
                    htmltext += "<td><style=\"text-align: center;\">" + CI.quantity.ToString() + "</td>";
                    htmltext += "</tr>";
                }
                htmltext += "</tbody></table>";

                htmltext += "</div>";        // chiude class col-md-12
                htmltext += "</div>";        //chiude la rows



                myXmlWriter.WriteStartDocument();
                myXmlWriter.WriteStartElement("datagrid");
                myXmlWriter.WriteStartElement("htmlcode");
                myXmlWriter.WriteCData(htmltext);
                myXmlWriter.WriteEndElement();
                myXmlWriter.WriteStartElement("meta");
                myXmlWriter.WriteStartElement("totalpages");
                myXmlWriter.WriteValue("0");
                myXmlWriter.WriteEndElement();
                myXmlWriter.WriteStartElement("title");

                myXmlWriter.WriteValue("");
                myXmlWriter.WriteEndElement();
                myXmlWriter.WriteEndElement();
                myXmlWriter.WriteEndElement();

                myXmlWriter.Flush();
                myXmlWriter.Close();
            }
        }
        break;

        case "empty":
        {
            /* Svuota il carrello corrente.
             * Restituisce un XML contenente il messaggio di notifica
             * dell'avvenuto svuotamento, oppure un messaggio di notifica
             * che avvisa l'utente che il carrello è già vuoto.
             */
            // azzera il carrello
            if (Session["Cart"] == null)
            {
                htmltext += "<p>Il suo carrello è già vuoto.</p>";
            }
            else
            {
                Session["Cart"] = null;

                htmltext += "<p>Il suo carrello è stato svuotato come richiesto.</p>";
            }

            myXmlWriter.WriteStartDocument();
            myXmlWriter.WriteStartElement("datagrid");
            myXmlWriter.WriteStartElement("htmlcode");
            myXmlWriter.WriteCData(htmltext);
            myXmlWriter.WriteEndElement();
            myXmlWriter.WriteStartElement("meta");
            myXmlWriter.WriteStartElement("totalpages");
            myXmlWriter.WriteValue("0");
            myXmlWriter.WriteEndElement();
            myXmlWriter.WriteStartElement("title");

            myXmlWriter.WriteValue("");
            myXmlWriter.WriteEndElement();
            myXmlWriter.WriteEndElement();
            myXmlWriter.WriteEndElement();

            myXmlWriter.Flush();
            myXmlWriter.Close();
        }
        break;
        }

        Page.Response.End();
    }