示例#1
0
        //检查用户登录帐号和密码
        public static AdUserInfo CheckUserLogin(string userId, string pwd)
        {
            string     sqlString = "select * from dbo.AdUserInfo where AdminUserId=@AdminUserId and AdminUserPwd=@AdminUserPwd";
            AdUserInfo item      = null;

            //参数列表
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@AdminUserId", userId),
                new SqlParameter("@AdminUserPwd", pwd)
            };
            try
            {
                using (SqlDataReader reader = SQLHelper.GetReader(sqlString, parms))
                {
                    if (reader.Read() && !reader.IsClosed)
                    {
                        item = new AdUserInfo(reader);
                    }
                    reader.Close();//关闭reader
                }
            }
            catch (Exception e)
            {
            }
            return(item);
        }
        //将上传成功的产品图片名称更新至数据库
        private bool UpdateDbFilesName(string fileName)
        {
            string adminUserId = string.Empty;

            if (Session["LoginedAdmin"] != null)
            {
                AdUserInfo adminUserObj = (AdUserInfo)Session["LoginedAdmin"];
                adminUserId = adminUserObj.AdminUserId;
            }
            return(ProductsDAL.UpdateProductImgFiles(fileName, txtProductId.Text, adminUserId));
        }
        //删除图片文件
        protected void imgdelbfbtn_Click(object sender, ImageClickEventArgs e)
        {
            uplblmsg.Text      = string.Empty;
            uplblmsg.ForeColor = System.Drawing.Color.Red;
            string adminUserId = string.Empty;

            if (Session["LoginedAdmin"] != null)
            {
                AdUserInfo adminUserObj = (AdUserInfo)Session["LoginedAdmin"];
                adminUserId = adminUserObj.AdminUserId;
            }
            if (ProductsDAL.UpdateProductImgFilesByDelete(txtProductId.Text, adminUserId))
            {
                uplblmsg.ForeColor = System.Drawing.Color.Green;
                uplblmsg.Text      = "删除产品图片成功!";
                //取得上传路径
                string upLoadFileOldPatch = Server.MapPath("~/ProductImg/" + txtProductId.Text);
                if (Directory.Exists(upLoadFileOldPatch))
                {
                    DirectoryInfo dir = new DirectoryInfo(upLoadFileOldPatch);
                    //删除目录及子目录和文件
                    try
                    {
                        dir.Delete(true);
                    }
                    catch (Exception)
                    {
                        uplblmsg.Text = "(删除产品图片文件失败!)";
                    }
                }
                HttpContext.Current.Response.Write("<script language='javascript'>alert('删除图片成功!');</script>");
            }
            else
            {
                lblmsg.Text = "删除产品图片失败!";
            }
        }
        //修改
        protected void imgUpdatebtn_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtProductId.Text))
            {
                Products item = new Products();
                //修改条件  HttpContext.Current.Response.Write("<script language='javascript'>alert(' 请输入密码? ');</script>");
                item.ProductId   = txtProductId.Text;
                item.ProductName = txtProductName.Text;

                decimal result = 0;
                //成本价
                if (decimal.TryParse(txtProductCost.Text, out result))
                {
                    item.ProductCost = decimal.Parse(txtProductCost.Text);
                }
                else
                {
                    HttpContext.Current.Response.Write("<script language='javascript'>alert('产品成本价不符合要求!');</script>");
                }

                //销售价
                decimal result1 = 0;
                if (decimal.TryParse(txtSalePrice.Text, out result1))
                {
                    item.SalePrice = decimal.Parse(txtSalePrice.Text);
                }
                else
                {
                    HttpContext.Current.Response.Write("<script language='javascript'>alert('产品销售价不符合要求!');</script>");
                }

                //最低库存量
                decimal result2 = 0;
                if (decimal.TryParse(txtCurrentstock.Text, out result2))
                {
                    item.Currentstock = decimal.Parse(txtCurrentstock.Text);
                }
                else
                {
                    HttpContext.Current.Response.Write("<script language='javascript'>alert('最低库存量不符合要求!');</script>");
                }


                //是否要提醒
                item.StockNotifyStatus = int.Parse(dwlStockNotifyStatus.SelectedItem.Value);
                item.Remarks           = txtRemarks.Text;
                item.UpdateDate        = DateTime.Now;
                if (Session["LoginedAdmin"] != null)
                {
                    AdUserInfo adminUserObj = (AdUserInfo)Session["LoginedAdmin"];
                    item.Updater = adminUserObj.AdminUserId;
                }
                item.ProductUnits = txtProductUnits.Text;
                //更新产品信息
                if (ProductsDAL.UpdateProductInfo(item))
                {
                    InitProduct(item.ProductId);
                    HttpContext.Current.Response.Write("<script language='javascript'>alert('修改产品信息成功!');</script>");
                }
                else
                {
                    HttpContext.Current.Response.Write("<script language='javascript'>alert('修改产品信息失败!');</script>");
                }
            }
            else
            {
                HttpContext.Current.Response.Write("<script language='javascript'>alert('没有产品信息无法修改!');</script>");
            }
        }
示例#5
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUserId.Text == string.Empty)
            {
                lbltp.Text = "请输入帐号?";
                txtUserId.Focus();
            }
            else if (txtPwd.Text == string.Empty)
            {
                lbltp.Text = string.Empty;
                txtPwd.Focus();
                HttpContext.Current.Response.Write("<script language='javascript'>alert(' 请输入密码? ');</script>");
            }
            else if (txtVerifycode.Text == string.Empty)
            {
                HttpContext.Current.Response.Write("<script language='javascript'>alert(' 请输入验证码? ');</script>");
                txtVerifycode.Focus();
            }
            else
            {
                string verfiycode = string.Empty;
                if (Session["VerifyCodeAdmin"] != null)
                {
                    verfiycode = (string)Session["VerifyCodeAdmin"];
                    if (txtVerifycode.Text.ToLower() != verfiycode.ToLower())
                    {
                        HttpContext.Current.Response.Write("<script language='javascript'>alert(' 验证码输入错误! ');</script>");
                    }
                    else
                    {
                        //查询数据校验帐号和密码
                        //查询之前先加密密码再与数据库中的密码比对
                        string     adminPwd = ComClass.TripleDESEncryptString(txtPwd.Text);
                        AdUserInfo item     = AdUserInfoDAL.CheckUserLogin(
                            ComClass.NoHTML(txtUserId.Text), adminPwd);
                        if (item == null)
                        {
                            HttpContext.Current.Response.Write("<script language='javascript'>alert(' 输入错误,未通过验证!');</script>");
                        }
                        else
                        {
                            if (item.AdminUserId == txtUserId.Text)
                            {
                                Session["LoginedAdmin"] = item;

                                //发放令牌
                                System.Web.Security.FormsAuthentication.SetAuthCookie(item.AdminUserId, false);

                                //跳转页面
                                Response.Redirect("~/Admin/ProductManageList.aspx");
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("<script language='javascript'>alert(' 注意大小写!');</script>");
                            }
                        }
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write("<script language='javascript'>alert(' 服务生成验证码出错! ');</script>");
                }
            }
        }