public string getAuxiliaryMaterialNameFromPkey(string tableName, int pkey)
        {
            string name = "";
            SortedDictionary <int, AuxiliaryMaterialDataTable> materialList = new SortedDictionary <int, AuxiliaryMaterialDataTable>();


            if (tableName.Length > 0)
            {
                if (!m_materialList.ContainsKey(tableName))
                {
                    load(tableName);
                }

                materialList = m_materialList[tableName];
            }

            foreach (KeyValuePair <int, AuxiliaryMaterialDataTable> index in materialList)
            {
                AuxiliaryMaterialDataTable record = new AuxiliaryMaterialDataTable();
                record = index.Value;
                if (record.pkey == pkey)
                {
                    name = record.name;
                    break;
                }
            }

            return(name);
        }
        public int getAuxiliaryMaterialPkeyFromName(string tableName, string name)
        {
            int pkey = 0;
            SortedDictionary <int, AuxiliaryMaterialDataTable> materialList = new SortedDictionary <int, AuxiliaryMaterialDataTable>();


            if (tableName.Length > 0)
            {
                if (!m_materialList.ContainsKey(tableName))
                {
                    load(tableName);
                }

                materialList = m_materialList[tableName];
            }

            foreach (KeyValuePair <int, AuxiliaryMaterialDataTable> index in materialList)
            {
                AuxiliaryMaterialDataTable record = new AuxiliaryMaterialDataTable();
                record = index.Value;
                if (record.name == name)
                {
                    pkey = record.pkey;
                    break;
                }
            }

            return(pkey);
        }
        private void load(string tableName)
        {
            if (tableName.Length > 0)
            {
                string sql = "SELECT [PKEY],[NAME],[DESC],[IS_ALLOW_DELETE] FROM [dbo].[" + tableName + "] ORDER BY PKEY";

                m_materialList.Clear();

                using (DataTable dataTable = DatabaseAccessFactoryInstance.Instance.QueryDataTable(FormMain.DB_NAME, sql))
                {
                    SortedDictionary <int, AuxiliaryMaterialDataTable> materialList = new SortedDictionary <int, AuxiliaryMaterialDataTable>();
                    foreach (DataRow row in dataTable.Rows)
                    {
                        AuxiliaryMaterialDataTable record = new AuxiliaryMaterialDataTable();

                        record.pkey          = DbDataConvert.ToInt32(row[0]);
                        record.name          = DbDataConvert.ToString(row[1]);
                        record.desc          = DbDataConvert.ToString(row[2]);
                        record.isAllowDelete = DbDataConvert.ToInt32(row[3]);

                        materialList.Add(materialList.Count, record);
                    }

                    if (m_materialList.ContainsKey(tableName))
                    {
                        m_materialList[tableName] = materialList;
                    }
                    else
                    {
                        m_materialList.Add(tableName, materialList);
                    }
                }
            }
        }
        public void insert(string tableName, AuxiliaryMaterialDataTable material)
        {
            string insert = "INSERT INTO [dbo].[" + tableName + "]([NAME],[DESC],[IS_ALLOW_DELETE]) VALUES(";

            insert += "'" + material.name + "',";
            insert += "'" + material.desc + "',";
            insert += "1";
            insert += ")";

            try
            {
                DatabaseAccessFactoryInstance.Instance.ExecuteCommand(FormMain.DB_NAME, insert);

                MessageBoxExtend.messageOK("数据保存成功");

                load(tableName);
            }
            catch (Exception error)
            {
                MessageBoxExtend.messageWarning(error.Message);
                return;
            }
        }