Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        userId       = Int32.Parse(Session["UserID"].ToString());
        zhuanTiId    = Int32.Parse(Request.QueryString["ztid"]);
        catTypeList  = UserCategoryAccess.GetCategoryTypeList(userId);
        itemTypeList = ItemAccess.GetItemListType();

        if (!IsPostBack)
        {
            BindGrid();

            this.CatTypeEmpIns.DataSource     = catTypeList;
            this.CatTypeEmpIns.DataTextField  = "CategoryTypeName";
            this.CatTypeEmpIns.DataValueField = "CategoryTypeID";
            this.CatTypeEmpIns.DataBind();
            if (Request.Cookies["CatTypeID"] != null)
            {
                this.CatTypeEmpIns.SelectedValue = Request.Cookies["CatTypeID"].Value;
            }

            this.ItemTypeEmpIns.DataSource     = itemTypeList;
            this.ItemTypeEmpIns.DataTextField  = "ItemTypeName";
            this.ItemTypeEmpIns.DataValueField = "ItemTypeValue";
            this.ItemTypeEmpIns.DataBind();

            if (Session["TodayDate"] != null)
            {
                string today = Session["TodayDate"].ToString();
                this.ItemBuyDateEmpIns.Text = today;
            }
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int userId = Int32.Parse(Session["UserID"].ToString());

            DataTable catTypeList = UserCategoryAccess.GetCategoryTypeList(userId);
            this.CatTypeList.DataSource = catTypeList;
            this.CatTypeList.DataBind();

            this.CategoryTypeDown.DataSource     = catTypeList;
            this.CategoryTypeDown.DataTextField  = "CategoryTypeName";
            this.CategoryTypeDown.DataValueField = "CategoryTypeID";
            this.CategoryTypeDown.DataBind();
            this.CategoryTypeDown.Items.Insert(0, new ListItem("请选择", "0"));

            this.ZhuanTiDown.DataSource     = ZhuanTiAccess.GetZhuanTiList(userId);
            this.ZhuanTiDown.DataTextField  = "ZhuanTiName";
            this.ZhuanTiDown.DataValueField = "ZTID";
            this.ZhuanTiDown.DataBind();
            this.ZhuanTiDown.Items.Insert(0, new ListItem("请选择", "0"));

            this.ItemType.Attributes.Add("readonly", "readonly");
            this.CategoryTypeDown.Attributes.Add("readonly", "readonly");
            this.ItemBuyDate.Attributes.Add("readonly", "readonly");
            //this.ItemBuyDate1.Attributes.Add("readonly", "readonly");
            //this.ItemBuyDate2.Attributes.Add("readonly", "readonly");

            if (Session["TodayDate"] != null)
            {
                string today  = Session["TodayDate"].ToString();
                string today2 = DateTime.Parse(today).AddMonths(11).ToString("yyyy-MM-dd");

                this.ItemBuyDate.Text     = today + " " + ItemHelper.GetWeekString(today, 0);
                this.ItemBuyDateHid.Value = today;

                this.ItemBuyDate1.Text = today;
                this.ItemBuyDate2.Text = today2;
            }

            //钱包
            this.CardDown.DataSource     = CardAccess.GetCardList(userId);
            this.CardDown.DataTextField  = "CardName";
            this.CardDown.DataValueField = "CardID";
            this.CardDown.DataBind();
            if (Request.Cookies["CardID"] != null)
            {
                string cardId = Request.Cookies["CardID"].Value;
                this.CardDown.SelectedValue = cardId;
            }
        }
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        userId       = Int32.Parse(Session["UserID"].ToString());
        catTypeList  = UserCategoryAccess.GetCategoryTypeList(userId);
        itemTypeList = ItemAccess.GetItemListType();
        cardList     = CardAccess.GetCardList(userId);

        if (Request.QueryString["date"] != null && Request.QueryString["date"] != "")
        {
            if (!ValidHelper.CheckDate(Request.QueryString["date"]))
            {
                Session["TodayDate"] = DateTime.Now.ToString("yyyy-MM-dd");
            }
            else
            {
                Session["TodayDate"] = Request.QueryString["date"];
            }
        }
        today = Session["TodayDate"].ToString();

        if (!IsPostBack)
        {
            BindGrid();

            this.CatTypeEmpIns.DataSource     = catTypeList;
            this.CatTypeEmpIns.DataTextField  = "CategoryTypeName";
            this.CatTypeEmpIns.DataValueField = "CategoryTypeID";
            this.CatTypeEmpIns.DataBind();
            if (Request.Cookies["CatTypeID"] != null)
            {
                this.CatTypeEmpIns.SelectedValue = Request.Cookies["CatTypeID"].Value;
            }

            this.ItemTypeEmpIns.DataSource     = itemTypeList;
            this.ItemTypeEmpIns.DataTextField  = "ItemTypeName";
            this.ItemTypeEmpIns.DataValueField = "ItemTypeValue";
            this.ItemTypeEmpIns.DataBind();

            //钱包
            this.CardEmpIns.DataSource     = cardList;
            this.CardEmpIns.DataTextField  = "CardName";
            this.CardEmpIns.DataValueField = "CardID";
            this.CardEmpIns.DataBind();
            if (Request.Cookies["CardID"] != null)
            {
                this.CardEmpIns.SelectedValue = Request.Cookies["CardID"].Value;
            }
        }
    }
    protected void BindGrid()
    {
        double    catRate = Double.Parse(Session["CategoryRate"].ToString());
        DataTable dt      = UserCategoryAccess.GetCategoryTypeList(userId);

        dt.Columns.Add("CategoryTypeRate", typeof(string));
        foreach (DataRow dr in dt.Rows)
        {
            double   catPrice = Double.Parse(dr["CategoryTypePrice"].ToString());
            double[] denArr   = GetDenArray(catPrice, catRate);
            if (catPrice > 0)
            {
                dr["CategoryTypeRate"] = denArr[0] + " ~ " + denArr[1];
            }
            else
            {
                dr["CategoryTypeRate"] = "0";
            }
        }

        this.CatTypeList.DataSource = dt;
        this.CatTypeList.DataBind();
    }
    //导出数据到App//
    protected void Button1_Click(object sender, EventArgs e)
    {
        int userId = Int32.Parse(Session["UserID"].ToString());

        fileName = "aalife2.bak";

        StringBuilder sb = new StringBuilder();

        DataTable itemListTab = BackupAccess.BackupItemTableById(userId);

        if (itemListTab.Rows.Count > 0)
        {
            sb.AppendLine("DELETE FROM ItemTable;");
            foreach (DataRow dr in itemListTab.Rows)
            {
                sb.AppendLine("INSERT INTO ItemTable (ItemType, ItemName, ItemPrice, ItemBuyDate, CategoryID, Recommend, Synchronize, RegionID, RegionType, ZhuanTiID, CardID) VALUES ('" +
                              dr["ItemType"].ToString() + "', '" +
                              dr["ItemName"].ToString() + "', '" +
                              dr["ItemPrice"].ToString() + "', '" +
                              String.Format("{0:yyyy-MM-dd}", dr["ItemBuyDate"]) + "', '" +
                              dr["CategoryTypeID"].ToString() + "', '" +
                              dr["Recommend"].ToString() + "', '0', '" +
                              dr["RegionID"].ToString() + "', '" +
                              dr["RegionType"].ToString() + "', '" +
                              dr["ZhuanTiID"].ToString() + "', '" +
                              dr["CardID"].ToString() + "');");
            }
            sb.AppendLine("");
        }

        DataTable catListTab = UserCategoryAccess.GetCategoryTypeList(userId);

        if (catListTab.Rows.Count > 0)
        {
            sb.AppendLine("DELETE FROM CategoryTable;");
            foreach (DataRow dr in catListTab.Rows)
            {
                sb.AppendLine("INSERT INTO CategoryTable (CategoryID, CategoryName, CategoryPrice, CategoryRank, CategoryDisplay, CategoryLive) VALUES ('" +
                              dr["CategoryTypeID"].ToString() + "', '" +
                              dr["CategoryTypeName"].ToString() + "', '" +
                              dr["CategoryTypePrice"].ToString() + "', '" +
                              dr["CategoryTypeID"].ToString() + "', '1', '1');");
            }
            sb.AppendLine("");
        }

        DataTable zhuanTiTab = ZhuanTiAccess.GetZhuanTiList(userId);

        if (zhuanTiTab.Rows.Count > 0)
        {
            sb.AppendLine("DELETE FROM ZhuanTiTable;");
            foreach (DataRow dr in zhuanTiTab.Rows)
            {
                sb.AppendLine("INSERT INTO ZhuanTiTable (ZTID, ZhuanTiName, ZhuanTiImage, ZhuanTiLive, Synchronize) VALUES ('" +
                              dr["ZTID"].ToString() + "', '" +
                              dr["ZhuanTiName"].ToString() + "', '" +
                              dr["ZhuanTiImage"].ToString() + "', '" +
                              dr["ZhuanTiLive"].ToString() + "', '0');");
            }
            sb.AppendLine("");
        }

        DataTable cardTab = CardAccess.GetCardList(userId);

        if (cardTab.Rows.Count > 0)
        {
            sb.AppendLine("DELETE FROM CardTable;");
            foreach (DataRow dr in cardTab.Rows)
            {
                if (dr["CardID"].ToString() == "0")
                {
                    continue;
                }
                sb.AppendLine("INSERT INTO CardTable (CDID, CardName, CardMoney, CardLive, Synchronize) VALUES ('" +
                              dr["CardID"].ToString() + "', '" +
                              dr["CardName"].ToString() + "', '" +
                              dr["CardMoney"].ToString() + "', '" +
                              dr["CardLive"].ToString() + "', '0');");
            }
        }

        BackupAccess.WriteBackupFile(filePath + fileName, sb.ToString());

        //Utility.Alert(this, "导出成功。");

        DownBackFile();
    }
