예제 #1
0
        public void UpdateTable(object table, string view, object parameters, string rowKey, ref string script, ref bool isInvalid)
        {
            DataRow drParams = parameters as DataRow;

            CiTable ciTable = table as CiTable;

            if (ciTable != null && drParams != null)
            {
                CiMacro ciMacro = ciTable.UpdateMacro;
                if (ciMacro != null)
                {
                    ciMacro.Run(drParams);
                    script    = ciMacro.ResultScript;
                    isInvalid = !MyUtils.IsEmpty(ciMacro.ErrorMessage);
                }
            }
        }
예제 #2
0
        public DataTable SelectTable(object table, string view, object parameters, ref string script)
        {
            DataRow   drParams = parameters as DataRow;
            DataTable dt       = null;

            CiTable ciTable = table as CiTable;

            if (ciTable != null)
            {
                if (parameters != null && parameters.GetType() == typeof(bool))
                {
                    // Do nothing - but can't remember what this is for???
                    throw new System.Exception("Aha!");
                }
                else if (ciTable.SelectMacro != null)
                {
                    CiMacro ciMacro = ciTable.SearchMacro;
                    if (ciMacro != null)
                    {
                        ciMacro.Run(drParams, true);
                        dt     = ciMacro.ResultTable;
                        script = ciMacro.ResultScript;
                    }
                }
                else if (ciTable.DataSource != null)
                {
                    dt = ciTable.DataTable;
                }

                if (dt == null)
                {
                    dt = new DataTable();
                }

                AddExpressionColumns(ciTable, dt, drParams);

                if (MyWebUtils.GetNumberOfColumns(dt) > 0 && !dt.Columns.Contains("RowKey"))
                {
                    dt.Columns.Add("RowKey").Expression = CreateRowKeyExpression(ciTable.RowKey);
                }
            }

            return(dt);
        }
예제 #3
0
        private void AddExpressionColumns(CiTable ciTable, DataTable dt, DataRow drParams)
        {
            if (ciTable != null)
            {
                foreach (CiField ciField in ciTable.CiFields)
                {
                    string fieldName    = ciField.FieldName;
                    string defaultValue = ciField.Value;

                    if (!dt.Columns.Contains(fieldName))
                    {
                        DataColumn dc         = dt.Columns.Add(fieldName);
                        string     expression = "";

                        if (ciField.Computed)
                        {
                            expression = defaultValue;
                        }
                        else
                        {
                            if (MyUtils.IsEmpty(defaultValue) && drParams != null && drParams.Table.Columns.Contains(fieldName))
                            {
                                defaultValue = drParams[fieldName].ToString().Replace("'", "''");
                            }

                            expression = string.Format("'{0}'", defaultValue);
                        }

                        dc.Expression = expression;
                    }
                    else if (ciField.GetType() == typeof(CiField) && !MyUtils.IsEmpty(defaultValue))
                    {
                        dt.Columns[fieldName].Expression = string.Format("'{0}'", defaultValue);
                    }
                }
            }
        }
예제 #4
0
        public void InsertTable(object table, string view, object parameters, ref string rowKey, ref string script, ref bool isInvalid)
        {
            DataRow drParams = parameters as DataRow;

            CiTable ciTable = table as CiTable;

            if (ciTable != null)
            {
                CiMacro ciMacro = ciTable.InsertMacro;
                if (ciMacro != null)
                {
                    ciMacro.Run(drParams);
                    script    = ciMacro.ResultScript;
                    isInvalid = !MyUtils.IsEmpty(ciMacro.ErrorMessage);

                    DataTable dt = ciMacro.ResultTable;
                    if (MyWebUtils.GetNumberOfRows(dt) > 0)
                    {
                        DataRow dr = dt.Rows[0];
                        int     i  = 0;
                        foreach (string key in ciTable.RowKeyNames)
                        {
                            if (i++ > 0)
                            {
                                rowKey += ",";
                            }

                            if (dt.Columns.Contains(key))
                            {
                                rowKey += MyUtils.Coalesce(dr[key], "").ToString();
                            }
                        }
                    }
                }
            }
        }