示例#1
0
        private void DoSelectTest(int idx)
        {
            ArrayList arr = ShopManager.get_item_cont_by_idx(connection_, null, idx);
            string    ret = "";

            resources.Visible = true;
            ta.SqlConnection  = connection_;
            ta.FillByIdx(sh_it, idx);


            shop_sold_itemTableAdapter si_ta = new shop_sold_itemTableAdapter();

            si_ta.SqlConnection = connection_;
            shop_sold_item.shop_sold_itemDataTable si = si_ta.GetByItt(idx, ShopManager.type2code("group"), access_manager_.UserGuid);

            if (sh_it.Rows.Count != 0 && si.Rows.Count != 0)
            {
                if (sh_it[0].limit != 0)
                {
                    description  = "<span style='color:red;'>Warning </span> this package is limited by administartor so you can use just: " + sh_it[0].limit.ToString() + " items from the list.";
                    description += "<br><span style='color:red'>Left</span> " + (si[0].sold_count - si[0].use_count).ToString() + " items to select.";
                    if (si[0].sold_count == si[0].use_count)
                    {
                        pPayAgain.Visible = true;
                    }
                }
            }


            foreach (Hashtable i in arr)
            {
                if ("" != i["bound"].ToString())
                {
                    if (2 == (int)i["type"])
                    {
                        ret += String.Format("<a href='StartTest.aspx?idx={0}&type=test&pkg_idx={2}'>{1}</a><br>", i["idx"], i["name"], idx);
                    }
                    if (3 == (int)i["type"])
                    {
                        ret += String.Format("<a href='StartTest.aspx?idx={0}&type=download&pkg_idx={2}'>{1}</a><br>", i["idx"], i["name"], idx);
                    }
                }
            }
            resourcelist = ret;
        }
示例#2
0
        protected static void purchase_(AccessControl.AccessManager mgr, IDbConnection conn, Guid guididx, int idx, string type, int package_idx, decimal payed)
        {
            string s = String.Format("item_{0}_{1}", type, idx);


            shop_itemTableAdapters.shop_itemTableAdapter sh_it_ta = new shop_itemTableAdapters.shop_itemTableAdapter();
            sh_it_ta.SqlConnection = (System.Data.SqlClient.SqlConnection)(conn);

            shop_sold_itemTableAdapters.shop_sold_itemTableAdapter sh_sit_ta = new shop_sold_itemTableAdapters.shop_sold_itemTableAdapter();
            sh_sit_ta.SqlConnection = (System.Data.SqlClient.SqlConnection)(conn);

            shop_item.shop_itemDataTable p = sh_it_ta.GetRowByIdx(package_idx);
            if (p.Rows.Count == 0)
            {
                throw new System.Exception("No such item to purchase");
            }

            shop_sold_item.shop_sold_itemDataTable sh_sit = sh_sit_ta.GetData();
            shop_sold_item.shop_sold_itemDataTable p_sit  = sh_sit_ta.GetByItt(package_idx, 1, guididx);
            int prnt_idx = -1;

            // if item bought from a package we must select a package idx to bind to
            if (p_sit.Rows.Count != 0)
            {
                prnt_idx = p_sit[0].idx;
            }

            string name = "";

            if ("group" == type)
            {
                name = "Access to package: " + get_package_name_id_((System.Data.SqlClient.SqlConnection)conn, null, idx);

                int pidx_ = -1;

                if (p[0]["parent_idx"].GetType() != typeof(System.DBNull))
                {
                    pidx_ = p[0].parent_idx;
                }

                sh_sit.Addshop_sold_itemRow(p[0].idx, DateTime.Now, DateTime.Now.AddMinutes(p[0].expires_after), 0, p[0].limit, guididx, (int)1, 0, p[0].name, pidx_, payed);
                payed = 0;

                int prn = sh_sit[sh_sit.Rows.Count - 1].idx;

                {
                    mgr.check_function_and_group(s, "Access to " + name);
                    mgr.grant_access_to_function(s);
                }

                // for unlimited package we must grant access to all it's contents
                if (p[0].limit == 0)
                {
                    System.Collections.ArrayList arr = get_item_cont_by_idx((System.Data.SqlClient.SqlConnection)(conn), null, idx);
                    foreach (System.Collections.Hashtable i in arr)
                    {
                        if (i["bound"] == null)
                        {
                            continue;
                        }
                        if (i["bound"].GetType() == typeof(System.DBNull))
                        {
                            continue;
                        }
                        if ((int)i["bound"] != idx)
                        {
                            continue;
                        }
                        if ((int)i["type"] == 2)
                        {
                            name = "Test: " + get_test_name_by_id_((System.Data.SqlClient.SqlConnection)conn, null, (int)i["idx"]);
                            string f = String.Format("item_{0}_{1}", "test", i["idx"]);
                            mgr.check_function_and_group(f, name);
                            mgr.grant_access_to_function(f);
                            //LogManager.GetLogger("Shop.purchase").WarnFormat("Access granted for '{0}' to {1}", mgr.UserLogin, name);
                            sh_sit.Addshop_sold_itemRow((int)i["idx"], DateTime.Now, DateTime.Now.AddMinutes(p[0].expires_after), 0, 0, guididx, (int)2, prn, i["name"].ToString(), p[0].idx, 0);
                        }
                        if ((int)i["type"] == 3)
                        {
                            name = "Download: " + get_download_name_by_id_((System.Data.SqlClient.SqlConnection)conn, null, (int)i["idx"]);
                            string f = String.Format("item_{0}_{1}", "download", i["idx"]);
                            mgr.check_function_and_group(f, name);
                            mgr.grant_access_to_function(f);
                            sh_sit.Addshop_sold_itemRow((int)i["idx"], DateTime.Now, DateTime.Now.AddMinutes(p[0].expires_after), 0, 0, guididx, (int)3, prn, i["name"].ToString(), p[0].idx, 0);
                            //LogManager.GetLogger("Shop.purchase").WarnFormat("Access granted for '{0}' to {1}", mgr.UserLogin, name);
                        }
                    }
                }
            }

            else if ("test" == type)
            {
                string nme = get_test_name_by_id_((System.Data.SqlClient.SqlConnection)conn, null, idx);
                sh_sit.Addshop_sold_itemRow(idx, DateTime.Now, DateTime.Now.AddMinutes(p[0].expires_after), 0, 0, guididx, (int)2, prnt_idx, nme, p[0].idx, payed);

                name = "Test: " + nme;
                mgr.check_function_and_group(s, name);
                mgr.grant_access_to_function(s);
            }
            else if ("download" == type)
            {
                string nme = get_download_name_by_id_((System.Data.SqlClient.SqlConnection)conn, null, idx);
                sh_sit.Addshop_sold_itemRow(idx, DateTime.Now, DateTime.Now.AddMinutes(p[0].expires_after), 0, 0, guididx, (int)3, prnt_idx, nme, p[0].idx, payed);
                name = "Download: " + nme;
                mgr.check_function_and_group(s, name);
                mgr.grant_access_to_function(s);
            }
            else
            {
                throw new System.Exception(String.Format("Unknown type: '{0}'", type));
            }

            sh_sit_ta.Update(sh_sit);
        }