Esempio n. 6
0
    //导入保存
    protected int[] SaveExcel(DataTable dt)
    {
        int[] arr = new int[2];
        all = UserAccess.ExportUserData(userId);

        catTypeList = UserCategoryAccess.GetCategoryTypeList(userId);

        string            dbProviderName     = WebConfiguration.DbProviderName;
        string            dbConnectionString = WebConfiguration.DbConnectionString;
        DbProviderFactory factory            = DbProviderFactories.GetFactory(dbProviderName);

        using (DbConnection conn = factory.CreateConnection())
        {
            conn.ConnectionString = dbConnectionString;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            DbCommand     comm = conn.CreateCommand();
            comm.Connection  = conn;
            comm.Transaction = tran;

            try
            {
                int           n1 = 0;
                int           n2 = 0;
                StringBuilder sb = new StringBuilder();
                foreach (DataRow dr in dt.Rows)
                {
                    string   _itemType    = GetItemTypeValue(dr["分类"].ToString());
                    string   _itemName    = dr["商品名称"].ToString();
                    int      _catTypeId   = GetCategoryTypeId(dr["商品类别"].ToString(), catTypeList);
                    string   _itemPrice   = dr["商品价格"].ToString();
                    DateTime _itemBuyDate = DateTime.Parse(dr["购买日期"].ToString());
                    int      _recommend   = (dr["推荐否"].ToString() == "否" ? 0 : 1);

                    ItemEntity item = new ItemEntity();
                    item.ItemType       = _itemType;
                    item.ItemName       = _itemName;
                    item.CategoryTypeID = _catTypeId;
                    item.ItemPrice      = (_itemPrice == "" ? 0 : Double.Parse(_itemPrice));
                    item.ItemBuyDate    = _itemBuyDate;
                    item.Recommend      = _recommend;

                    if (CheckRepeat(item, catTypeList))
                    {
                        n2++;
                        continue;
                    }
                    sb.AppendLine("INSERT INTO ItemTable(ItemType, ItemName, CategoryTypeID, ItemPrice, ItemBuyDate, UserID, Recommend) VALUES('" +
                                  item.ItemType + "','" + item.ItemName + "','" + item.CategoryTypeID + "','" + item.ItemPrice + "','" +
                                  item.ItemBuyDate.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss") + "','" + userId + "','" + item.Recommend + "');");
                    n1++;
                }

                arr[0] = n1;
                arr[1] = n2;
                if (sb.ToString() == "")
                {
                    return(arr);
                }

                comm.CommandText = sb.ToString();
                comm.ExecuteNonQuery();
                tran.Commit();
            }
            catch
            {
                tran.Rollback();
                throw;
            }
            finally
            {
                conn.Close();
            }
        }

        return(arr);
    }