Ejemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.FileUpload1.FileContent.Length > 0)
            {
                //文件存放规则:attachments + 年月 + 文件名+ 后缀
                string fileext  = Path.GetExtension(this.FileUpload1.FileName).ToLower();
                string filename = Utils.GetRandomFilename(this.FileUpload1.FileName);

                string year  = DateTime.Now.Year.ToString();
                string month = DateTime.Now.Month.ToString();

                string rootPath = Path.Combine("/attachments", year.ToString() + month.ToString());
                rootPath = Server.MapPath(rootPath);

                if (!Directory.Exists(rootPath))
                {
                    Directory.CreateDirectory(rootPath);
                }

                //保存文件的路径
                string savePath = Path.Combine(rootPath, filename);

                this.FileUpload1.SaveAs(savePath);

                //需返回到父页面的路径
                string returnPath = string.Format("/{0}/{1}{2}/{3}", "attachments", year, month, filename); //string.Format("{0}{1}/{2}", year, month, filename);
                string parentobj  = HYRequest.GetString("parentobj");
                ClientScript.RegisterStartupScript(this.GetType(), "UpfileTips", "<script language=\"javascript\">window.parent.opener.document.getElementById(\"" + parentobj + "\").value=\"" + returnPath + "\";window.close();</script>");
            }
        }
Ejemplo n.º 2
0
        private void UpLoadFile(HttpContext context)
        {
            //Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig();
            string         _delfile     = HYRequest.GetString("DelFilePath");
            HttpPostedFile _upfile      = context.Request.Files["Filedata"];
            bool           _iswater     = false; //默认不打水印
            bool           _isthumbnail = false; //默认不生成缩略图

            if (HYRequest.GetQueryString("IsWater") == "1")
            {
                _iswater = true;
            }
            if (HYRequest.GetQueryString("IsThumbnail") == "1")
            {
                _isthumbnail = true;
            }
            if (_upfile == null)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}");
                return;
            }
            UpLoad upFiles = new UpLoad();
            string msg     = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater);

            //删除已存在的旧文件,旧文件不为空且应是上传文件,防止跨目录删除
            if (!string.IsNullOrEmpty(_delfile) && _delfile.IndexOf("../") == -1 &&
                _delfile.ToLower().StartsWith(SiteConfig.Instance().FileUpLoadPath.ToLower()))
            {
                Utils.DeleteUpFile(_delfile);
            }
            //返回成功信息
            context.Response.Write(msg);
            context.Response.End();
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                UserModel  userInfo = this.LoginUser;
                OrderModel myorder  = OrderFactory.GetCartOrder(userInfo.uid);

                int    pid      = HYRequest.GetQueryInt("pid", 0);
                int    itemflag = HYRequest.GetQueryInt("itemflag", 0);
                string action   = HYRequest.GetQueryString("action");

                if (action == "add") //添加商品
                {
                    OrderModel myof = myorder;
                    if (myof == null)
                    {
                        myof              = new OrderModel();
                        myof.orderno      = Utils.GenerateOutTradeNo(userInfo.uid); //Utils.GetRandomOrderNo();
                        myof.uid          = userInfo.uid;
                        myof.customername = userInfo.fullname;
                        myof.tel          = userInfo.tel;
                        myof.address      = userInfo.address;
                    }

                    ProductModel p  = ProductFactory.Get(pid);
                    OrderProduct op = new OrderProduct();
                    op.count       = 1;
                    op.productinfo = p;
                    op.price       = p.price;

                    //判断是否有属性
                    if (itemflag > 0)
                    {
                        int tmpflag = 1;
                        foreach (KeyValuePair <string, decimal> kvp in p.itempricelist)
                        {
                            if (itemflag == tmpflag)
                            {
                                op.item  = kvp.Key;
                                op.price = kvp.Value;
                                break;
                            }
                            tmpflag++;
                        }
                    }

                    CheckIsAdd(myof.productlist, op);

                    if (myorder == null)
                    {
                        OrderFactory.Add(myof);
                    }
                    else
                    {
                        OrderFactory.Update(myof);
                    }

                    Response.Redirect("cart.aspx");
                }
                else if (action == "del")
                {
                    OrderModel   myof = myorder;
                    ProductModel p    = ProductFactory.Get(pid);

                    OrderProduct op = new OrderProduct();
                    op.productinfo = p;
                    op.item        = HYRequest.GetQueryString("item");

                    CheckIsDel(myof.productlist, op);

                    OrderFactory.Update(myof);
                    Response.Redirect("cart.aspx");
                }
                else if (action == "ajaxupdate")   //更新数量
                {
                    int    goods_selected = HYRequest.GetInt("goods_selected", 1);
                    int    goods_number   = HYRequest.GetInt("goods_number", 1);
                    int    rec_id         = HYRequest.GetInt("rec_id", 0);
                    string item           = HYRequest.GetString("item");

                    OrderModel   myof = myorder;
                    ProductModel p    = ProductFactory.Get(rec_id);
                    OrderProduct op   = new OrderProduct();
                    op.isselected  = (goods_selected == 1) ? true : false;
                    op.count       = goods_number;
                    op.item        = item;
                    op.productinfo = p;
                    CheckIsUpdate(myof.productlist, op);

                    OrderFactory.Update(myof);

                    string json = "{\"rec_id\":" + rec_id + ",\"goods_number\":" + goods_number + ",\"total_number\":" + myof.productcount + ",\"total_desc\":" + myof.productprice.ToString() + ",\"postage\":" + myof.postage.ToString() + ",\"error\":0}";
                    Response.Write(json);
                    Response.Flush();
                    Response.End();
                    return;
                }
                else if (action == "ajaxupdateall")  //全选状态处理
                {
                    int        goods_selected = HYRequest.GetInt("goods_selected", 1);
                    int        rec_id         = HYRequest.GetInt("rec_id", 0);
                    OrderModel myof           = myorder;
                    foreach (OrderProduct o in myof.productlist)
                    {
                        o.isselected = (goods_selected == 1) ? true : false;
                    }

                    OrderFactory.Update(myof);

                    string json = "{\"rec_id\":" + rec_id + ",\"total_number\":" + myof.productcount + ",\"total_desc\":" + myof.productprice.ToString() + ",\"postage\":" + myof.postage.ToString() + ",\"error\":0}";
                    Response.Write(json);
                    Response.Flush();
                    Response.End();
                    return;
                }

                if (myorder != null && myorder.productcount > 0)
                {
                    this.phNoProduct.Visible = false;
                    CartOrder = myorder;
                }
                else
                {
                    this.phNoProduct.Visible = true;
                }
            }
        }