Esempio n. 1
0
        /// <summary>
        /// 執行 Save 方法的實作。
        /// </summary>
        /// <param name="inputArgs"></param>
        /// <param name="outputResult"></param>
        protected virtual void DoSave(GSaveInputArgs inputArgs, GSaveOutputResult outputResult)
        {
            var table = inputArgs.EntitySet.Tables[this.ProgID];

            if (inputArgs.SaveMode == ESaveMode.Add)
            {
                foreach (GEntityRow row in table.Rows)
                {
                    var sql = new StringBuilder();
                    sql.AppendLine($"Insert Into {this.ProgID} (");
                    var isFirst = true;
                    foreach (var fieldDefine in this.ProgramDefine.MasterFields.Where(x => x.FieldType == EFieldType.DataField))
                    {
                        if (!row.HasField(fieldDefine.FieldName))
                        {
                            continue;
                        }
                        var fieldName = fieldDefine.FieldName;
                        sql.AppendLine((isFirst ? "" : ",") + $"{fieldName}");
                        isFirst = false;
                    }
                    sql.AppendLine(")");
                    sql.AppendLine("Values (");
                    isFirst = true;
                    foreach (var fieldDefine in this.ProgramDefine.MasterFields.Where(x => x.FieldType == EFieldType.DataField))
                    {
                        var fieldName = fieldDefine.FieldName;
                        if (row.HasField(fieldName))
                        {
                            sql.AppendLine((isFirst ? "" : ",") + $"{row.ValueAsString(fieldName).SQLStr()}");
                            isFirst = false;
                        }
                    }
                    sql.AppendLine(")");
                    this.DbAccess.ExecuteNonQuery(this.DatabaseID, sql.ToString());
                }
            }
            else
            {
                foreach (GEntityRow row in table.Rows)
                {
                    var sql = new StringBuilder();
                    sql.AppendLine("Update A Set");
                    var isFirst = true;
                    foreach (var fieldDefine in this.ProgramDefine.MasterFields.Where(x => x.FieldType == EFieldType.DataField))
                    {
                        var fieldName = fieldDefine.FieldName;
                        if (row.HasField(fieldName) && !fieldName.SameText($"{SysFields.ID}"))
                        {
                            sql.AppendLine((isFirst ? "" : ",") + $"{fieldName} = {row.ValueAsString(fieldName).SQLStr()}");
                            isFirst = false;
                        }
                    }
                    sql.AppendLine($"From {this.ProgID} A");
                    sql.AppendLine($"Where A.{SysFields.ID} = {row.ValueAsString($"{SysFields.ID}").SQLStr()}");
                    this.DbAccess.ExecuteNonQuery(this.DatabaseID, sql.ToString());
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 儲存表單資料。
        /// </summary>
        /// <param name="inputArgs"></param>
        /// <returns></returns>
        public GSaveOutputResult Save(GSaveInputArgs inputArgs)
        {
            var outputResult = new GSaveOutputResult();

            DoBeforeSave(inputArgs, outputResult);
            if (inputArgs.Cancel)
            {
                return(outputResult);
            }

            DoSave(inputArgs, outputResult);

            DoAfterSave(inputArgs, outputResult);

            return(outputResult);
        }
Esempio n. 3
0
 /// <summary>
 /// 執行 Save 方法後呼叫的方法。
 /// </summary>
 /// <param name="inputArgs"></param>
 /// <param name="outputResult"></param>
 protected virtual void DoAfterSave(GSaveInputArgs inputArgs, GSaveOutputResult outputResult)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// 執行 Save 方法前呼叫的方法。
 /// </summary>
 /// <param name="inputArgs"></param>
 /// <param name="outputResult"></param>
 protected virtual void DoBeforeSave(GSaveInputArgs inputArgs, GSaveOutputResult outputResult)
 {
 }