Example #1
0
        /// <summary>
        /// CustMixprop表数据导入到ConsMixprop表
        /// </summary>
        /// <param name="sid">CustMixprop表主键ID</param>
        /// <returns></returns>
        public bool CU2CO(string sid, string did)
        {
            using (IGenericTransaction tx = this.m_UnitOfWork.BeginTransaction())
            {
                try
                {
                    CustMixprop            obj    = this.m_UnitOfWork.GetRepositoryBase <CustMixprop>().Get(sid);
                    IConsMixpropRepository m_cons = this.m_UnitOfWork.ConsMixpropRepository;
                    IList <ProductLine>    plList = this.m_UnitOfWork.GetRepositoryBase <ProductLine>()
                                                    .Query()
                                                    .Where(m => m.IsUsed)
                                                    .ToList();
                    ConsMixprop newobj = new ConsMixprop();
                    foreach (ProductLine pl in plList)
                    {
                        ConsMixprop tempobj = new ConsMixprop();
                        if (did.Length > 0)
                        {
                            tempobj.ID = did;
                        }
                        tempobj.ConStrength   = obj.ConStrength;
                        tempobj.FormulaID     = obj.ID;
                        tempobj.IsSlurry      = obj.CementType == "混凝土" ? false : true;
                        tempobj.ImpGrade      = obj.ImpGrade;
                        tempobj.SCRate        = obj.SCRate;
                        tempobj.ProductLineID = pl.ID;

                        newobj = m_cons.Add(tempobj);

                        IList <CustMixpropItem> list = obj.CustMixpropItems;
                        foreach (CustMixpropItem item in list)
                        {
                            foreach (SiloProductLine sp in pl.SiloProductLines)
                            {
                                ConsMixpropItem temp = new ConsMixpropItem();
                                temp.ConsMixprop   = tempobj;
                                temp.ConsMixpropID = tempobj.ID;
                                if (sp.Silo.StuffInfo.StuffType.ID == item.StuffInfo.StuffType.ID)
                                {
                                    temp.Amount = (decimal)item.Amount * (decimal)sp.Rate;
                                    temp.Silo   = sp.Silo;
                                    temp.SiloID = sp.Silo.ID;
                                    this.m_UnitOfWork.GetRepositoryBase <ConsMixpropItem>().Add(temp);
                                }
                            }
                        }
                    }
                    tx.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    tx.Rollback();
                    logger.Error(ex.Message);
                    throw;
                }
            }
        }
