Exemplo n.º 1
0
        private void updateTableData(object sender, RoutedEventArgs e)
        {
            string sql    = string.Format("update material set m_name='{0}',m_density='{1}',m_color='{2}' where ID=", currentMaterial.Text, currentDensity.Text, currentColor.Text) + currentID.Text;
            bool   result = adb.updateTableData(sql);

            if (!result)
            {
                MessageBox.Show("更新失败!", "警告");
            }
        }
Exemplo n.º 2
0
        private void updateDatabaseMaterial(Dictionary <string, Dictionary <string, string> > update_dict)
        {
            //只添加新创建的材料,已有的材料就不添加了
            ArrayList result = adb.queryALLMaterialFromTable("select * from Material");

            bool   isHaveMaterial = false;
            string materialName   = ((Dictionary <string, string>)((Dictionary <string, Dictionary <string, string> >)update_dict)["materialName"])["content"];

            for (int j = 0; j < result.Count; j++)
            {
                if (materialName == ((ArrayList)result[j])[1].ToString())
                {
                    isHaveMaterial = true;
                    break;
                }
            }

            if (isHaveMaterial == true)
            {
                string matName = ((Dictionary <string, string>)((Dictionary <string, Dictionary <string, string> >)update_dict)["matName"])["content"];
                string eosName = ((Dictionary <string, string>)((Dictionary <string, Dictionary <string, string> >)update_dict)["soeName"])["content"];
                Dictionary <string, string> matData = (Dictionary <string, string>)((Dictionary <string, Dictionary <string, string> >)update_dict)["mat"];
                Dictionary <string, string> eosData = (Dictionary <string, string>)((Dictionary <string, Dictionary <string, string> >)update_dict)["soe"];
                string refer   = ((Dictionary <string, string>)((Dictionary <string, Dictionary <string, string> >)update_dict)["refer"])["content"];
                string density = ((Dictionary <string, string>)((Dictionary <string, Dictionary <string, string> >)update_dict)["density"])["content"];
                string color   = ((Dictionary <string, string>)((Dictionary <string, Dictionary <string, string> >)update_dict)["color"])["content"];
                string mid     = matData["MID"];
                string eosid   = eosData["EOSID"];

                //更新一条材料   需要更新三个表
                bool   success;
                string matTableName = "Mat_" + matName;
                string eosTableName = "Eos_" + eosName;

                //组装sql语句
                //插入mat表
                string matSql1 = "update " + matTableName;
                string matSql2 = " set ";
                for (int k = 0; k < matData.Count; k++)
                {
                    matSql2 += matData.Keys.ElementAt(k) + '=' + matData[matData.Keys.ElementAt(k)];

                    if (k != matData.Count - 1)
                    {
                        matSql2 += ",";
                    }
                }
                matSql2 += " where MID='" + mid + "'";
                string matsql = matSql1 + matSql2;
                success = adb.updateTableData(matsql);
                if (success)
                {
                    Console.WriteLine("更新mat表成功");
                }
                else
                {
                    Console.WriteLine("更新mat表失败");
                }

                //插入eos表
                string eosSql1 = "update " + eosTableName;
                string eosSql2 = " set ";
                for (int l = 0; l < eosData.Count; l++)
                {
                    eosSql2 += eosData.Keys.ElementAt(l) + '=' + eosData[eosData.Keys.ElementAt(l)];

                    if (l != eosData.Count - 1)
                    {
                        eosSql2 += ",";
                    }
                }
                eosSql2 += " where EOSID='" + eosid + "'";
                string eosSql = eosSql1 + eosSql2;
                success = adb.updateTableData(eosSql);
                if (success)
                {
                    Console.WriteLine("更新eos表成功");
                }
                else
                {
                    Console.WriteLine("更新eos表失败");
                }

                //插入material表
                //得到material表字段名
                List <string> matFieldName       = adb.GetTableFieldNameList("Material");
                string        materialSql1       = "update Material";
                string        materialSql2       = " set ";
                ArrayList     materialType       = adb.queryALLMaterialFromTable("select * from Material_Type where mat_name ='" + matName + "'");
                string        material_type_name = ((ArrayList)materialType[0])[1].ToString();
                materialSql2 += matFieldName[1] + "='" + materialName + "'," + matFieldName[2] + "='" + material_type_name + "'," + matFieldName[3] + "='" + mid.ToString() + "'," + matFieldName[4] + "='" + eosid.ToString() + "'," + matFieldName[5] + "='" + refer + "'," + matFieldName[6] + "='" + density + "'," + matFieldName[7] + "='" + color + "'";
                materialSql2 += " where material_name='" + materialName + "'";
                string materialSql = materialSql1 + materialSql2;
                success = adb.updateTableData(materialSql);
                if (success)
                {
                    Console.WriteLine("更新materila表成功");
                }
                else
                {
                    Console.WriteLine("更新materila表失败");
                }
            }
            else
            {
                System.Windows.MessageBox.Show("该材料不在数据库中", "警告");
                return;
            }
        }