Пример #1
0
        /// <summary>
        /// 摘要:更新一条记录
        /// </summary>
        /// <param name="T">实体类对象</param>
        public ReturnMessage Update()
        {
            ReturnMessage rm          = new ReturnMessage(true);
            string        stTableName = string.Empty;

            try
            {
                T obj = (T)this.MemberwiseClone();
                stTableName = ((TableAttribute)obj.GetType().GetCustomAttributes(true)[0]).TableName;
                IDBCore iDB = null;
                if (DATABASE_TYPE == "XML")
                {
                    iDB = new XMLCore(_TagData);
                }
                else
                {
                    iDB = DBFactory.CreateDB();
                }
                iDB.Update(obj);
            }
            catch (Exception ex)
            {
                rm.IsSucessed = false;
                rm.Message    = "表【" + stTableName + "】更新数据失败,原因:" + ex.Message;
            }
            return(rm);
        }
Пример #2
0
        /// <summary>
        /// 摘要:根据条件查询数据集记录条数
        /// </summary>
        /// <param name="dataSetSql">查询语句(包括列名、表等信息,支持表关联)</param>
        /// <param name="where">条件组,二维数据【0】为包括字段名的语句段模板,【1】为取值</param>
        /// <returns></returns>
        public int GetDataSetCount(string dataSetSql, List <string[]> where)
        {
            int    iCount      = -1;
            string stTableName = string.Empty;

            try
            {
                T obj = (T)this.MemberwiseClone();
                stTableName = ((TableAttribute)obj.GetType().GetCustomAttributes(true)[0]).TableName;
                IDBCore iDB = null;
                if (DATABASE_TYPE == "XML")
                {
                    iDB = new XMLCore(_TagData);
                }
                else
                {
                    iDB = DBFactory.CreateDB();
                }
                iCount = iDB.GetDataSetCount(dataSetSql, where);
            }
            catch (Exception ex)
            {
                ;
            }
            return(iCount);
        }
Пример #3
0
 public async void LoadFirstConnAsync()
 {
     try
     {
         XMLCore.ConnectionDeserialize();
         if (XMLCore.Connections.Count > 0)
         {
             try
             {
                 await XMLCore.Connections.First().LoadDatabasesAsync();
             }
             catch (Exception ex)
             {
                 await dialogCoordinator.ShowMessageAsync(this, $"Error!", $"Error message: {ex.Message}  \r\nStackTrace: {ex.StackTrace}");
             }
         }
         else
         {
             new Views.Windows.ConnectionManagerWin().ShowDialog();
             XMLCore.ConnectionDeserialize();
             XMLCore.Connections.FirstOrDefault()?.LoadDatabasesAsync();
         }
     }
     catch (Exception ex)
     {
         await dialogCoordinator.ShowMessageAsync(this, $"Error!", $"Error message: {ex.Message}  \r\nStackTrace: {ex.StackTrace}");
     }
 }
Пример #4
0
        private async void DeleteConnectionAsync()
        {
            if (SelectedNode != null && SelectedNode is TreeViewModel)
            {
                var res = await dialogCoordinator.ShowMessageAsync(this, $"Are you sure?", $"Are you sure to delete this connection: {(SelectedNode as TreeViewModel).Connection.ConnectionName}?", MessageDialogStyle.AffirmativeAndNegative);

                if (res == MessageDialogResult.Affirmative)
                {
                    XMLCore.Connections.Remove((SelectedNode as TreeViewModel));
                    XMLCore.ConnectionSerialize();
                    XMLCore.ConnectionDeserialize();
                }
            }
        }