Example #2
0
        /// <summary>
        /// 保存横向与纵向配比
        /// </summary>
        /// <param name="cm"></param>
        /// <param name="updateKeys"></param>
        public IList <string> UpdatePrimaryAndItems(ConsMixprop cm, NameValueCollection updateKeys)
        {
            using (var tx = this.m_UnitOfWork.BeginTransaction()) {
                try
                {
                    IList <string> errorList      = new List <string>();
                    string         _ConsMixpropID = cm.ID;
                    //先更新主表,此时synstatus为0表示修改状态
                    this.Update(cm, updateKeys);
                    //获取需要更新的子表
                    cm = this.Get(cm.ID);
                    IList <SiloProductLine> siloProductLines = this.m_UnitOfWork.GetRepositoryBase <SiloProductLine>().Query().Where(m => m.ProductLineID == cm.ProductLineID).ToList();
                    var  updateKeysOrderList = updateKeys.AllKeys.ToList();
                    Type tp = cm.GetType();
                    Dictionary <int, decimal> orderList = new Dictionary <int, decimal>();
                    string startWith = "S";
                    string endWith   = "_wet";
                    foreach (string item in updateKeysOrderList)
                    {
                        if (item.TrimStart().StartsWith(startWith) && item.TrimEnd().EndsWith(endWith))
                        {
                            Dictionary <int, decimal> orderAndValDic = new Dictionary <int, decimal>();
                            //取得orderNum
                            Regex rg    = new Regex("(?<=(" + startWith + "))[.\\s\\S]*?(?=(" + endWith + "))", RegexOptions.Multiline | RegexOptions.Singleline);
                            int   order = Convert.ToInt32(rg.Match(item).Value);
                            //取得orderNum对应的用量
                            var val = tp.GetProperty(string.Format("S{0}_wet", order).ToString()).GetValue(cm, null);
                            orderList.Add(order, Convert.ToDecimal(val));
                            //orderList.Add(orderAndValDic);
                        }
                    }
                    //根据orderNum取得需要更新的siloID
                    Dictionary <string, decimal> needToUpdateSiloIdList = new Dictionary <string, decimal>();
                    foreach (SiloProductLine sp in siloProductLines)
                    {
                        if (orderList.ContainsKey(sp.OrderNum))
                        {
                            string siloId = sp.SiloID;
                            needToUpdateSiloIdList.Add(siloId, orderList[sp.OrderNum]);
                        }
                    }

                    //开始更新子表
                    foreach (KeyValuePair <string, decimal> kvp in needToUpdateSiloIdList)
                    {
                        ConsMixpropItem cmi = this.m_UnitOfWork.ConsMixpropItemRepository.Query().Where(c => c.ConsMixpropID == _ConsMixpropID && c.SiloID == kvp.Key).FirstOrDefault();
                        cmi.Amount = kvp.Value;
                        this.m_UnitOfWork.ConsMixpropItemRepository.Update(cmi, null);
                    }
                    //检查容重与水泥、水的用量
                    IConsMixpropItemRepository IConItems = this.m_UnitOfWork.ConsMixpropItemRepository;
                    IList <ConsMixpropItem>    citems    = IConItems.Query().Where(m => m.ConsMixpropID == cm.ID).ToList();
                    decimal totolWeight = 0;
                    foreach (ConsMixpropItem citem in citems)
                    {
                        totolWeight = totolWeight + citem.Amount;
                    }
                    SysConfigService configService = new SysConfigService(this.m_UnitOfWork);
                    SysConfig        config        = configService.GetSysConfig(SysConfigEnum.IsAllowConsMixpropLimit);
                    if (!cm.IsSlurry)
                    {
                        SysConfig configFormulaRZMax = configService.GetSysConfig(SysConfigEnum.FormulaRZMax);
                        SysConfig configFormulaRZMin = configService.GetSysConfig(SysConfigEnum.FormulaRZMin);
                        decimal   dFormulaRZMax      = decimal.Parse(configFormulaRZMax.ConfigValue);
                        decimal   dFormulaRZMin      = decimal.Parse(configFormulaRZMin.ConfigValue);
                        decimal   weight             = cm.Weight ?? 0;
                        if (config != null && bool.Parse(config.ConfigValue) && cm.ProduceTask.CementType == Model.Enums.CementType.CommonCement)
                        {
                            if (totolWeight > dFormulaRZMax || totolWeight < dFormulaRZMin)
                            {
                                errorList.Add("施工配比号[" + cm.ID + "]" + "&nbsp;&nbsp;超出混凝土配比容重范围");
                                tx.Rollback();
                                return(errorList);
                                //throw new Exception("混凝土配比超出容重范围");
                            }
                            string measureError = CheckMesureScale(cm.TaskID, cm.ProductLineID, 0, 0, true, false);
                            if (!string.IsNullOrEmpty(measureError))
                            {
                                errorList.Add(measureError);
                                tx.Rollback();
                                return(errorList);
                                //throw new Exception(measureError);
                            }
                        }
                    }
                    else
                    {
                        if (config != null && bool.Parse(config.ConfigValue) && cm.ProduceTask.CementType == Model.Enums.CementType.CommonCement)
                        {
                            string measureError = CheckMesureScale(cm.TaskID, cm.ProductLineID, 0, 0, false, true);
                            if (!string.IsNullOrEmpty(measureError))
                            {
                                errorList.Add(measureError);
                                tx.Rollback();
                                return(errorList);
                            }
                        }
                    }
                    cm.SynStatus = 1;      //主表与子表修改完毕后将SynStatus设为1,准备同步与发送搅拌楼
                    base.Update(cm, null);
                    if (cm.SynStatus == 1) //发送配比至搅拌楼(12版楼站)
                    {
                        /*//直连:通知控制系统修改配比
                         * by:Sky 2013/3/17
                         *****************************************************************************/
                        IList <ConsMixpropItem> cmItems = this.m_UnitOfWork.GetRepositoryBase <ConsMixpropItem>().All("ConsMixpropID='" + cm.ID + "'", "ID", true);
                        ResultInfo result = controlSystem.UpdateConsMixprop(cm, cmItems);
                        if (!result.Result)       //配比没有发送成功
                        {
                            errorList.Add(result.Message);
                            tx.Rollback();
                            return(errorList);
                            //throw new Exception(result.Message);
                        }
                    }
                    tx.Commit();
                    return(errorList);
                }
                catch (Exception e) {
                    tx.Rollback();
                    throw e;
                }
            }
        }
Example #3
0
        public void SendModifiedPBToKZ(ConsMixprop entity, string[] DirtyDataArr)
        {
            using (var tx = this.m_UnitOfWork.BeginTransaction())
            {
                try
                {
                    if (DirtyDataArr != null)
                    {
                        ////先保存子表数据,只用到编号与数量
                        string        is2012   = "";
                        Synmonitor    synTable = null;
                        PublicService op       = null;

                        foreach (string DirtyData in DirtyDataArr)
                        {
                            string[] dirty = DirtyData.Split(',');
                            ConsMixpropItemService consMixpropItemservice = new ConsMixpropItemService(this.m_UnitOfWork);
                            ConsMixpropItem        item = consMixpropItemservice.Get(Convert.ToInt32(dirty[0]));
                            item.Amount = Convert.ToDecimal(dirty[1]);
                            consMixpropItemservice.Update(item, null);

                            is2012 = ConfigurationManager.AppSettings["Is2012"];
                            if (is2012 == "true")
                            {
                                //是2012工控则插入同步表
                                synTable               = new Synmonitor();
                                synTable.tb_name       = "view_ConsMixpropItems";
                                synTable.tb_action     = "UPDATE";
                                synTable.key_name      = "ConsMixpropID";
                                synTable.key_value     = dirty[0];
                                synTable.key_type      = "0";
                                synTable.action_time   = DateTime.Now;
                                synTable.ProductLineID = item.ConsMixprop.ProductLineID;
                                if (op == null)
                                {
                                    op = new PublicService();
                                }
                                op.Synmonitor.Add(synTable);
                            }
                        }
                    }
                    IConsMixpropItemRepository IConItems = this.m_UnitOfWork.ConsMixpropItemRepository;
                    IList <ConsMixpropItem>    citems    = IConItems.Query().Where(m => m.ConsMixpropID == entity.ID).ToList();
                    decimal totolWeight = 0;
                    foreach (ConsMixpropItem citem in citems)
                    {
                        totolWeight = totolWeight + citem.Amount;
                    }
                    ConsMixprop cons = this.Get(entity.ID);
                    cons.SynStatus = entity.SynStatus;
                    base.Update(cons, null);
                    entity = this.Get(entity.ID);
                    SysConfigService configService = new SysConfigService(this.m_UnitOfWork);
                    SysConfig        config        = configService.GetSysConfig(SysConfigEnum.IsAllowConsMixpropLimit);
                    if (!entity.IsSlurry)
                    {
                        SysConfig configFormulaRZMax = configService.GetSysConfig(SysConfigEnum.FormulaRZMax);
                        SysConfig configFormulaRZMin = configService.GetSysConfig(SysConfigEnum.FormulaRZMin);
                        decimal   dFormulaRZMax      = decimal.Parse(configFormulaRZMax.ConfigValue);
                        decimal   dFormulaRZMin      = decimal.Parse(configFormulaRZMin.ConfigValue);
                        decimal   weight             = entity.Weight ?? 0;
                        if (config != null && bool.Parse(config.ConfigValue) && entity.ProduceTask.CementType == Model.Enums.CementType.CommonCement)
                        {
                            if (totolWeight > dFormulaRZMax || totolWeight < dFormulaRZMin)
                            {
                                throw new Exception("混凝土配比超出容重范围");
                            }
                            string measureError = CheckMesureScale(entity.TaskID, entity.ProductLineID, 0, 0, true, false);
                            if (!string.IsNullOrEmpty(measureError))
                            {
                                throw new Exception(measureError);
                            }
                        }
                    }
                    else
                    {
                        if (config != null && bool.Parse(config.ConfigValue) && entity.ProduceTask.CementType == Model.Enums.CementType.CommonCement)
                        {
                            string measureError = CheckMesureScale(entity.TaskID, entity.ProductLineID, 0, 0, false, true);
                            if (!string.IsNullOrEmpty(measureError))
                            {
                                throw new Exception(measureError);
                            }
                        }
                    }
                    if (entity.SynStatus == 1)      //发送配比
                    {
                        /*//直连:通知控制系统修改配比
                         * by:Sky 2013/3/17
                         *****************************************************************************/
                        IList <ConsMixpropItem> cmItems = this.m_UnitOfWork.GetRepositoryBase <ConsMixpropItem>().All("ConsMixpropID='" + entity.ID + "'", "ID", true);
                        ResultInfo result = controlSystem.UpdateConsMixprop(entity, cmItems);
                        if (!result.Result)       //配比没有发送成功
                        {
                            throw new Exception(result.Message);
                        }
                    }
                    tx.Commit();
                }
                catch (Exception e)
                {
                    tx.Rollback();
                    throw e;
                }
            }
        }