Beispiel #1
0
 public CpPackageInfo(CpPackageInfo objEntr) : base(objEntr)
 {
 }
        public override bool import(string db, JArray p, string mode, ref string errMsg, ref string logMsg)
        {
            bool anyError      = false,
                 isTransaction = false;

            BUS.CpPackageControl 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 shortCmd = _oShortCmd;
            string shortCmd = "CPK";
            String seqcode = null, format = string.Empty;

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

            foreach (JObject o in p)
            {
                if (anyError)
                {
                    break;
                }
                DTO.CpPackageInfo 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);
                    if (shortCmd == "PKT")
                    {
                        o["isterm"] = "Y";
                    }
                    else
                    {
                        o["isterm"] = "N";
                    }
                }
                anyError = ctr.validate(o, BUS.BUSControl.ValidType.Imp, ref errMsg);

                if (anyError)
                {
                    break;
                }
                try
                {
                    inf           = o.ToObject <DTO.CpPackageInfo>();
                    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, 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);
        }