예제 #1
0
 public DateTime?GetValidFrom(BO.BaseBO rec)
 {
     if (rec.pid == 0)
     {
         return(DateTime.Now.AddSeconds(-10));
     }
     else
     {
         return(rec.ValidFrom);
     }
 }
예제 #2
0
        public DateTime?GetValidUntil(BO.BaseBO rec)
        {
            switch (this.ArchiveFlag)
            {
            case "1":
                return(DateTime.Now);

            case "2":
                return(new DateTime(3000, 1, 1));

            default:
                if (rec.pid == 0)
                {
                    return(new DateTime(3000, 1, 1));
                }
                else
                {
                    return(rec.ValidUntil);
                }
            }
        }
예제 #3
0
 public MyToolbarViewModel(BO.BaseBO rec)
 {
     Record = rec;
     RefreshState();
 }
예제 #4
0
        public int SaveRecord(string strTable, DynamicParameters pars, BO.BaseBO rec, bool isvalidity = true, bool istimestamp = true)
        {
            var  strPidField = strTable.Substring(0, 3) + "ID";
            var  s           = new System.Text.StringBuilder();
            bool bolInsert   = true;

            if (rec.pid > 0)
            {
                bolInsert = false;
            }

            if (bolInsert)
            {
                s.Append(string.Format("INSERT INTO {0} (", strTable));
                if (istimestamp)
                {
                    pars.Add("DateInsert", DateTime.Now, System.Data.DbType.DateTime);
                    pars.Add("UserInsert", this.CurrentUser.j03Login, System.Data.DbType.String);
                }
            }
            else
            {
                s.Append(string.Format("UPDATE {0} SET ", strTable));
            }
            if (istimestamp)
            {
                pars.Add("DateUpdate", DateTime.Now, System.Data.DbType.DateTime);
                pars.Add("UserUpdate", this.CurrentUser.j03Login, System.Data.DbType.String);
            }
            if (isvalidity == true)
            {
                if (rec.ValidFrom == null)
                {
                    rec.ValidFrom = System.DateTime.Now;
                }
                pars.Add("ValidFrom", rec.ValidFrom, System.Data.DbType.DateTime);
                if (rec.ValidUntil == null)
                {
                    rec.ValidUntil = new DateTime(3000, 1, 1);
                }
                pars.Add("ValidUntil", rec.ValidUntil, System.Data.DbType.DateTime);
            }


            string strF = "", strV = "";

            foreach (var strP in pars.ParameterNames.Where(p => p != "pid"))
            {
                if (bolInsert)
                {
                    strF += "," + strP;
                    strV += ",@" + strP;
                }
                else
                {
                    strV += "," + strP + " = @" + strP;
                }
            }
            strV = strV.Substring(1, strV.Length - 1);
            if (bolInsert)
            {
                strF = strF.Substring(1, strF.Length - 1);
                s.Append(strF + ") VALUES (" + strV + ")");
            }
            else
            {
                s.Append(strV);
                s.Append(" WHERE " + strPidField + " = @pid");
            }


            using (SqlConnection con = new SqlConnection(_conString))
            {
                try
                {
                    if (bolInsert)
                    {
                        s.Append("; SELECT CAST(SCOPE_IDENTITY() as int) as Value");
                        return(con.Query <BO.COM.GetInteger>(s.ToString(), pars).FirstOrDefault().Value);
                    }
                    else
                    {
                        if (con.Execute(s.ToString(), pars) > 0)
                        {
                            return(pars.Get <int>("pid"));
                        }
                    }
                }
                catch (Exception e)
                {
                    log_error(e, s.ToString(), pars);
                }
            }


            return(0);
        }