1. 程式人生 > >ERP商品管理業務邏輯封裝(三十一)

ERP商品管理業務邏輯封裝(三十一)

extend colspan wid tel row $() ase 1.4 ble

產品購進管理業務邏輯:

 public   class ProductBLL
    {

      /// <summary>
      /// 產品對象添加 並且返回產品編號
      /// </summary>
      /// <param name="viewpro">產品視圖對象</param>
      public int BiotbProductAdd(ViewProInfo model)
      {
          int rowsAffected;
          SqlParameter[] parameters = {
					new SqlParameter("@ProID", SqlDbType.Int,4),
					new SqlParameter("@ProName", SqlDbType.NVarChar,100),
					new SqlParameter("@TypeID", SqlDbType.Int,4),
					new SqlParameter("@CustomerID", SqlDbType.Int,4),
					new SqlParameter("@ProLogo", SqlDbType.NVarChar,200),
					new SqlParameter("@Spec", SqlDbType.NVarChar,100),
					new SqlParameter("@ProFullName", SqlDbType.NVarChar,100),
					new SqlParameter("@ConfirmNo", SqlDbType.NVarChar,100),
					new SqlParameter("@Unit", SqlDbType.NVarChar,50),
					new SqlParameter("@ProSize", SqlDbType.NVarChar,50),
					new SqlParameter("@Grossweight", SqlDbType.NVarChar,50),
					new SqlParameter("@MadeEnterprise", SqlDbType.NVarChar,100),
					new SqlParameter("@Retailprice", SqlDbType.Money,8),
					new SqlParameter("@BidPrice", SqlDbType.Money,8),
					new SqlParameter("@TradePrice", SqlDbType.Money,8),
					new SqlParameter("@AdvicePrice", SqlDbType.Money,8),
					new SqlParameter("@CountyPrice", SqlDbType.Money,8),
					new SqlParameter("@CityPrice", SqlDbType.Money,8),
					new SqlParameter("@ProvincePrice", SqlDbType.Money,8),
					new SqlParameter("@NetPrice", SqlDbType.Money,8),
					new SqlParameter("@NetVipPrice", SqlDbType.Money,8),
					new SqlParameter("@NetMemberprice", SqlDbType.Money,8),
					new SqlParameter("@OurCompany", SqlDbType.NVarChar,100),
					new SqlParameter("@ChannelID", SqlDbType.Int,4),
					new SqlParameter("@Usefullife", SqlDbType.NVarChar,50),
					new SqlParameter("@SubmitTime", SqlDbType.DateTime),
					new SqlParameter("@StockMost", SqlDbType.NVarChar,100),
					new SqlParameter("@StockLess", SqlDbType.NVarChar,100),
					new SqlParameter("@Remark", SqlDbType.NVarChar,1000)};
          parameters[0].Direction = ParameterDirection.Output;
          parameters[1].Value = model.ProName;
          parameters[2].Value = model.TypeID;
          parameters[3].Value = model.CustomerID;
          parameters[4].Value = model.ProLogo;
          parameters[5].Value = model.Spec;
          parameters[6].Value = model.ProFullName;
          parameters[7].Value = model.ConfirmNo;
          parameters[8].Value = model.Unit;
          parameters[9].Value = model.ProSize;
          parameters[10].Value = model.Grossweight;
          parameters[11].Value = model.MadeEnterprise;
          parameters[12].Value = model.Retailprice;
          parameters[13].Value = model.BidPrice;
          parameters[14].Value = model.TradePrice;
          parameters[15].Value = model.AdvicePrice;
          parameters[16].Value = model.CountyPrice;
          parameters[17].Value = model.CityPrice;
          parameters[18].Value = model.ProvincePrice;
          parameters[19].Value = model.NetPrice;
          parameters[20].Value = model.NetVipPrice;
          parameters[21].Value = model.NetMemberprice;
          parameters[22].Value = model.OurCompany;
          parameters[23].Value = model.ChannelID;
          parameters[24].Value = model.Usefullife;
          parameters[25].Value = model.SubmitTime;
          parameters[26].Value = model.StockMost;
          parameters[27].Value = model.StockLess;
          parameters[28].Value = model.Remark;


          rowsAffected= DataBaseHelper.ExcuteSqlReturnInt("BiotbProduct_ADD", CommandType.StoredProcedure, parameters);
          if (rowsAffected != 0)
          {
              return int.Parse(parameters[0].ToString());
          }
          else
          {
              return 0;
          }

      
      }

      /// <summary>
      /// 修改產品對象
      /// </summary>
      /// <param name="model">產品對象</param>
      /// <returns>int</returns>
      public int BiotbProductUpdate(ViewProInfo model)
      {
          SqlParameter[] parameters = {
					new SqlParameter("@ProID", SqlDbType.Int,4),
					new SqlParameter("@ProName", SqlDbType.NVarChar,100),
					new SqlParameter("@TypeID", SqlDbType.Int,4),
					new SqlParameter("@CustomerID", SqlDbType.Int,4),
					new SqlParameter("@ProLogo", SqlDbType.NVarChar,200),
					new SqlParameter("@Spec", SqlDbType.NVarChar,100),
					new SqlParameter("@ProFullName", SqlDbType.NVarChar,100),
					new SqlParameter("@ConfirmNo", SqlDbType.NVarChar,100),
					new SqlParameter("@Unit", SqlDbType.NVarChar,50),
					new SqlParameter("@ProSize", SqlDbType.NVarChar,50),
					new SqlParameter("@Grossweight", SqlDbType.NVarChar,50),
					new SqlParameter("@MadeEnterprise", SqlDbType.NVarChar,100),
					new SqlParameter("@Retailprice", SqlDbType.Money,8),
					new SqlParameter("@BidPrice", SqlDbType.Money,8),
					new SqlParameter("@TradePrice", SqlDbType.Money,8),
					new SqlParameter("@AdvicePrice", SqlDbType.Money,8),
					new SqlParameter("@CountyPrice", SqlDbType.Money,8),
					new SqlParameter("@CityPrice", SqlDbType.Money,8),
					new SqlParameter("@ProvincePrice", SqlDbType.Money,8),
					new SqlParameter("@NetPrice", SqlDbType.Money,8),
					new SqlParameter("@NetVipPrice", SqlDbType.Money,8),
					new SqlParameter("@NetMemberprice", SqlDbType.Money,8),
					new SqlParameter("@OurCompany", SqlDbType.NVarChar,100),
					new SqlParameter("@ChannelID", SqlDbType.Int,4),
					new SqlParameter("@Usefullife", SqlDbType.NVarChar,50),
					new SqlParameter("@SubmitTime", SqlDbType.DateTime),
					new SqlParameter("@StockMost", SqlDbType.NVarChar,100),
					new SqlParameter("@StockLess", SqlDbType.NVarChar,100),
					new SqlParameter("@Remark", SqlDbType.NVarChar,1000)};
          parameters[0].Value = model.ProID;
          parameters[1].Value = model.ProName;
          parameters[2].Value = model.TypeID;
          parameters[3].Value = model.CustomerID;
          parameters[4].Value = model.ProLogo;
          parameters[5].Value = model.Spec;
          parameters[6].Value = model.ProFullName;
          parameters[7].Value = model.ConfirmNo;
          parameters[8].Value = model.Unit;
          parameters[9].Value = model.ProSize;
          parameters[10].Value = model.Grossweight;
          parameters[11].Value = model.MadeEnterprise;
          parameters[12].Value = model.Retailprice;
          parameters[13].Value = model.BidPrice;
          parameters[14].Value = model.TradePrice;
          parameters[15].Value = model.AdvicePrice;
          parameters[16].Value = model.CountyPrice;
          parameters[17].Value = model.CityPrice;
          parameters[18].Value = model.ProvincePrice;
          parameters[19].Value = model.NetPrice;
          parameters[20].Value = model.NetVipPrice;
          parameters[21].Value = model.NetMemberprice;
          parameters[22].Value = model.OurCompany;
          parameters[23].Value = model.ChannelID;
          parameters[24].Value = model.Usefullife;
          parameters[25].Value = model.SubmitTime;
          parameters[26].Value = model.StockMost;
          parameters[27].Value = model.StockLess;
          parameters[28].Value = model.Remark;

          return DataBaseHelper.ExcuteSqlReturnInt("BioProType_Update", CommandType.StoredProcedure, parameters);
      }


      /// <summary>
      /// 根據產品編號返回產品視圖實體對象
      /// </summary>
      /// <param name="proid"></param>
      /// <returns></returns>
      public ViewProInfo getProViewByProId(string ProID)
      {
          SqlParameter[] parameters = {
					new SqlParameter("@ProID", SqlDbType.Int,4)
};
          parameters[0].Value = ProID;

          ViewProInfo model = new ViewProInfo();
          DataSet ds = DataBaseHelper.SelectSQLReturnDataSet("View_ProInfo_GetModel",CommandType.StoredProcedure,parameters);
          if (ds.Tables[0].Rows.Count > 0)
          {
              if (ds.Tables[0].Rows[0]["ProID"].ToString() != "")
              {
                  model.ProID = int.Parse(ds.Tables[0].Rows[0]["ProID"].ToString());
              }


              model.ProName = ds.Tables[0].Rows[0]["ProName"].ToString();
              if (ds.Tables[0].Rows[0]["TypeID"].ToString() != "")
              {
                  model.TypeID = int.Parse(ds.Tables[0].Rows[0]["TypeID"].ToString());
              }
              model.TypeName = ds.Tables[0].Rows[0]["TypeName"].ToString();
              if (ds.Tables[0].Rows[0]["CustomerID"].ToString() != "")
              {
                  model.CustomerID = int.Parse(ds.Tables[0].Rows[0]["CustomerID"].ToString());
              }
              model.CustomerName = ds.Tables[0].Rows[0]["CustomerName"].ToString();
              model.ProLogo = ds.Tables[0].Rows[0]["ProLogo"].ToString();
              model.Spec = ds.Tables[0].Rows[0]["Spec"].ToString();
              model.ProFullName = ds.Tables[0].Rows[0]["ProFullName"].ToString();
              model.ConfirmNo = ds.Tables[0].Rows[0]["ConfirmNo"].ToString();
              model.Unit = ds.Tables[0].Rows[0]["Unit"].ToString();
              model.ProSize = ds.Tables[0].Rows[0]["ProSize"].ToString();
              model.Grossweight = ds.Tables[0].Rows[0]["Grossweight"].ToString();
              model.MadeEnterprise = ds.Tables[0].Rows[0]["MadeEnterprise"].ToString();
              if (ds.Tables[0].Rows[0]["Retailprice"].ToString() != "")
              {
                  model.Retailprice = decimal.Parse(ds.Tables[0].Rows[0]["Retailprice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["BidPrice"].ToString() != "")
              {
                  model.BidPrice = decimal.Parse(ds.Tables[0].Rows[0]["BidPrice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["TradePrice"].ToString() != "")
              {
                  model.TradePrice = decimal.Parse(ds.Tables[0].Rows[0]["TradePrice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["AdvicePrice"].ToString() != "")
              {
                  model.AdvicePrice = decimal.Parse(ds.Tables[0].Rows[0]["AdvicePrice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["CountyPrice"].ToString() != "")
              {
                  model.CountyPrice = decimal.Parse(ds.Tables[0].Rows[0]["CountyPrice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["CityPrice"].ToString() != "")
              {
                  model.CityPrice = decimal.Parse(ds.Tables[0].Rows[0]["CityPrice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["ProvincePrice"].ToString() != "")
              {
                  model.ProvincePrice = decimal.Parse(ds.Tables[0].Rows[0]["ProvincePrice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["NetPrice"].ToString() != "")
              {
                  model.NetPrice = decimal.Parse(ds.Tables[0].Rows[0]["NetPrice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["NetVipPrice"].ToString() != "")
              {
                  model.NetVipPrice = decimal.Parse(ds.Tables[0].Rows[0]["NetVipPrice"].ToString());
              }
              if (ds.Tables[0].Rows[0]["NetMemberprice"].ToString() != "")
              {
                  model.NetMemberprice = decimal.Parse(ds.Tables[0].Rows[0]["NetMemberprice"].ToString());
              }
              model.OurCompany = ds.Tables[0].Rows[0]["OurCompany"].ToString();
              if (ds.Tables[0].Rows[0]["ChannelID"].ToString() != "")
              {
                  model.ChannelID = int.Parse(ds.Tables[0].Rows[0]["ChannelID"].ToString());
              }
              model.ChannelName = ds.Tables[0].Rows[0]["ChannelName"].ToString();
              model.Usefullife = ds.Tables[0].Rows[0]["Usefullife"].ToString();
              if (ds.Tables[0].Rows[0]["SubmitTime"].ToString() != "")
              {
                  model.SubmitTime = DateTime.Parse(ds.Tables[0].Rows[0]["SubmitTime"].ToString());
              }
              model.StockMost = ds.Tables[0].Rows[0]["StockMost"].ToString();
              model.StockLess = ds.Tables[0].Rows[0]["StockLess"].ToString();
              model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
              return model;
          }
          else
          {
              return null;
          }
      }

    }

商品類型的業務:

public  class BioProTypeBLL
    {
      /// <summary>
      /// 添加一個產品類型對象
      /// </summary>
      /// <param name="model"></param>
      /// <returns></returns>
      public int ProTypeAdd(BioProType model)
      {
          SqlParameter[] parameters = {				
					new SqlParameter("@ParentTypeID", SqlDbType.Int,4),
					new SqlParameter("@TypeName", SqlDbType.NVarChar,100)};
       
          parameters[0].Value = model.ParentTypeID;
          parameters[1].Value = model.TypeName;

          return DataBaseHelper.ExcuteSqlReturnInt("BioProType_Add", CommandType.StoredProcedure, parameters);
          
      }
      /// <summary>
      /// 產品類型修改
      /// </summary>
      /// <param name="model"></param>
      /// <returns></returns>
      public int ProTypeUpdate(BioProType model)
      {
          SqlParameter[] parameters = {
					new SqlParameter("@TypeID", SqlDbType.Int,4),
					new SqlParameter("@ParentTypeID", SqlDbType.Int,4),
					new SqlParameter("@TypeName", SqlDbType.NVarChar,100)};
          parameters[0].Value = model.TypeID;
          parameters[1].Value = model.ParentTypeID;
          parameters[2].Value = model.TypeName;

          return DataBaseHelper.ExcuteSqlReturnInt("BioProType_Update", CommandType.StoredProcedure, parameters);

      }

      /// <summary>
      /// 根據產品類型編號返回產品類型對象
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      public BioProType getProTypeByTypeID(string id)
      {
         SqlDataReader reader= SqlComm.GetDataReaderByCondition("dbo.BioProType", "*", " TypeID=" + id);
         BioProType type = new BioProType();
         if (reader.Read())
         {
             if (reader["TypeID"] != null)
             {
                 type.TypeID = int.Parse(reader["TypeID"].ToString());
             }

             if (reader["ParentTypeID"] != null)
             {
                 type.ParentTypeID = int.Parse(reader["ParentTypeID"].ToString());
             }
             if (reader["TypeName"] != null)
             {
                 type.TypeName = reader["TypeName"].ToString();
             }
         }
         return type;
      }
    }

商品圖片的BLL:

/// <summary>
       /// 添加一條圖片對象
       /// </summary>
       /// <param name="images"></param>
       /// <returns></returns>
       public int BiotbProImgsAdd(BiotbProImgs images)
       {
           SqlParameter[] parameters = {
					new SqlParameter("@ProID", SqlDbType.Int,4),
					new SqlParameter("@ProImg", SqlDbType.NVarChar,200)};

           parameters[0].Value = images.ProID;
           parameters[1].Value = images.ProImg;

           return DataBaseHelper.ExcuteSqlReturnInt("BiotbProImgs_ADD", CommandType.StoredProcedure, parameters);
       
       }

添加產品類型的頁面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProTypeList.aspx.cs" Inherits="BioErpWeb.PersonList.ProTypeList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function ReturnValue(noteid) {
            if (noteid != NaN || noteid != 0) {
                window.returnValue = noteid;
                window.close();
            } else {
                window.returnValue = 0;
                window.close();
            }
            
       }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TreeView ID="TreeView1" runat="server">
        </asp:TreeView>
    </div>
    </form>
</body>
</html>

選擇的js:

function showProType() {
    var re = showModalDialog("../../PersonList/ProTypeList.aspx", "", "dialogWidth=350px;dialogHeight=400px");
    var obj = window.event.srcElement;
    var td = obj.parentNode;
    var txts = td.getElementsByTagName(‘input‘);
    if (re == null || re == "") {

        if (txts[0].value == "" || txts[0].value == null) {
            txts[0].value = "請選擇";
        }
    }
    else {
        txts[0].value = re;
    }
}

後臺代碼:

  protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              CreateTreeVeiw();
            }

        }

        DataSet ds;
        DataTable dt;

        private void CreateTreeVeiw()
        {

            ds = SqlComm.GetDataByCondition("dbo.BioProType", "TypeID,ParentTypeID,TypeName", "1=1");

            dt = new DataTable();
            dt = ds.Tables[0];
            if (dt.Rows.Count == 0)
            {
                Response.Write("<span style=‘color:red;‘>數據庫中沒有產品類型數據,請直接輸入0即可…</span>");
                return;
            }

            DataView dv = new DataView(dt, "ParentTypeID=0 or ParentTypeID=null", "TypeID", DataViewRowState.CurrentRows);
            //遍歷父節點
            foreach (DataRowView d in dv)
            {
                TreeNode n = new TreeNode(d["TypeName"].ToString(), d["TypeID"].ToString());
                n.ImageToolTip = dt.TableName;
                n.NavigateUrl = "javascript:ReturnValue(" + d["TypeID"].ToString() + ");";
                TreeView1.Nodes.Add(n);
                n.Expanded = false;
                //根據父節點篩選出對應的子節點
                dv = new DataView(dt, " ParentTypeID=‘" + d["TypeID"] + "‘", "TypeID", DataViewRowState.CurrentRows);
                if (dv.Count > 0)
                {
                    CreateSubTreeView(n, dv);

                }
            }

        }

        /// <summary>
        /// 添加子項
        /// </summary>
        /// <param name="n"></param>
        /// <param name="dv"></param>
        private void CreateSubTreeView(TreeNode n, DataView dv)
        {
            foreach (DataRowView d in dv)
            {
                TreeNode cn = new TreeNode(d["TypeName"].ToString(), d["TypeID"].ToString());
                cn.NavigateUrl = "javascript:ReturnValue(" + d["TypeID"].ToString() + ");";
                n.ChildNodes.Add(cn);
                DataView sdv = new DataView(dt, "ParentTypeID=‘" + d["TypeID"] + "‘", "TypeID", DataViewRowState.CurrentRows);
                if (sdv.Count > 0)
                {
                    CreateSubTreeView(cn, sdv);
                }

            }
        }

類型的添加:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProTypeInsert.aspx.cs"
    Inherits="BioErpWeb.WholeSaleSystem.Product.ProTypeInsert" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../Styles/ERPBaseStyle.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/ValidateMessage_ZW.js" type="text/javascript"></script>
    <script src="../../Scripts/validateExtender.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.metadata.js" type="text/javascript"></script>
    <script src="../../JS/ProTypeChoose.js" type="text/javascript"></script>
    <style type="text/css">
        .style1
        {
            height: 22px;
        }
    </style>

    <script type="text/javascript">
        $().ready(function () {
            $("#form1").validate();
          });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="maintable">
            <tr>
                <td colspan="2" class="titlebar">
                    產品類型添加
                </td>
            </tr>
            <tr>
                <td class="style1">
                    類型名稱
                </td>
                <td class="style1">
                    <asp:TextBox ID="txtTypeName" CssClass="{required:true}" runat="server" ></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    所屬大類</td>
                <td class="style1">
                    <asp:TextBox ID="txtSupertTypeID" 
                        CssClass="{required:true, number:true, min:0}" runat="server" 
                        ></asp:TextBox><input type="button" value="選擇" onclick="showProType()"/>
                  
                    <asp:Label ID="Label1" runat="server" ForeColor="Red" Text="(註:如果為0代表頂級父類)"></asp:Label>
                </td>
            </tr>

            <tr>
                <td colspan="2" class="bottomtd">
                    <asp:Button ID="btnSubmit" runat="server" Text="產品類型保存" OnClick="btnSubmit_Click" />
                    <asp:Button ID="btnReturn" runat="server" CausesValidation="false" UseSubmitBehavior="false" Text="返回列表" OnClick="btnReturn_Click" />
                </td>
            </tr>
        </table>
        <br />
    </div>
    </form>
</body>
</html>

添加的代碼:

BioProTypeBLL typebll=new BioProTypeBLL();

            BioProType type = new BioProType();
            type.ParentTypeID = int.Parse(this.txtSupertTypeID.Text.Trim()) ;
            type.TypeName = this.txtTypeName.Text;
            if (typebll.ProTypeAdd(type) != 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "test", "alert(‘添加類型成功‘)", true);
                return;
            }

ERP商品管理業務邏輯封裝(三十一)