Пример #5
0
        private void EditConnectionAsync()
        {
            Views.Windows.ConnectionManagerWin connectionManagerWin = new Views.Windows.ConnectionManagerWin(SelectedNode as TreeViewModel);
            var res = connectionManagerWin.ShowDialog();

            XMLCore.ConnectionDeserialize();
            if (res != null && res == true)
            {
                var cmvm = connectionManagerWin.DataContext as ConnectionManagerVM;
                if (cmvm.EditModel != null)
                {
                    var con = XMLCore.Connections.FirstOrDefault(x => x.Connection.ConnectionName == cmvm.EditModel.ConnectionName);
                    con?.LoadDatabasesAsync();
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 摘要:删除记录
        /// </summary>
        /// <param name="value">要删除的主键值数组</param>
        public ReturnMessage Delete(List <string> value)
        {
            ReturnMessage rm          = new ReturnMessage(true);
            string        stTableName = string.Empty;

            try
            {
                T obj = (T)this.MemberwiseClone();
                stTableName = ((TableAttribute)obj.GetType().GetCustomAttributes(true)[0]).TableName;
                string         stPK          = string.Empty;
                PropertyInfo[] propertyInfos = obj.GetType().GetProperties();
                for (int i = 0; i < propertyInfos.Length; i++)
                {
                    if (propertyInfos[i].GetCustomAttributes(true).Length != 0)
                    {
                        if (propertyInfos[i].GetCustomAttributes(true)[0].GetType().Name == "PrimaryKeyAttribute")
                        {
                            stPK = propertyInfos[i].Name;
                        }
                    }
                }
                IDBCore iDB = null;
                if (DATABASE_TYPE == "XML")
                {
                    iDB = new XMLCore(_TagData);
                }
                else
                {
                    iDB = DBFactory.CreateDB();
                }
                iDB.Delete(stPK, stTableName, value);
            }
            catch (Exception ex)
            {
                rm.IsSucessed = false;
                rm.Message    = "表【" + stTableName + "】删除数据失败,原因:" + ex.Message;
            }
            return(rm);
        }
Пример #7
0
        private async void EditConnectionAsync()
        {
            try
            {
                Views.Windows.ConnectionManagerWin connectionManagerWin = new Views.Windows.ConnectionManagerWin(SelectedNode as TreeViewModel);
                var res = connectionManagerWin.ShowDialog();

                XMLCore.ConnectionDeserialize();
                if (res != null && res == true)
                {
                    var cmvm = connectionManagerWin.DataContext as ConnectionManagerVM;
                    if (cmvm.ConnectionBuilder != null)
                    {
                        var con = XMLCore.Connections.FirstOrDefault(x => x.ConnectionBuilder.Id == cmvm.ConnectionBuilder.Id);
                        con?.LoadDatabasesAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                await dialogCoordinator.ShowMessageAsync(this, $"Error!", $"Error message: {ex.Message}  \r\nStackTrace: {ex.StackTrace}");
            }
        }
Пример #8
0
        /// <summary>
        /// 摘要:对数据进行分页
        /// </summary>
        /// <param name="dataSetSql">查询语句(包括列名、表等信息,支持表关联)</param>
        /// <param name="where">条件组,二维数据【0】为包括字段名的语句段模板,【1】为取值</param>
        /// <param name="orderByColumn">排序列,二维数据【0】为字段名,【1】为ASC(升序)或DESC(降序)</param>
        /// <param name="rowBegin">排序后数据集的行开始索引</param>
        /// <param name="rowEnd">排序后数据集的行结束索引</param>
        /// <returns></returns>
        public DataTable GetDataSet(string dataSetSql, List <string[]> where, List <string[]> orderByColumn, int rowBegin, int rowEnd)
        {
            DataTable dt          = new DataTable();
            string    stTableName = string.Empty;

            try
            {
                T obj = (T)this.MemberwiseClone();
                stTableName = ((TableAttribute)obj.GetType().GetCustomAttributes(true)[0]).TableName;
                IDBCore iDB = null;
                if (DATABASE_TYPE == "XML")
                {
                    iDB = new XMLCore(_TagData);
                }
                else
                {
                    iDB = DBFactory.CreateDB();
                }
                if ((rowBegin == -1 || rowEnd == -1) && orderByColumn != null)
                {
                    dt = iDB.GetDataSet(dataSetSql, where, orderByColumn);
                }
                else if ((rowBegin == -1 || rowEnd == -1) && orderByColumn == null)
                {
                    dt = iDB.GetDataSet(dataSetSql, where);
                }
                else
                {
                    dt = iDB.GetDataSet(dataSetSql, where, orderByColumn, rowBegin, rowEnd);
                }
            }
            catch (Exception ex)
            {
                dt = null;
            }
            return(dt);
        }