/// <summary> /// 更新数据,数据必须先初始化进入所有表 /// </summary> /// <param name="rfqId"></param> /// <param name="dicAllTable"></param> /// <param name="fields"></param> /// <returns></returns> public static bool Update(ref int rfqId, FieldInfoCollecton fields) { string uid = BI.SGP.BLL.Utils.AccessControl.CurrentLogonUser.Uid; string internalNumber = string.Empty; string extNumber = string.Empty; SGP.BLL.DataModels.FieldInfo fiNumber = fields.Find(t => string.Compare(t.FieldName, "Number", true) == 0); if (fiNumber != null) internalNumber = string.Format("{0}", fiNumber.DataValue); SGP.BLL.DataModels.FieldInfo fiExtNumber = fields.Find(t => string.Compare(t.FieldName, "ExtNumber", true) == 0); if (fiExtNumber != null) extNumber = string.Format("{0}", fiExtNumber.DataValue); if (string.IsNullOrEmpty(internalNumber)) //如果没有内部号码,则根据外部号码,BUILDING等合成内部号码 { internalNumber = PrepareInternalNumber(fields, out extNumber); } if (fiNumber != null) fiNumber.DataValue = internalNumber; RFQDetail detail = null; if (string.IsNullOrEmpty(internalNumber) == false) { //查找当前记录 detail = GetDetailByInternalNumber(internalNumber); if (detail != null) { rfqId = detail.RFQID; extNumber = detail.ExtNumber; if (fiExtNumber != null) fiExtNumber.DataValue = extNumber; } //在有外部号码的情况下,查找数据不存在,则查找最大的一条外部号码对应的数据 if (detail == null) { detail = GetLastDetailByExtNumber(extNumber); if (detail != null) { rfqId = detail.RFQID; } } } //当前记录不存在,但是内部号码存在的情况,先找到外部号码,然后尝试获取该外部号码对应的一条数据 if (rfqId <= 0 && string.IsNullOrEmpty(internalNumber) == false && detail == null) { if (internalNumber.IndexOf('-') > 0) { string[] ary = internalNumber.Split('-'); if (ary.Length >= 2) { extNumber = string.Format("{0}-{1}", ary[0], ary[1]); detail = GetLastDetailByExtNumber(extNumber); if (detail != null) { rfqId = detail.RFQID; if (fiExtNumber != null) fiExtNumber.DataValue = extNumber; } } } } if (rfqId <= 0)//新数据,则创建数据 { rfqId = CreateNewRFQID(uid, out internalNumber); extNumber = internalNumber; if (fiNumber != null) fiNumber.DataValue = internalNumber; if (fiExtNumber != null) fiExtNumber.DataValue = internalNumber; } if (detail != null)// 如果在有老数据存在的情况下,判断Building是否有修改,如果有需要一条复制数据 { extNumber = detail.ExtNumber; string revOld = detail.InternalRevisionNumber; string buildingOld = detail.Building; string buildingNew = string.Empty; string revNew = string.Empty; if (fields["Building"] != null) buildingNew = string.Format("{0}", fields["Building"].DataValue); if (fields["InternalRevisionNumber"] != null) revNew = string.Format("{0}", fields["InternalRevisionNumber"].DataValue); //创建新数据 string newNumber = string.Empty; rfqId = CreateNewRFQID4BuildingChange(rfqId, detail, buildingNew, revNew, uid, out newNumber); if (fiNumber != null) fiNumber.DataValue = newNumber; } if (rfqId > 0) { return UpdateData(rfqId, fields); } return false; }
private static string PrepareInternalNumber(FieldInfoCollecton fields, out string extNumber) { string internalNumber = string.Empty; extNumber = string.Empty; SGP.BLL.DataModels.FieldInfo fiNumber = fields.Find(t => string.Compare(t.FieldName, "Number", true) == 0); if (fiNumber != null) internalNumber = string.Format("{0}", fiNumber.DataValue); SGP.BLL.DataModels.FieldInfo fiExtNumber = fields.Find(t => string.Compare(t.FieldName, "ExtNumber", true) == 0); if (fiExtNumber != null) extNumber = string.Format("{0}", fiExtNumber.DataValue); //如果内部编号为空,但是外部编号不为空,则合成外部编号 if (string.IsNullOrEmpty(internalNumber)) { if (string.IsNullOrEmpty(extNumber) == false) { string rev = string.Empty; string building = string.Empty; SGP.BLL.DataModels.FieldInfo fiRev = fields.Find(t => string.Compare(t.FieldName, "InternalRevisionNumber", true) == 0); SGP.BLL.DataModels.FieldInfo fiBuilding = fields.Find(t => string.Compare(t.FieldName, "Building", true) == 0); if (fiRev != null) rev = string.Format("{0}", fiRev.DataValue); if (fiBuilding != null) building = string.Format("{0}", fiBuilding.DataValue); if (string.IsNullOrEmpty(rev)) rev = "01"; rev = rev.PadLeft(2, '0'); if (string.IsNullOrEmpty(building)) { internalNumber = extNumber; } else { internalNumber = string.Format("{0}-{1}{2}", extNumber, rev, building); } } } return internalNumber; }