Пример #1
0
 public CpPackageMtrInfo(CpPackageMtrInfo objEntr) : base(objEntr)
 {
 }
Пример #2
0
        public override bool import(string db, JArray p, string mode, ref string errMsg, ref string logMsg)
        {
            bool anyError      = false,
                 isTransaction = false;

            BUS.CpPackageMtrControl ctr = this;

            if (p.Count > 1)
            {
                isTransaction = true;
            }

            if (isTransaction)
            {
                ctr.BeginTransaction(ref logMsg);
                if (logMsg != "")
                {
                    errMsg   = BUS.StLanguageControl.translate(this, "There was processing errors. Transaction ROLLBACKED");
                    anyError = true;
                }
            }
            String seqcode = null, format = string.Empty;

            BUS.CsSequenceControl ctrSq = new BUS.CsSequenceControl(this);
            bool   isSeq                = ctrSq.CheckSequence(db, shortCmd, ref logMsg);
            string keyField             = "packagecodematerialcode",
                   tableName            = "cppackagemtr";

            foreach (JObject o in p)
            {
                if (anyError)
                {
                    break;
                }
                DTO.CpPackageMtrInfo inf = null;
                if (isSeq && (o[keyField] == null || o[keyField].ToString() == ""))
                {
                    o[keyField] = ctrSq.genSeqCode(db, this.LD, ref seqcode, shortCmd, tableName, keyField, o, ref format);
                }
                anyError = ctr.validate(o, BUS.BUSControl.ValidType.Imp, ref errMsg);

                if (anyError)
                {
                    break;
                }
                try {
                    inf           = o.ToObject <DTO.CpPackageMtrInfo>();
                    inf.tvcdb     = db;
                    inf.updatedby = USER_ID;
                } catch (Exception ex) {
                    anyError = true;
                    logMsg   = ex.Message;
                    errMsg   = BUS.StLanguageControl.translate(this, "There was processing errors. Transaction ROLLBACKED");
                }

                if (anyError)
                {
                    break;
                }

                if (IsExist(inf.tvcdb, inf.packagecode, inf.materialcode, ref logMsg))
                {
                    logMsg = ctr.Update(inf);
                }
                else
                {
                    inf.createdby = USER_ID;
                    if (string.IsNullOrEmpty(logMsg))
                    {
                        ctr.Add(inf, ref logMsg);
                    }
                    if (!string.IsNullOrEmpty(logMsg))
                    {
                        anyError = true;
                    }
                }
            }

            if (isTransaction)
            {
                if (anyError)
                {
                    RollbackTransaction(ref logMsg);
                }
                else
                {
                    CommitTransaction(ref logMsg);
                }
            }

            return(anyError);
        }