Beispiel #1
0
 public virtual string g(string sCn, string sSql, string nullValue, params object[] oValues)
 {
     if (sSql == string.Empty)
     {
         return(string.Empty);
     }
     if ((oValues.Length == 1) && ((oValues[0] == null) || (oValues[0] == Convert.DBNull)))
     {
         return(nullValue);
     }
     for (int i = 0; i < oValues.Length; i++)
     {
         sSql = sSql.Replace("{" + i + "}", Convert.ToString(oValues[i]));
     }
     if (sCn == string.Empty)
     {
         return(XSql.GetDB(sCn).GetData(sSql).ToStr());
     }
     return(XSql.GetDB(sCn).GetData(sSql).ToStr());
 }
Beispiel #2
0
        ///**************************************************************
        public int SaveToDb(XModel updateModel)
        {
            _CheckKeyField();
            string sets       = updateModel.SetsListString();
            string fieldLists = updateModel.FieldsListStringForInsert(false);
            string valueLists = updateModel.ValuesListStringForInsert(false);
            //string whereStr=updateModel.DefaultConditionString(this.KeyField);
            string whereStr = GetKeyConditionString(false, updateModel);
            //if (string.IsNullOrEmpty(sets))
            //{
            //    return 0;
            //}
            string sSql_Exists = "Select * from  " + this.TableName + " where " + whereStr;
            string sSql_Update = String.IsNullOrEmpty(sets) ? "Select 1;" : "Update " + this.TableName + " set " + sets + " where " + whereStr + ";";
            string sSql_Insert = String.IsNullOrEmpty(fieldLists) || String.IsNullOrEmpty(valueLists) ? "Select 1;" : "Insert into " + this.TableName + "(" + fieldLists + ") values(" + valueLists + ");";
            string sSql        = String.Format("if exists({0}) {1} else {2}", sSql_Exists, sSql_Update, sSql_Insert);
            int    iR          = 0;

            ULCode.QDA.ProviderType ct = XSql.GetDB(this.CnName).GetProviderType();
            if (ct == ProviderType.MsSql)
            {
                iR = this.Execute(sSql);
            }
            else// if (ct == ProviderType.OleDb)
            {
                if (XSql.IsHasRow(this.CnName, sSql_Exists))
                {
                    iR = this.Execute(sSql_Update);
                }
                else
                {
                    iR = this.Execute(sSql_Insert);
                }
            }
            if (iR > 0)
            {
                updateModel.ClearAllUpdated();
            }
            return(iR);
        }
Beispiel #3
0
        public virtual string gl(string outputFormat, object nullValue, string sCn, string sSql, params object[] oValues)
        {
            int i;

            object[] oArr;
            if (sSql == string.Empty)
            {
                return(Convert.ToString(nullValue));
            }
            if ((oValues.Length == 1) && ((oValues[0] == null) || (oValues[0] == Convert.DBNull)))
            {
                return(Convert.ToString(nullValue));
            }
            for (i = 0; i < oValues.Length; i++)
            {
                sSql = sSql.Replace("{" + i + "}", Convert.ToString(oValues[i]));
            }
            oArr = XSql.GetDB(sCn).GetXDataTable(sSql).ToObjectArray();
            if ((oArr.Length == 0) || ((oArr.Length == 1) && ((oArr[0] == null) || (oArr[0] == Convert.DBNull))))
            {
                return(Convert.ToString(nullValue));
            }
            for (i = 0; i < oArr.Length; i++)
            {
                string sSingleValue = string.Empty;
                if (outputFormat.Contains("{" + i + "}"))
                {
                    if ((oArr[i] == null) || (oArr[i] == Convert.DBNull))
                    {
                        sSingleValue = string.Empty;
                    }
                    else
                    {
                        sSingleValue = Convert.ToString(oArr[i]);
                    }
                    outputFormat = outputFormat.Replace("{" + i + "}", sSingleValue);
                }
            }
            return(outputFormat);
        }