Ejemplo n.º 1
0
        public static string show_user_basket(System.Data.SqlClient.SqlConnection conn, System.Web.HttpRequest req, AccessControl.AccessManager access_manager, System.Data.SqlClient.SqlTransaction tr)
        {
            System.Guid guididix = new System.Guid(req["guididx"]);

            Shop.shop_sold_item sold_items = new Shop.shop_sold_item();
            Shop.shop_sold_itemTableAdapters.shop_sold_itemTableAdapter ta = new Shop.shop_sold_itemTableAdapters.shop_sold_itemTableAdapter();
            ta.Connection = (System.Data.SqlClient.SqlConnection)access_manager.Connection;
            ta.FillByOwner(sold_items._shop_sold_item, guididix);

            Shop.shop_sold_item sold_items_sorted = sort_sold_items(sold_items);

            string left = "<form name='to_delete_items'><table border=0 cellpadding=0 cellspacing=0>";

            left += "<tr><td colspan='5'>Bought items</td></tr>";


            foreach (Shop.shop_sold_item.shop_sold_itemRow r in sold_items_sorted._shop_sold_item)
            {
                left += "<tr>";
                left += String.Format("<td><input type='checkbox' class='itt' style='border: none;' value='{0}' name='to_del_idx_{0}'/></td>", r.idx);
                left += String.Format("<td><img width='16' height='16' src='i/{0}'/></td>", (r.is_expired() || r.is_depleted())?"expired.gif":"blank.gif");
                string img = String.Format("<img width='16' height='16' src='i/{0}'/>", ((r.type == 1) ? "package.gif":(r.type == 2?"test.gif":"pdf.gif")));

                if (r.type != 1 && r.parent != -1)
                {
                    left += "<td width='10'>&nbsp;</td><td>" + img + r.name + "</td>";
                }
                else
                {
                    left += "<td colspan='2'>" + img + r.name + "</td>";
                }
                left += "</tr>";
            }
            if (sold_items_sorted._shop_sold_item.Rows.Count != 0)
            {
                left += "<tr><td colspan='5'><input value='Delete' type='button' style='itt' onclick='javascript:delete_bought_items();'></td></tr>";
            }

            left += "<tr><td colspan='5'><input type='hidden' name='guididx' value='" + guididix.ToString() + "'/></td></tr>";
            left += "</table></form>";

            //////////////////////////////////////////////////////////////////////////////////////////////

            string right = "<form name='to_purchase_items'><table border=0 cellpadding=0 cellspacing=0>";

            right += "<tr><td colspan='2'>Shop items</tr>";
            Shop.binded_tests bt = new Shop.binded_tests();
            Shop.binded_testsTableAdapters.binded_testsTableAdapter bta = new Shop.binded_testsTableAdapters.binded_testsTableAdapter();
            bta.Connection = conn;
            bta.Fill(bt._binded_tests);

            Shop.shop_item sh = new Shop.shop_item();
            Shop.shop_itemTableAdapters.shop_itemTableAdapter sha = new Shop.shop_itemTableAdapters.shop_itemTableAdapter();
            sha.Connection = conn;
            sha.Fill(sh._shop_item);

            foreach (shop_item.shop_itemRow r in sh._shop_item.Rows)
            {
                right += build_pdescr(r, bt);
            }


            right += "<tr><td colspan='2'><input value='Add to user' type='button' style='itt' onclick='javascript:add_selected_items();'></td></tr>";
            if (sh._shop_item.Rows.Count != 0)
            {
                right += "<tr><td colspan='2'><input type='hidden' name='guididx' value='" + guididix.ToString() + "'/></td></tr>";
            }
            right += "</table></form>";
            //////////////////////////////////////////////////////////////////////////////////////////////
            return("<table width='100%' border=0><tr><td valign='top' width='50%'>" + left + "</td><td width='50%' valign='top'>" + right + "</td></tr></table>");
        }
Ejemplo n.º 2
0
        public static void check_sold_item(AccessControl.AccessManager mgr, int idx, string type, int package_idx)
        {
            shop_itemTableAdapters.shop_itemTableAdapter ta = new shop_itemTableAdapters.shop_itemTableAdapter();
            ta.SqlConnection = (System.Data.SqlClient.SqlConnection)mgr.Connection;

            Shop.shop_sold_itemTableAdapters.shop_sold_itemTableAdapter si_ta = new Shop.shop_sold_itemTableAdapters.shop_sold_itemTableAdapter();
            si_ta.SqlConnection = (System.Data.SqlClient.SqlConnection)mgr.Connection;


            shop_item.shop_itemDataTable p = ta.GetRowByIdx(package_idx);
            if (0 == p.Rows.Count)
            {
                throw new System.Exception("Has no such package");
            }

            Shop.shop_sold_item.shop_sold_itemDataTable psi = si_ta.GetByItt(package_idx, type2code("group"), mgr.UserGuid);
            if (psi.Rows.Count == 0 && "group" == type)
            {
                throw new System.Exception("Package was not bought");
            }

            if (type != "group")
            {
                Shop.shop_sold_item.shop_sold_itemDataTable csi = si_ta.GetByItt(idx, type2code(type), mgr.UserGuid);
                // let's merge

                foreach (Shop.shop_sold_item.shop_sold_itemRow r in csi)
                {
                    if (r.sold_at == r.expires_at)
                    {
                        csi[0].sold_at = csi[0].expires_at;
                    }
                }

                if (p[0].limit != 0)
                {
                    if (psi.Rows.Count == 0)
                    {
                        throw new System.Exception("Unexpected condition");
                    }
                    bool has_nb = false;
                    if (csi.Rows.Count != 0)
                    {
                        foreach (Shop.shop_sold_item.shop_sold_itemRow i in csi)
                        {
                            if (i.parent == psi[0].idx)
                            {
                                has_nb = true;
                            }
                        }
                    }

                    if (!has_nb)
                    {
                        // item is selected from the limited package
                        if (psi[0].use_count == psi[0].sold_count)
                        {
                            throw new System.Exception("Limit reached");
                        }
                        purchase(mgr, idx, type, package_idx, 0);
                        psi[0].use_count++;
                        si_ta.Update(psi);
                        return;
                    }
                }
                if (csi.Rows.Count == 0)
                {
                    throw new System.Exception("Item was not bought");
                }

                if (csi[0].expires_at < DateTime.Now && csi[0].expires_at != csi[0].sold_at)
                {
                    mgr.revoke_access_to_function(String.Format("item_{0}_{1}", type, idx));
                    throw new System.Exception("Access time was expired");
                }
            }
        }