Example #1
0
        static string makesql(string taskid, string log, string jobid = "", string remark = "")
        {
            string columers = "";

            if (DbHelper.DBType == DatabaseType.Mdb)
            {
                columers = " ([时间],[任务编号],[事件],[作业编号],[备注]) ";
            }
            else
            {
                columers = " (时间,任务编号,事件,作业编号,备注) ";
            }
            StringBuilder updatesql = new StringBuilder(200);

            updatesql.Append("Insert Into ");
            updatesql.Append("qc_pro_timelinetask");
            updatesql.Append(columers);
            string values = "";

            if (jobid == "")
            {
                jobid = "null";
            }
            else
            {
                jobid = "\'" + jobid + "\'";
            }
            if (remark == "")
            {
                remark = "null";
            }
            else
            {
                remark = "\'" + remark + "\'";
            }
            string datetime = "";

            if (DbHelper.DBType == DatabaseType.Oracle)
            {
                datetime = "to_date('" + QcDate.DateString() + "','yyyy-mm-dd hh24:mi:ss')";
            }
            else if (DbHelper.DBType == DatabaseType.Mdb || DbHelper.DBType == DatabaseType.Accdb)
            {
                datetime = "#" + DateTime.Now.ToLongTimeString() + "#";
            }
            else
            {
                datetime = "\'" + DateTime.Now.ToLongTimeString() + "\'";
            }
            values = string.Format("({0},'{1}','{2}',{3},{4})", datetime, taskid, log, jobid, remark);
            updatesql.Append(" Values ");
            updatesql.Append(values);
            return(updatesql.ToString());
        }
        /// <summary>
        ///  更新数据到数据库
        /// </summary>
        /// <returns></returns>
        public virtual bool Update(QcDbTransaction trans = null)
        {
            if (tablename == null)
            {
                return(false);
            }
            bool   returnvalue = true;
            string Sql         = null;
            var    cols        = row.Table.Columns;

            if (row.RowState == DataRowState.Detached)
            {
                if (cols.Contains("创建人"))
                {
                    if (this["创建人"] != "" && QcUser.User != null)
                    {
                        this["创建人"] = QcUser.User.UserID;
                    }
                }
                if (cols.Contains("创建日期"))
                {
                    this["创建日期"] = QcDate.DateString();
                }
                Sql = MakeInsertSql();
                if (trans != null)
                {
                    returnvalue = trans.Execute(Sql);
                }
                else
                {
                    returnvalue = DbHelper.Execute(Sql);
                }
                this.Refresh();
            }
            else if (row.RowState == DataRowState.Modified)
            {
                if (cols.Contains("修改人"))
                {
                    if (QcUser.User != null)
                    {
                        this["修改人"] = QcUser.User.UserID;
                    }
                }
                if (cols.Contains("修改日期"))
                {
                    this["修改日期"] = QcDate.DateString();
                }
                Sql = MakeUpdateSql();
                if (trans != null)
                {
                    returnvalue = trans.Execute(Sql);
                }
                else
                {
                    returnvalue = DbHelper.Execute(Sql);
                }
                if (returnvalue)
                {
                    row.AcceptChanges();
                }
            }
            return(returnvalue);
        }