⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addproduct.ascx.cs

📁 网上书店
💻 CS
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class AdminControl_AddProduct : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Admin"] != null)
        {
            if (!IsPostBack)
            {
                if (AdminCenterAccess.GetAdminTypeByAdminName(Session["Admin"].ToString()) == "超级管理员"
                    || AdminCenterAccess.GetAdminTypeByAdminName(Session["Admin"].ToString()) == "图书管理员")
                {
                    GetCategories();
                }
                else
                {
                    Response.Redirect("AdminCenter.aspx");
                }
            }
        }
    }

    private void GetCategories()
    {
        lbxCategory.DataSource = CommonDataAccess.GetCategories();
        lbxCategory.DataTextField = "Name";
        lbxCategory.DataValueField = "CategoryID";
        lbxCategory.DataBind();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string fileName1 = fileUploadImageSmall.FileName;
        string fileType1 = fileName1.Substring(fileName1.LastIndexOf('.') + 1);
        if (!IsPhotoLogical(fileType1))
        {
            Message.ShowMsgBox(Page, "图片1不是正确的图片格式");
            return;
        }
        string fileName2 = fileUploasImageBig.FileName;
        string fileType2 = fileName2.Substring(fileName2.LastIndexOf('.') + 1);
        if (!IsPhotoLogical(fileType2))
        {
            Message.ShowMsgBox(Page, "图片2不是正确的图片格式");
            return;
        }
        fileName1 = txtBookNO.Text + "1." + fileType1;
        fileName2 = txtBookNO.Text + "2." + fileType2;
        if (!UploadImage(fileName1, fileUploadImageSmall))
        {
            Message.ShowMsgBox(Page, "图片1上传失败!");
            return;
        }
        if (!UploadImage(fileName2, fileUploasImageBig))
        {
            Message.ShowMsgBox(Page, "图片2上传失败!");
            return;
        }

        if (AdminCenterAccess.InsertNewBookInfo(txtBookName.Text, fileName1, fileName2, txtAuthor.Text, txtPublisher.Text,txtBookNO.Text, txtContent.Text, txtPrice.Text, rblIsRecommand.SelectedValue.ToString(), rblSpecialPrice.SelectedValue.ToString(),
            txtCount.Text.ToString()))
        {
             
            string bookID = AdminCenterAccess.GetBookInfoByBookNo(txtBookNO.Text);
            int i;
            for (i = 0; i < lbxCategory.Items.Count; i++)
            {
                
                if (lbxCategory.Items[i].Selected == true)
                {
                    
                    if (!AdminCenterAccess.InsertBook_BookCategory(bookID, lbxCategory.Items[i].Value.ToString()))
                    {
                        Message.ShowMsgBox(Page, "图书添加失败!");
                        return;
                    }
                }
            }

            Message.ShowMsgBox(Page, "图书添加成功!");
            imgSmall.ImageUrl = "~/BookImages/" + fileName1;
            imgBig.ImageUrl = "~/BookImages/" + fileName2;

        }
        else
        {
            Message.ShowMsgBox(Page, "图书添加失败!");
        }
    }

    protected bool UploadImage(string fileName, FileUpload file)
    {
        bool success = false;
        try
        {
            string filePath = Server.MapPath("BookImages") + "\\" + fileName;
            file.SaveAs(filePath);
            success = true;
        }
        catch
        {

        }
        return success;
    }

    private bool IsPhotoLogical(string fileType1)
    {
        string type = fileType1.ToUpper();
        if (type == "BMP" || type == "GIF" || type == "JPG")
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    protected void lbxCategory_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -