Ejemplo n.º 1
0
        public IList<COAReceivingDef> ReadTXTFile(string path, string userName,string ip)
        {
            string line = String.Empty;

            IList<COAReceivingDef> coaLst = new List<COAReceivingDef>();
            COAReceivingDef globalObj = new COAReceivingDef();
            COAReceivingDef def = new COAReceivingDef();
            int flagBegin = 0;
            bool isQty = false, isBegNo = false, isEndNo = false;

            using (StreamReader reader = new StreamReader(path))
            {
                string l = String.Empty;

                while (!reader.EndOfStream)
                {
                    l = reader.ReadLine();
                    string[] attr = l.Split(SPLITSTR);
                    //把多行回车过滤掉...
                    //ITC-1361-0098 ITC210012 2012-02-22 
                    if (attr.Length == 1 || attr[0].Trim() == "")
                    {
                        continue;
                    }
                    string attrKey = attr[0].Trim();
                    string attrVal = attr[1].Trim();

                    if (string.Compare(CUSTOMERNAME, attrKey, true) == 0)
                    {
                        List<string> param = new List<string>();
                        param.Add("[Customer Name]");
                        CheckAttrVal(param, attrVal);
                        globalObj.customerName = attrVal;
                        flagBegin |= 1;
                    }
                    else if (string.Compare(INVENTECPO, attrKey, true) == 0)
                    {
                        List<string> param = new List<string>();
                        param.Add("[Inventec PO]");
                        CheckAttrVal(param, attrVal);
                        globalObj.po = attrVal;
                        flagBegin |= 2;
                    }
                    else if (string.Compare(CUSTPN, attrKey, true) == 0)
                    {
                        List<string> param = new List<string>();
                        param.Add("[Customer PN]");
                        CheckAttrVal(param, attrVal);
                        globalObj.custPN = attrVal;
                        flagBegin |= 4;
                    }
                    else if (string.Compare(IECPN, attrKey, true) == 0)
                    {
                        List<string> param = new List<string>();
                        param.Add("[IEC PN]");
                        CheckAttrVal(param, attrVal);
                        globalObj.iecPN = attrVal;
                        flagBegin |= 8;
                    }
                    else if (string.Compare(DESC, attrKey, true) == 0)
                    {
                        List<string> param = new List<string>();
                        param.Add("[Description]");
                        CheckAttrVal(param, attrVal);
                        globalObj.description = attrVal;
                        flagBegin |= 16;
                    }
                    else if (string.Compare(SHIPPINGDATE, attrKey, true) == 0)
                    {
                        List<string> param = new List<string>();
                        param.Add("[Shipping Date]");
                        CheckAttrVal(param, attrVal);
                        globalObj.shippingDate = attrVal;
                        flagBegin |= 32;
                    }
                    if (isQty && isBegNo && isEndNo)
                    {
                        isQty = false;
                        isBegNo = false;
                        isEndNo = false;

                        COAReceivingDef crDef = new COAReceivingDef();
                        crDef.customerName = globalObj.customerName;
                        crDef.po = globalObj.po;
                        crDef.custPN = globalObj.custPN;
                        crDef.iecPN = globalObj.iecPN;
                        crDef.description = globalObj.description;
                        crDef.shippingDate = globalObj.shippingDate;
                        crDef.qty = def.qty;
                        crDef.begNO = def.begNO;
                        crDef.endNO = def.endNO;
                        crDef.editor = userName;
                        crDef.pc = ip;
                        coaLst.Add(crDef);
                    }
                    if (string.Compare(QTY, attrKey, true) == 0 || string.Compare(BEGNO, attrKey, true) == 0 || string.Compare(ENDNO, attrKey, true) == 0)
                    {

                        if (string.Compare(QTY, attrKey, true) == 0)
                        {
                            if (!isQty)
                            {
                                List<string> param = new List<string>();
                                param.Add("[Quantity]");
                                CheckAttrVal(param, attrVal);
                                def.qty = attrVal;
                                isQty = true;
                            }
                            else
                            {
                                ThrowBizException("DMT106");
                            }

                        }

                        if (string.Compare(BEGNO, attrKey, true) == 0)
                        {
                            if (!isBegNo)
                            {
                                List<string> param = new List<string>();
                                param.Add("[Start COA Number]");
                                CheckAttrVal(param, attrVal);
                                //如果包含小写字母,抛出异常...
                                if (System.Text.RegularExpressions.Regex.IsMatch(attrVal, "[a-z]"))
                                {
                                    ThrowBizException("DMT105");
                                }
                                def.begNO = attrVal;
                                isBegNo = true;
                            }

                            else
                            {
                                ThrowBizException("DMT106");
                            }
                        }

                        if (string.Compare(ENDNO, attrKey, true) == 0)
                        {
                            if (!isEndNo)
                            {
                                List<string> param = new List<string>();
                                param.Add("[End COA Number]");
                                CheckAttrVal(param, attrVal);
                                if (System.Text.RegularExpressions.Regex.IsMatch(attrVal, "[a-z]"))
                                {
                                    ThrowBizException("DMT105");
                                }
                                def.endNO = attrVal;
                                isEndNo = true;
                            }

                            else
                            {
                                ThrowBizException("DMT106");
                            }
                        }

                    }
                }
                // read end file
                if (reader.EndOfStream)
                {
                    if (!isQty || !isBegNo || !isEndNo)
                    {
                        ThrowBizException("DMT106");
                    }
                    else
                    {
                        COAReceivingDef crDef = new COAReceivingDef();
                        crDef.customerName = globalObj.customerName;
                        crDef.po = globalObj.po;
                        crDef.custPN = globalObj.custPN;
                        crDef.iecPN = globalObj.iecPN;
                        crDef.description = globalObj.description;
                        crDef.shippingDate = globalObj.shippingDate;
                        crDef.qty = def.qty;
                        crDef.begNO = def.begNO;
                        crDef.endNO = def.endNO;
                        crDef.editor = userName;
                        crDef.pc = ip;
                        coaLst.Add(crDef);
                    }
                }

            }
            if (flagBegin != (1 | 2 | 4 | 8 | 16 | 32))
            {

                ThrowBizException("DMT106");
            }

            return coaLst;
        }
Ejemplo n.º 2
0
        private IList<COAReceivingDef> VO2PO(IList<TmpTableInfo> tmpDataList)
        {
            IList<COAReceivingDef> defDataLst = new List<COAReceivingDef>();
            foreach (TmpTableInfo info in tmpDataList)
            {
                COAReceivingDef tmp = new COAReceivingDef();
                tmp.po = info.po;
                //issue code
                //ITC-1361-0060  itc210012  2012-02-01
                tmp.shippingDate = info.shipDate.ToString("yyyy-MM-dd");

                tmp.custPN = info.custPN;
                tmp.iecPN = info.iecpn;
                tmp.description = info.descr;
                tmp.begNO = info.begSN;
                tmp.endNO = info.endSN;
                tmp.qty = info.qty.ToString();

                tmp.editor = info.editor;
                //      info.cdt = DateTime.Now;
                tmp.customerName = info.cust;
                //       info.udt = DateTime.Now;
                defDataLst.Add(tmp);
            }
            return defDataLst;
        }