/// <summary> /// 数据保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { string strInfo = ""; if (!this.ValidateData(out strInfo)) { strInfo = strInfo.Replace("\"", "'").Replace("\n", ""); this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + strInfo + "');", true); return; } LMaterialData model = new LMaterialData(); LMaterialBB materialBB = new LMaterialBB(); try { if (this.State == "1") { this.SetModel(ref model); model.isrtDt = DateTime.Now.ToString(); model.isrtEmpId = this.currentUser.empId; this.IdValue = materialBB.AddRecord(model); } else if (this.State == "2") { model = materialBB.GetModel(this.IdValue); this.SetModel(ref model); model.updtDt = DateTime.Now.ToString(); model.updtEmpId = this.currentUser.empId; materialBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { materialBB.Dispose(); } Response.Redirect("LMaterialList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false); }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LMaterialData model) { return this.materialDB.ModifyRecord(model); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LMaterialData model) { return this.materialDB.AddRecord(model); }
/// <summary> /// 新增区域 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnNewArea_Click(object sender, EventArgs e) { try { this.SaveStencilDetailViewState();//保存 bool isChecked = false; foreach (GridViewRow gvrow in this.grid.Rows) { CheckBox chkId = (CheckBox)gvrow.FindControl("chkId"); DataRow[] myDataRowArray = null; if (chkId.Checked == true) { isChecked = true; //所选采购订单信息 string materialNo = this.grid.DataKeys[gvrow.RowIndex].Values["materialNo"].ToString(); string lfinanceBillNo = this.grid.DataKeys[gvrow.RowIndex].Values["financeBillNo"].ToString(); string lCustomNo = this.grid.DataKeys[gvrow.RowIndex].Values["customNo"].ToString(); string lmaterialDesc = this.grid.DataKeys[gvrow.RowIndex].Values["materialDesc"].ToString(); string financeBillSort = this.grid.DataKeys[gvrow.RowIndex].Values["financeBillSort"].ToString(); string wareSortNo = this.grid.DataKeys[gvrow.RowIndex].Values["wareSortNo"].ToString(); string strWareSortNm = this.grid.DataKeys[gvrow.RowIndex].Values["wareSortNm"].ToString(); //判断物料是否有剩余 myDataRowArray = this.DtDetail.Select("financeBillNo='" + this.grid.DataKeys[gvrow.RowIndex].Values["financeBillNo"].ToString() + "' and materialNo='" + this.grid.DataKeys[gvrow.RowIndex].Values["materialNo"].ToString() + "'"); if (myDataRowArray.Length > 0) { if (myDataRowArray[0]["arrangeBoxNum_leaving"].ToString() == "" || myDataRowArray[0]["arrangeBoxNum_leaving"].ToString() == "0") { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此物料已经没有剩余!\");", true); return; } } foreach (GridViewRow grow in this.gridDetail.Rows) { CheckBox chkId1 = (CheckBox)grow.FindControl("chkId"); if (chkId1.Checked == true) { string arriveBillNo = this.gridDetail.DataKeys[grow.RowIndex].Values["arriveBillNo"].ToString(); string financeBillNo = this.gridDetail.DataKeys[grow.RowIndex].Values["financeBillNo"].ToString(); string preMaterialNo = this.gridDetail.DataKeys[grow.RowIndex].Values["materialNo"].ToString(); string pindex = this.gridDetail.DataKeys[grow.RowIndex].Values["palletIndex"].ToString(); string pwareSortNo = this.gridDetail.DataKeys[grow.RowIndex].Values["wareSortNo"].ToString(); string strCustomNo = this.gridDetail.DataKeys[grow.RowIndex].Values["customNo"].ToString(); if (strCustomNo != lCustomNo && financeBillNo != lfinanceBillNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"同一托盘只允许放置同一采购订单或同一客户订单物料!\");", true); return; } LMaterialBB materialBB = new LMaterialBB(); try { LMaterialData materialModel = new LMaterialData(); //判断当前选择物料的货位分类 materialModel = materialBB.GetModel(materialNo); if (financeBillSort == "备货" && (materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C") && materialNo != preMaterialNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"放置高位货架托盘只允许放置同一种备货物料!\");", true); return; } else if (financeBillSort == "备货" && (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D" || materialModel.wareSortNo == "E") && pwareSortNo != wareSortNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此托盘只允许放置同一仓库类别的备货物料!\");", true); return; } //判断上一次选择物料的货位分类 materialModel = materialBB.GetModel(preMaterialNo); if (financeBillSort == "备货" && (materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C") && materialNo != preMaterialNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"放置高位货架托盘只允许放置同一种备货物料!\");", true); return; } else if (financeBillSort == "备货" && (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D" || materialModel.wareSortNo == "E") && pwareSortNo != wareSortNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此托盘只允许放置同一仓库类别的备货物料!\");", true); return; } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { materialBB.Dispose(); } //求出最大的托盘序号 int maxnum = 1; DataRow[] drs = DtResult.Select(" isdel=0 and palletIndex=" + pindex, "region"); for (int i = 0; i < drs.Length; i++) { if (Convert.ToInt32(drs[i]["region"]) > maxnum) { break; } maxnum++; } if (maxnum > int.Parse(txtRegionNum.Text.Trim())) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"区域必须小于等于设定的托盘区域!\");", true); return; } //记录添加到临时表 DataRow dr = this.DtResult.NewRow(); dr["wareSortNo"] = wareSortNo; dr["wareSortNm"] = strWareSortNm; dr["rowId"] = Guid.NewGuid().ToString(); dr["isdel"] = "0"; dr["id"] = 0; dr["boxNum"] = 0; dr["hideAmount"] = 0; dr["ischeck"] = false; dr["arrangeBillNo"] = "PT" + this.ArriveBillNo; dr["arriveBillNo"] = arriveBillNo; dr["materialDesc"] = lmaterialDesc; dr["financeBillNo"] = lfinanceBillNo; dr["materialNo"] = materialNo; dr["region"] = maxnum; dr["palletIndex"] = pindex;//托盘序号 dr["customNo"] = lCustomNo;//客户编号 this.DtResult.Rows.Add(dr); } } } } if (isChecked == false) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"请选择采购物料和托盘记录!\");", true); return; } } finally { this.BindDetailTable();//绑定排托明细列表 this.BindGrid();//绑定到货明细列表 } }
/// <summary> /// 自动排托 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAutoArrange_Click(object sender, EventArgs e) { //2015-10-21 董利特修改 //首先用自动排托的功能进行测试 int maxManualRegion = int.Parse(txtRegionNum.Text.Trim()); int maxManualNum = int.Parse(txtMaxNum.Text.Trim()); LMaterialBB materialBB = new LMaterialBB(); try { if (this.DtDetail == null || this.DtDetail.Rows.Count <= 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "AutoArrange", "alert(\"该到货单没有任何明细,无法自动排拖!\");", true); } //判断是否已经生成排托明细 if (this.DtResult.Rows.Count > 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "AutoArrange", "alert(\"该到货单已经生成排托明细,无法自动排拖!\");", true); return; } LMaterialData materialModel = new LMaterialData(); DataView dvArriveDetail = this.DtDetail.DefaultView; dvArriveDetail.Sort = "financeBillSort,wareSortNo,financeBillNo,materialNo";//customNo //遍历所有到货单的所有物料 foreach (DataRow drArriveDetail in dvArriveDetail.ToTable().Rows) { //非标准箱不予排拖 //if (drArriveDetail["isStandardBox"].ToString() == "0" // || drArriveDetail["isStandardBox"].ToString().Trim() == "N" // || drArriveDetail["isStandardBox"].ToString().Trim() == "") //{ // continue; //} if (drArriveDetail["isStandardBox"].ToString().Trim() == "N" || drArriveDetail["isStandardBox"].ToString().Trim() == "") { continue; } int leavingNum = Convert.ToInt32(drArriveDetail["arrangeBoxNum_leaving"]);//到货单明细剩余未排数量 int maxPalletIndex = 0;//最大托盘序号 //int empty = 5;//区域空余数量 int empty = maxManualNum; int maxRegion = 1;//区域 bool isNewPallet = true;//是否需要新托盘 DataView dvResult = null; //采购订单类型 备货 if (drArriveDetail["financeBillSort"].ToString() == "备货") { #region 备货订单排托 materialModel = materialBB.GetModel(drArriveDetail["materialNo"].ToString()); //物料放置高位货架的 if ((materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C")) { #region 物料放置高位货架的,相同物料进行排托 dvResult = this.DtResult.DefaultView; dvResult.Sort = "wareSortNo,materialNo,palletIndex"; dvResult.RowFilter = "isdel=0 and arriveBillNo='" + drArriveDetail["arriveBillNo"] + "' and wareSortNo='" + drArriveDetail["wareSortNo"].ToString() + "'" + " and materialNo='" + drArriveDetail["materialNo"] + "'"; #endregion 物料放置高位货架的,相同物料进行排托 } else if (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D" || materialModel.wareSortNo == "E") { #region 非高位货架 同一区域的排拖 dvResult = this.DtResult.DefaultView; dvResult.Sort = "wareSortNo,palletIndex"; dvResult.RowFilter = "isdel=0 and arriveBillNo='" + drArriveDetail["arriveBillNo"] + "' and wareSortNo='" + drArriveDetail["wareSortNo"].ToString() + "'"; #endregion 非高位货架 同一区域的排拖 } #endregion 备货订单排托 } else { #region 采购订单类型为按单 //找到当前采购订单 同一物料已经排拖的数据 //同一客户的不同采购订单的相同物料可以排在同一托盘 dvResult = this.DtResult.DefaultView; dvResult.Sort = "customNo,materialNo,financeBillNo,palletIndex,region"; dvResult.RowFilter = "isdel=0 and arriveBillNo='" + drArriveDetail["arriveBillNo"] + "' and ((isnull(customNo,'')<>'' and customNo='" + drArriveDetail["customNo"] + "') or (isnull(customNo,'')='' and financeBillNo='" + drArriveDetail["financeBillNo"] + "')) "; #endregion 采购订单类型为按单 } #region 查找有剩余位置的托盘 //找到同种采购订单,同种物料,有剩余位置的托盘 if (dvResult.ToTable() != null && dvResult.ToTable().Rows.Count > 0) { foreach (DataRow dr in dvResult.ToTable().Rows) { //遍历 同采购订单的同物料并且已经排拖的数据 ,找到 最大的托盘号,以及已经排拖的总数量 if (Convert.ToInt32(dr["palletIndex"]) > maxPalletIndex || Convert.ToInt32(dr["region"]) > maxRegion) { //获取当前订单,当前物料的最大托盘号(由于自动排拖,有空余位置的托盘,是最后一个托盘号) maxPalletIndex = Convert.ToInt32(dr["palletIndex"]); maxRegion = Convert.ToInt32(dr["region"]); } } //计算最后一个托盘的空余位置数量 DataRow[] drsLastRegion = this.DtResult.Select("palletIndex='" + maxPalletIndex.ToString() + "' and region='" + maxRegion.ToString() + "'"); if (drsLastRegion.Length > 0 && drsLastRegion[0]["materialNo"] == drArriveDetail["materialNo"]) { //查找到相同物料 // empty = 5 - Convert.ToInt32(drsLastRegion[0]["boxNum"]); empty = maxManualNum - Convert.ToInt32(drsLastRegion[0]["boxNum"]); if (empty > 0) { isNewPallet = false;//不需要新托盘 } } else { if (drsLastRegion.Length > 0 && drsLastRegion[0]["materialNo"] != drArriveDetail["materialNo"]) { maxRegion++; } //if (maxRegion > 8) if (maxRegion > maxManualRegion) { maxPalletIndex = maxPalletIndex + 1; maxRegion = 1; } else { isNewPallet = false;//不需要新托盘 } } } #endregion 查找有剩余位置的托盘 #region 生成排托计划 if (isNewPallet)//需要使用新托盘 { DataView dvMaxPallet = this.DtResult.DefaultView; dvMaxPallet.RowFilter = "isdel=0 "; dvMaxPallet.Sort = "palletIndex"; foreach (DataRow drMaxPallet in dvMaxPallet.ToTable().Rows) { //遍历 同采购订单的同物料并且已经排拖的数据 ,找到 最大的托盘号,以及已经排拖的总数量 if (Convert.ToInt32(drMaxPallet["palletIndex"]) > maxPalletIndex) { //获取 最大托盘号+1为新的托盘 maxPalletIndex = Convert.ToInt32(drMaxPallet["palletIndex"]); } } maxPalletIndex = maxPalletIndex + 1; maxRegion = 1; } int lastNum = leavingNum; do { while (maxRegion <= maxManualRegion && lastNum > 0) { //把之前的托盘不足的补全 DataRow drnew = this.DtResult.NewRow(); drnew["rowId"] = Guid.NewGuid().ToString(); drnew["isdel"] = "0"; drnew["id"] = 0; drnew["boxNum"] = lastNum >= empty ? empty : lastNum;//要补全的托盘,如果剩余不足,数量就等于剩余数量 drnew["hideAmount"] = lastNum >= empty ? empty : lastNum; drArriveDetail["arrangeBoxNum_leaving"] = Convert.ToInt32(drArriveDetail["arrangeBoxNum_leaving"]) - (lastNum >= empty ? empty : lastNum);//采购订单明细扣除相应已经排拖的数量 drArriveDetail["arrangeBoxNum"] = Convert.ToInt32(drArriveDetail["arrangeBoxNum"]) + (lastNum >= empty ? empty : lastNum);//采购订单明细扣除相应已经排拖的数量 drnew["ischeck"] = false; drnew["arrangeBillNo"] = "PT" + this.ArriveBillNo; drnew["arriveBillNo"] = drArriveDetail["arriveBillNo"]; drnew["materialDesc"] = drArriveDetail["materialDesc"]; drnew["financeBillNo"] = drArriveDetail["financeBillNo"]; drnew["materialNo"] = drArriveDetail["materialNo"]; drnew["wareSortNo"] = drArriveDetail["wareSortNo"]; drnew["wareSortNm"] = drArriveDetail["wareSortNm"]; drnew["region"] = maxRegion; drnew["palletIndex"] = maxPalletIndex;//托盘序号 drnew["customNo"] = drArriveDetail["customNo"];//客户编号 this.DtResult.Rows.Add(drnew); maxRegion = maxRegion + 1; lastNum = lastNum - empty; //empty = 5; empty = maxManualNum; } maxPalletIndex += 1; maxRegion = 1; } while (lastNum > 0); #endregion 生成排托计划 } this.BindDetailTable();//绑定排托明细列表 this.SaveStencilDetailViewState();//保存 this.BindGrid();//绑定到货明细列表 } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { materialBB.Dispose(); } }
/// <summary> /// 实体类赋值 /// </summary> /// <param name="model">实体类实例</param> private void SetModel(ref LMaterialData model) { model.systemWeight = Convert.ToDouble(this.tbSystemWeight.Text.Trim()); model.weightDiffWaring = Convert.ToDouble(this.tbWeightDiffWaring.Text.Trim()); model.wareSortNo = this.ddlWareSort.SelectedValue; }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LMaterialData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into LMaterial("); strSql.Append(@"materialNo,materialDesc,materialFrgnDesc,materialGroup,invntItem,buyUnitMsr,numInBuy,salUnitMsr,numInSale,isStocked, isRoutinePackage,isStandardBox,manBtchNum,validFor,validFrom,validTo,frozenFor,frozenFrom,frozenTo,invntryUom, U_CNSize,U_ENSize,U_StanWiht,U_PullStan,U_DrawHlink,U_LablHlink,U_CCVOHlink,U_UintQty,U_BoxQty,U_CodeNo, U_Material,U_BoxSize,materialNm_CH,materialNm_EN,U_PackWay,wareSortNo,DEType,weightDiffWaring,systemWeight,isrtEmpId, isrtDt,updtEmpId,updtDt)"); strSql.Append(" values ("); strSql.Append(@"@materialNo,@materialDesc,@materialFrgnDesc,@materialGroup,@invntItem,@buyUnitMsr,@numInBuy,@salUnitMsr,@numInSale,@isStocked, @isRoutinePackage,@isStandardBox,@manBtchNum,@validFor,@validFrom,@validTo,@frozenFor,@frozenFrom,@frozenTo,@invntryUom, @U_CNSize,@U_ENSize,@U_StanWiht,@U_PullStan,@U_DrawHlink,@U_LablHlink,@U_CCVOHlink,@U_UintQty,@U_BoxQty,@U_CodeNo, @U_Material,@U_BoxSize,@materialNm_CH,@materialNm_EN,@U_PackWay,@wareSortNo,@DEType,@weightDiffWaring,@systemWeight,@isrtEmpId, @isrtDt,@updtEmpId,@updtDt)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@materialNo", SqlDbType.NVarChar,20), new SqlParameter("@materialDesc", SqlDbType.NVarChar,100), new SqlParameter("@materialFrgnDesc", SqlDbType.NVarChar,100), new SqlParameter("@materialGroup", SqlDbType.SmallInt), new SqlParameter("@invntItem", SqlDbType.Char,1), new SqlParameter("@buyUnitMsr", SqlDbType.NVarChar,100), new SqlParameter("@numInBuy", SqlDbType.Decimal,9), new SqlParameter("@salUnitMsr", SqlDbType.NVarChar,100), new SqlParameter("@numInSale", SqlDbType.Decimal,9), new SqlParameter("@isStocked", SqlDbType.Char,1), new SqlParameter("@isRoutinePackage", SqlDbType.Char,1), new SqlParameter("@isStandardBox", SqlDbType.Char,1), new SqlParameter("@manBtchNum", SqlDbType.Char,1), new SqlParameter("@validFor", SqlDbType.Char,1), new SqlParameter("@validFrom", SqlDbType.DateTime), new SqlParameter("@validTo", SqlDbType.DateTime), new SqlParameter("@frozenFor", SqlDbType.Char,1), new SqlParameter("@frozenFrom", SqlDbType.DateTime), new SqlParameter("@frozenTo", SqlDbType.DateTime), new SqlParameter("@invntryUom", SqlDbType.NVarChar,100), new SqlParameter("@U_CNSize", SqlDbType.NVarChar,50), new SqlParameter("@U_ENSize", SqlDbType.NVarChar,50), new SqlParameter("@U_StanWiht", SqlDbType.Decimal,9), new SqlParameter("@U_PullStan", SqlDbType.NVarChar,50), new SqlParameter("@U_DrawHlink", SqlDbType.NText), new SqlParameter("@U_LablHlink", SqlDbType.NText), new SqlParameter("@U_CCVOHlink", SqlDbType.NText), new SqlParameter("@U_UintQty", SqlDbType.Decimal,9), new SqlParameter("@U_BoxQty", SqlDbType.Decimal,9), new SqlParameter("@U_CodeNo", SqlDbType.NVarChar,20), new SqlParameter("@U_Material", SqlDbType.VarChar,20), new SqlParameter("@U_BoxSize", SqlDbType.NVarChar,50), new SqlParameter("@materialNm_CH", SqlDbType.NVarChar,100), new SqlParameter("@materialNm_EN", SqlDbType.VarChar,100), new SqlParameter("@U_PackWay", SqlDbType.NVarChar,20), new SqlParameter("@wareSortNo", SqlDbType.VarChar,20), new SqlParameter("@DEType", SqlDbType.Bit), new SqlParameter("@weightDiffWaring", SqlDbType.Float), new SqlParameter("@systemWeight", SqlDbType.Float), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime) }; parameters[0].Value = model.materialNo; parameters[1].Value = model.materialDesc; parameters[2].Value = model.materialFrgnDesc; parameters[3].Value = model.materialGroup; parameters[4].Value = model.invntItem; parameters[5].Value = model.buyUnitMsr; parameters[6].Value = model.numInBuy; parameters[7].Value = model.salUnitMsr; parameters[8].Value = model.numInSale; parameters[9].Value = model.isStocked; parameters[10].Value = model.isRoutinePackage; parameters[11].Value = model.isStandardBox; parameters[12].Value = model.manBtchNum; parameters[13].Value = model.validFor; parameters[14].Value = model.validFrom == string.Empty ? null : model.validFrom; parameters[15].Value = model.validTo == string.Empty ? null : model.validTo; parameters[16].Value = model.frozenFor; parameters[17].Value = model.frozenFrom == string.Empty ? null : model.frozenFrom; parameters[18].Value = model.frozenTo == string.Empty ? null : model.frozenTo; parameters[19].Value = model.invntryUom; parameters[20].Value = model.U_CNSize; parameters[21].Value = model.U_ENSize; parameters[22].Value = model.U_StanWiht; parameters[23].Value = model.U_PullStan; parameters[24].Value = model.U_DrawHlink; parameters[25].Value = model.U_LablHlink; parameters[26].Value = model.U_CCVOHlink; parameters[27].Value = model.U_UintQty; parameters[28].Value = model.U_BoxQty; parameters[29].Value = model.U_CodeNo; parameters[30].Value = model.U_Material; parameters[31].Value = model.U_BoxSize; parameters[32].Value = model.materialNm_CH; parameters[33].Value = model.materialNm_EN; parameters[34].Value = model.U_PackWay; parameters[35].Value = model.wareSortNo; parameters[36].Value = model.DEType; parameters[37].Value = model.weightDiffWaring; parameters[38].Value = model.systemWeight; parameters[39].Value = model.isrtEmpId; parameters[40].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[41].Value = model.updtEmpId; parameters[42].Value = model.updtDt == string.Empty ? null : model.updtDt; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
//***************************************************************************** //do it later do it later do it later //***************************************************************************** /// <summary> /// 得到一个model /// </summary> /// <param name="id">主键值</param> /// <returns>model</returns> public LMaterialData GetModel(string materialNo) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select id,materialNo,materialDesc,materialFrgnDesc,materialGroup,invntItem,buyUnitMsr,numInBuy,salUnitMsr,numInSale,isStocked,isRoutinePackage, isStandardBox,manBtchNum,validFor,validFrom,validTo,frozenFor,frozenFrom,frozenTo,invntryUom,U_CNSize, U_ENSize,U_StanWiht,U_PullStan,U_DrawHlink,U_LablHlink,U_CCVOHlink,U_UintQty,U_BoxQty,U_CodeNo,U_BoxSize, materialNm_CH,materialNm_EN,U_PackWay,wareSortNo,DEType,weightDiffWaring,systemWeight,isrtEmpId,isrtDt,updtEmpId,updtDt,U_Material from LMaterial"); strSql.Append(" where materialNo = @materialNo "); SqlParameter[] parameters = { new SqlParameter("@materialNo", SqlDbType.VarChar,100) }; parameters[0].Value = materialNo; LMaterialData model = new LMaterialData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["materialNo"] != DBNull.Value) { model.materialNo = Convert.ToString(row["materialNo"]); } if (row["materialDesc"] != DBNull.Value) { model.materialDesc = Convert.ToString(row["materialDesc"]); } if (row["materialFrgnDesc"] != DBNull.Value) { model.materialFrgnDesc = Convert.ToString(row["materialFrgnDesc"]); } if (row["materialGroup"] != DBNull.Value) { model.materialGroup = Convert.ToInt16(row["materialGroup"]); } if (row["invntItem"] != DBNull.Value) { model.invntItem = Convert.ToString(row["invntItem"]); } if (row["buyUnitMsr"] != DBNull.Value) { model.buyUnitMsr = Convert.ToString(row["buyUnitMsr"]); } if (row["numInBuy"] != DBNull.Value) { model.numInBuy = Convert.ToDecimal(row["numInBuy"]); } if (row["salUnitMsr"] != DBNull.Value) { model.salUnitMsr = Convert.ToString(row["salUnitMsr"]); } if (row["numInSale"] != DBNull.Value) { model.numInSale = Convert.ToDecimal(row["numInSale"]); } if (row["isStocked"] != DBNull.Value) { model.isStocked = Convert.ToString(row["isStocked"]); } if (row["isRoutinePackage"] != DBNull.Value) { model.isRoutinePackage = Convert.ToString(row["isRoutinePackage"]); } if (row["isStandardBox"] != DBNull.Value) { model.isStandardBox = Convert.ToString(row["isStandardBox"]); } if (row["manBtchNum"] != DBNull.Value) { model.manBtchNum = Convert.ToString(row["manBtchNum"]); } if (row["validFor"] != DBNull.Value) { model.validFor = Convert.ToString(row["validFor"]); } if (row["validFrom"] != DBNull.Value) { model.validFrom = Convert.ToString(row["validFrom"]); } if (row["validTo"] != DBNull.Value) { model.validTo = Convert.ToString(row["validTo"]); } if (row["frozenFor"] != DBNull.Value) { model.frozenFor = Convert.ToString(row["frozenFor"]); } if (row["frozenFrom"] != DBNull.Value) { model.frozenFrom = Convert.ToString(row["frozenFrom"]); } if (row["frozenTo"] != DBNull.Value) { model.frozenTo = Convert.ToString(row["frozenTo"]); } if (row["invntryUom"] != DBNull.Value) { model.invntryUom = Convert.ToString(row["invntryUom"]); } if (row["U_CNSize"] != DBNull.Value) { model.U_CNSize = Convert.ToString(row["U_CNSize"]); } if (row["U_ENSize"] != DBNull.Value) { model.U_ENSize = Convert.ToString(row["U_ENSize"]); } if (row["U_StanWiht"] != DBNull.Value) { model.U_StanWiht = Convert.ToDecimal(row["U_StanWiht"]); } if (row["U_PullStan"] != DBNull.Value) { model.U_PullStan = Convert.ToString(row["U_PullStan"]); } if (row["U_DrawHlink"] != DBNull.Value) { model.U_DrawHlink = Convert.ToString(row["U_DrawHlink"]); } if (row["U_LablHlink"] != DBNull.Value) { model.U_LablHlink = Convert.ToString(row["U_LablHlink"]); } if (row["U_CCVOHlink"] != DBNull.Value) { model.U_CCVOHlink = Convert.ToString(row["U_CCVOHlink"]); } if (row["U_UintQty"] != DBNull.Value) { model.U_UintQty = Convert.ToDecimal(row["U_UintQty"]); } if (row["U_BoxQty"] != DBNull.Value) { model.U_BoxQty = Convert.ToDecimal(row["U_BoxQty"]); } if (row["U_CodeNo"] != DBNull.Value) { model.U_CodeNo = Convert.ToString(row["U_CodeNo"]); } if (row["U_BoxSize"] != DBNull.Value) { model.U_BoxSize = Convert.ToString(row["U_BoxSize"]); } if (row["materialNm_CH"] != DBNull.Value) { model.materialNm_CH = Convert.ToString(row["materialNm_CH"]); } if (row["materialNm_EN"] != DBNull.Value) { model.materialNm_EN = Convert.ToString(row["materialNm_EN"]); } if (row["U_PackWay"] != DBNull.Value) { model.U_PackWay = Convert.ToString(row["U_PackWay"]); } if (row["wareSortNo"] != DBNull.Value) { model.wareSortNo = Convert.ToString(row["wareSortNo"]); } if (row["DEType"] != DBNull.Value) { model.DEType = Convert.ToBoolean(row["DEType"]); } if (row["weightDiffWaring"] != DBNull.Value) { model.weightDiffWaring = Convert.ToDouble(row["weightDiffWaring"]); } if (row["systemWeight"] != DBNull.Value) { model.systemWeight = Convert.ToDouble(row["systemWeight"]); } if (row["isrtEmpId"] != DBNull.Value) { model.isrtEmpId = Convert.ToInt32(row["isrtEmpId"]); } if (row["isrtDt"] != DBNull.Value) { model.isrtDt = Convert.ToString(row["isrtDt"]); } if (row["updtEmpId"] != DBNull.Value) { model.updtEmpId = Convert.ToInt32(row["updtEmpId"]); } if (row["updtDt"] != DBNull.Value) { model.updtDt = Convert.ToString(row["updtDt"]); } if (row["U_Material"] != DBNull.Value) { model.U_Material = Convert.ToString(row["U_Material"]); } return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LMaterialData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update LMaterial set "); strSql.Append("materialNo=@materialNo,"); strSql.Append("materialDesc=@materialDesc,"); strSql.Append("materialFrgnDesc=@materialFrgnDesc,"); strSql.Append("materialGroup=@materialGroup,"); strSql.Append("invntItem=@invntItem,"); strSql.Append("buyUnitMsr=@buyUnitMsr,"); strSql.Append("numInBuy=@numInBuy,"); strSql.Append("salUnitMsr=@salUnitMsr,"); strSql.Append("numInSale=@numInSale,"); strSql.Append("isStocked=@isStocked,"); strSql.Append("isRoutinePackage=@isRoutinePackage,"); strSql.Append("isStandardBox=@isStandardBox,"); strSql.Append("manBtchNum=@manBtchNum,"); strSql.Append("validFor=@validFor,"); strSql.Append("validFrom=@validFrom,"); strSql.Append("validTo=@validTo,"); strSql.Append("frozenFor=@frozenFor,"); strSql.Append("frozenFrom=@frozenFrom,"); strSql.Append("frozenTo=@frozenTo,"); strSql.Append("invntryUom=@invntryUom,"); strSql.Append("U_CNSize=@U_CNSize,"); strSql.Append("U_ENSize=@U_ENSize,"); strSql.Append("U_StanWiht=@U_StanWiht,"); strSql.Append("U_PullStan=@U_PullStan,"); strSql.Append("U_DrawHlink=@U_DrawHlink,"); strSql.Append("U_LablHlink=@U_LablHlink,"); strSql.Append("U_CCVOHlink=@U_CCVOHlink,"); strSql.Append("U_UintQty=@U_UintQty,"); strSql.Append("U_BoxQty=@U_BoxQty,"); strSql.Append("U_CodeNo=@U_CodeNo,"); strSql.Append("U_Material=@U_Material,"); strSql.Append("U_BoxSize=@U_BoxSize,"); strSql.Append("materialNm_CH=@materialNm_CH,"); strSql.Append("materialNm_EN=@materialNm_EN,"); strSql.Append("U_PackWay=@U_PackWay,"); strSql.Append("wareSortNo=@wareSortNo,"); strSql.Append("DEType=@DEType,"); strSql.Append("weightDiffWaring=@weightDiffWaring,"); strSql.Append("systemWeight=@systemWeight,"); strSql.Append("isrtEmpId=@isrtEmpId,"); strSql.Append("isrtDt=@isrtDt,"); strSql.Append("updtEmpId=@updtEmpId,"); strSql.Append("updtDt=@updtDt"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@materialNo", SqlDbType.NVarChar,20), new SqlParameter("@materialDesc", SqlDbType.NVarChar,100), new SqlParameter("@materialFrgnDesc", SqlDbType.NVarChar,100), new SqlParameter("@materialGroup", SqlDbType.SmallInt), new SqlParameter("@invntItem", SqlDbType.Char,1), new SqlParameter("@buyUnitMsr", SqlDbType.NVarChar,100), new SqlParameter("@numInBuy", SqlDbType.Decimal,9), new SqlParameter("@salUnitMsr", SqlDbType.NVarChar,100), new SqlParameter("@numInSale", SqlDbType.Decimal,9), new SqlParameter("@isStocked", SqlDbType.Char,1), new SqlParameter("@isRoutinePackage", SqlDbType.Char,1), new SqlParameter("@isStandardBox", SqlDbType.Char,1), new SqlParameter("@manBtchNum", SqlDbType.Char,1), new SqlParameter("@validFor", SqlDbType.Char,1), new SqlParameter("@validFrom", SqlDbType.DateTime), new SqlParameter("@validTo", SqlDbType.DateTime), new SqlParameter("@frozenFor", SqlDbType.Char,1), new SqlParameter("@frozenFrom", SqlDbType.DateTime), new SqlParameter("@frozenTo", SqlDbType.DateTime), new SqlParameter("@invntryUom", SqlDbType.NVarChar,100), new SqlParameter("@U_CNSize", SqlDbType.NVarChar,50), new SqlParameter("@U_ENSize", SqlDbType.NVarChar,50), new SqlParameter("@U_StanWiht", SqlDbType.Decimal,9), new SqlParameter("@U_PullStan", SqlDbType.NVarChar,50), new SqlParameter("@U_DrawHlink", SqlDbType.NText), new SqlParameter("@U_LablHlink", SqlDbType.NText), new SqlParameter("@U_CCVOHlink", SqlDbType.NText), new SqlParameter("@U_UintQty", SqlDbType.Decimal,9), new SqlParameter("@U_BoxQty", SqlDbType.Decimal,9), new SqlParameter("@U_CodeNo", SqlDbType.NVarChar,20), new SqlParameter("@U_Material", SqlDbType.VarChar,20), new SqlParameter("@U_BoxSize", SqlDbType.NVarChar,50), new SqlParameter("@materialNm_CH", SqlDbType.NVarChar,100), new SqlParameter("@materialNm_EN", SqlDbType.VarChar,100), new SqlParameter("@U_PackWay", SqlDbType.NVarChar,20), new SqlParameter("@wareSortNo", SqlDbType.VarChar,20), new SqlParameter("@DEType", SqlDbType.Bit), new SqlParameter("@weightDiffWaring", SqlDbType.Float), new SqlParameter("@systemWeight", SqlDbType.Float), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.materialNo; parameters[2].Value = model.materialDesc; parameters[3].Value = model.materialFrgnDesc; parameters[4].Value = model.materialGroup; parameters[5].Value = model.invntItem; parameters[6].Value = model.buyUnitMsr; parameters[7].Value = model.numInBuy; parameters[8].Value = model.salUnitMsr; parameters[9].Value = model.numInSale; parameters[10].Value = model.isStocked; parameters[11].Value = model.isRoutinePackage; parameters[12].Value = model.isStandardBox; parameters[13].Value = model.manBtchNum; parameters[14].Value = model.validFor; parameters[15].Value = model.validFrom == string.Empty ? null : model.validFrom; parameters[16].Value = model.validTo == string.Empty ? null : model.validTo; parameters[17].Value = model.frozenFor; parameters[18].Value = model.frozenFrom == string.Empty ? null : model.frozenFrom; parameters[19].Value = model.frozenTo == string.Empty ? null : model.frozenTo; parameters[20].Value = model.invntryUom; parameters[21].Value = model.U_CNSize; parameters[22].Value = model.U_ENSize; parameters[23].Value = model.U_StanWiht; parameters[24].Value = model.U_PullStan; parameters[25].Value = model.U_DrawHlink; parameters[26].Value = model.U_LablHlink; parameters[27].Value = model.U_CCVOHlink; parameters[28].Value = model.U_UintQty; parameters[29].Value = model.U_BoxQty; parameters[30].Value = model.U_CodeNo; parameters[31].Value = model.U_Material; parameters[32].Value = model.U_BoxSize; parameters[33].Value = model.materialNm_CH; parameters[34].Value = model.materialNm_EN; parameters[35].Value = model.U_PackWay; parameters[36].Value = model.wareSortNo; parameters[37].Value = model.DEType; parameters[38].Value = model.weightDiffWaring; parameters[39].Value = model.systemWeight; parameters[40].Value = model.isrtEmpId; parameters[41].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[42].Value = model.updtEmpId; parameters[43].Value = model.updtDt == string.Empty ? null : model.updtDt; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }