Esempio n. 1
0
    /// <summary>
    /// 验证模块
    /// </summary>
    /// <returns></returns>
    private new bool IsValid()
    {
        var selDate = Calendar1.SelectedDate;

        if (selDate.Date <= DateTime.Now.Date.Date)
        {
            lblError.Text = "选择的排餐日期必须大于今天!";
            return(false);
        }

        if (string.IsNullOrEmpty(ddlCookbookEnum.SelectedValue))
        {
            lblError.Text = "请选择排餐时段!";
            return(false);
        }

        if (string.IsNullOrEmpty(ddlCafeteria.SelectedValue))
        {
            lblError.Text = "请选择食堂!";
            return(false);
        }

        if (cbklCookbook.SelectedItem == null)
        {
            lblError.Text = "请选择排餐菜品!";
            return(false);
        }

        if (pnlPrice.Visible)
        {
            if (string.IsNullOrEmpty(tbxPrice.Text.Trim()) || !ValidationUtility.IsDecimal(tbxPrice.Text.Trim()))
            {
                lblError.Text = "请输入正确格式的自助餐价格!";
                return(false);
            }
        }

        if (string.IsNullOrEmpty(txtOrder.Text.Trim()) || !ValidationUtility.IsDecimal(txtOrder.Text.Trim()))
        {
            lblError.Text = "请输入正确格式的排序数值!";
            return(false);
        }

        //判断当前日期的三餐排餐信息是否已经存在
        var cbList = _cookbookBLL.GetCookbookSetInDateList((CookbookEnum)Enum.Parse(typeof(CookbookEnum), this.ddlCookbookEnum.SelectedValue),
                                                           Calendar1.SelectedDate, PageUtility.User.OrganizationId, Convert.ToInt32(ddlCafeteria.SelectedValue));

        if (cbList.Count != 0)
        {
            lblError.Text = "当前排餐信息已经存在!";
            return(false);
        }
        return(true);
    }
    private CookbookInfo getCookbookInfo(UserInfo loginedUser)
    {
        // 检查用户的输入情况
        if (string.IsNullOrEmpty(txtName.Text.Trim()))
        {
            lblError.Text = "请输入菜品名称!";
            return(null);
        }

        if (string.IsNullOrEmpty(txtPrice.Text.Trim()) || !ValidationUtility.IsDecimal(txtPrice.Text.Trim()))
        {
            lblError.Text = "请输入正确格式的价格数值!";
            return(null);
        }


        if (string.IsNullOrEmpty(txtSalePrice.Text.Trim()) || !ValidationUtility.IsDecimal(txtSalePrice.Text.Trim()))
        {
            lblError.Text = "请输入正确格式的优惠价格数值!";
            return(null);
        }

        if (string.IsNullOrEmpty(txtOrder.Text.Trim()) || !ValidationUtility.IsDecimal(txtOrder.Text.Trim()))
        {
            lblError.Text = "请输入正确格式的排序数值!";
            return(null);
        }

        var ret = new CookbookInfo
        {
            Id            = 0,
            CreatedByID   = loginedUser.ID,
            CreatedByName = loginedUser.Alias,
            CreatedDate   = DateTime.Now
        };

        // 如果是修改,则获取要修改的对象
        if (!string.IsNullOrEmpty(Request["id"]))
        {
            var cbInfo = _cookbookBLL.GetCookbook(Convert.ToInt32(Request["id"]));
            if (cbInfo == null)
            {
                return(null);
            }

            ret = cbInfo;
        }

        if (fileIcon.HasFile)
        {
            var fileExt = FileUtility.GetExtension(fileIcon.FileName);
            if (fileExt.ToLower() != ".jpg" && fileExt.ToLower() != ".png")
            {
                lblError.Text = "请输入jpg或png图片!";
                return(null);
            }

            var filePath     = FileUtility.GetNewFileName(Path.GetFileName(fileIcon.FileName));
            var filePathThum = FileUtility.GetNewFileName(filePath);

            FileUtility.FileSave(FileUtility.GetPhysicAbsoluteFullFileName(FileUtility.ConstCookbookImg, filePath),
                                 this.fileIcon.PostedFile, 60, 60,
                                 FileUtility.GetPhysicAbsoluteFullFileName(FileUtility.ConstCookbookImg, filePathThum));

            ret.Icon     = filePath;
            ret.IconThum = filePathThum;
        }

        ret.Name        = txtName.Text.Trim();
        ret.Description = txtDescription.Text.Trim();

        ret.Price     = decimal.Parse(txtPrice.Text.Trim());
        ret.SalePrice = decimal.Parse(txtSalePrice.Text.Trim());
        ret.RealPrice = ret.Price - ret.SalePrice;

        if (!loginedUser.IsSystem)
        {
            if (loginedUser.OrganizationId != null)
            {
                ret.OrganizationId = loginedUser.OrganizationId.Value;
            }
            ret.OrganizationName = loginedUser.OrganizationName;
        }

        ret.DisplayOrder = int.Parse(txtOrder.Text.Trim());

        ret.LastUpdByID   = loginedUser.ID;
        ret.LastUpdByName = loginedUser.Alias;
        ret.LastUpdDate   = DateTime.Now;

        return(ret);
    }
    private CookbookPreferentialInRankInfo getcprInfo(UserInfo loginedUser)
    {
        // 检查用户的输入情况
        if (string.IsNullOrEmpty(txtName.Text.Trim()))
        {
            lblError.Text = "请输入优惠名称!";
            return(null);
        }

        if (string.IsNullOrEmpty(ddlCookbook.SelectedValue))
        {
            lblError.Text = "请选择菜品!";
            return(null);
        }

        if (string.IsNullOrEmpty(ddlRank.SelectedValue))
        {
            lblError.Text = "请选择警衔!";
            return(null);
        }

        if (string.IsNullOrEmpty(txtSalePrice.Text.Trim()) || !ValidationUtility.IsDecimal(txtSalePrice.Text.Trim()))
        {
            lblError.Text = "请输入正确格式的优惠价格数值!";
            return(null);
        }

        if (string.IsNullOrEmpty(txtOrder.Text.Trim()) || !ValidationUtility.IsDecimal(txtOrder.Text.Trim()))
        {
            lblError.Text = "请输入正确格式的排序数值!";
            return(null);
        }

        var ret = new CookbookPreferentialInRankInfo
        {
            Id            = 0,
            CreatedByID   = loginedUser.ID,
            CreatedByName = loginedUser.Alias,
            CreatedDate   = DateTime.Now
        };

        var rankId     = Convert.ToInt32(this.ddlRank.SelectedValue);
        var cookbookId = Convert.ToInt32(this.ddlCookbook.SelectedValue);

        // 如果是修改,则获取要修改的对象
        if (!string.IsNullOrEmpty(Request["id"]))
        {
            var cbrInfo = _cookbookBLL.GetCookbookPreferentialInRank(Convert.ToInt32(Request["id"]));
            if (cbrInfo == null)
            {
                return(null);
            }

            ret = cbrInfo;
        }
        else
        {
            //判断是否已经存在了当前机构,当前菜品,当前警衔是的数据是否存在,如果存在,则给出修改链接
            if (loginedUser.OrganizationId != null)
            {
                var info = _cookbookBLL.GetCookbookPreferentialInRank(rankId, cookbookId, loginedUser.OrganizationId.Value);
                if (info != null)
                {
                    lblError.Text = "当前菜品的优惠已经存在,您可以进行修改菜品优惠处理";
                    return(null);
                }
            }
        }

        ret.Name        = txtName.Text.Trim();
        ret.Description = txtDescription.Text.Trim();

        ret.RankId   = rankId;
        ret.RandName = this.ddlRank.SelectedItem.Text;

        ret.CookbookId   = cookbookId;
        ret.CookbookName = this.ddlCookbook.SelectedItem.Text;

        ret.SalePrice = decimal.Parse(this.txtSalePrice.Text.Trim());

        //获取cookbook的实际价格
        var cbInfo = _cookbookBLL.GetCookbook(ret.CookbookId);

        if (cbInfo != null)
        {
            ret.RealPrice = cbInfo.Price - ret.SalePrice;
        }

        ret.SalePrice = decimal.Parse(txtSalePrice.Text.Trim());

        if (!loginedUser.IsSystem)
        {
            if (loginedUser.OrganizationId != null)
            {
                ret.OrganizationId = loginedUser.OrganizationId.Value;
            }
            ret.OrganizationName = loginedUser.OrganizationName;
        }

        ret.DisplayOrder = int.Parse(txtOrder.Text.Trim());

        ret.LastUpdByID   = loginedUser.ID;
        ret.LastUpdByName = loginedUser.Alias;
        ret.LastUpdDate   = DateTime.Now;

        return(ret);
    }