⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 在VS2005下写的把SQLCE上的数据库数据导出为XML的应用程序
💻 CS
📖 第 1 页 / 共 4 页
字号:
                if (strfile.IndexOf("<T_pcm>") != -1)
                {
                    strfile = strfile.Replace("<T_pcm>", ",");
                    strfile = strfile.Replace("</T_pcm>\r", "");
                    strfile = strfile.Insert(0, "T_pcm,");
                }
                if (strfile.IndexOf("<T_igbt>") != -1)
                {
                    strfile = strfile.Replace("<T_igbt>", ",");
                    strfile = strfile.Replace("</T_igbt>\r", "");
                    strfile = strfile.Insert(0, "T_igbt,");
                }
                if (strfile.IndexOf("<T_stator>") != -1)
                {
                    strfile = strfile.Replace("<T_stator>", ",");
                    strfile = strfile.Replace("</T_stator>\r", "");
                    strfile = strfile.Insert(0, "T_stator,");
                }
                if (strfile.IndexOf("<T_rotor>") != -1)
                {
                    strfile = strfile.Replace("<T_rotor>", ",");
                    strfile = strfile.Replace("</T_rotor>\r", "");
                    strfile = strfile.Insert(0, "T_rotor,");
                }
                if (strfile.IndexOf("<T_cab>") != -1)
                {
                    strfile = strfile.Replace("<T_cab>", ",");
                    strfile = strfile.Replace("</T_cab>\r", "");
                    strfile = strfile.Insert(0, "T_cab,");
                }

                if (strfile.IndexOf("<Faults>") != -1)
                {
                    strfile = strfile.Replace("<Faults>", ",");
                    strfile = strfile.Replace("</Faults>\r", "");
                    strfile = strfile.Insert(0, "Faults,");
                }
                if (strfile.IndexOf("<Warnings>") != -1)
                {
                    strfile = strfile.Replace("<Warnings>", ",");
                    strfile = strfile.Replace("</Warnings>\r", "");
                    strfile = strfile.Insert(0, "Warnings,");
                }
                if (strfile.IndexOf("<Control>") != -1)
                {
                    strfile = strfile.Replace("<Control>", ",");
                    strfile = strfile.Replace("</Control>\r", "");
                    strfile = strfile.Insert(0, "Control,");
                }
                if (strfile.IndexOf("<Status>") != -1)
                {
                    strfile = strfile.Replace("<Status>", ",");
                    strfile = strfile.Replace("</Status>\r", "");
                    strfile = strfile.Insert(0, "Status,");
                }
                if (strfile.IndexOf("<Mode>") != -1)
                {
                    strfile = strfile.Replace("<Mode>", ",");
                    strfile = strfile.Replace("</Mode>\r", "");
                    strfile = strfile.Insert(0, "Mode,");
                }
                if (strfile.IndexOf("<t_dis>") != -1)
                {
                    strfile = strfile.Replace("<t_dis>\r", ",");
                    strfile = strfile.Replace("</t_dis>\r", "");
                    strfile = strfile.Insert(0, "t_dis,");
                }
                if (strfile.IndexOf("<P_busF>") != -1)
                {
                    strfile = strfile.Replace("<P_busF>", ",");
                    strfile = strfile.Replace("</P_busF>\r", "");
                    strfile = strfile.Insert(0, "P_busF,");
                }
                if (strfile.IndexOf("<I_busF>") != -1)
                {
                    strfile = strfile.Replace("<I_busF>", ",");
                    strfile = strfile.Replace("</I_busF>\r", "");
                    strfile = strfile.Insert(0, "I_busF,");
                }
                if (strfile.IndexOf("<P_bus>") != -1)
                {
                    strfile = strfile.Replace("<P_bus>", ",");
                    strfile = strfile.Replace("</P_bus>\r", "");
                    strfile = strfile.Insert(0, "P_bus,");
                }
                if (strfile.IndexOf("<I_bus>") != -1)
                {
                    strfile = strfile.Replace("<I_bus>", ",");
                    strfile = strfile.Replace("</I_bus>\r", "");
                    strfile = strfile.Insert(0, "I_bus,");
                }
                if (strfile.IndexOf("<V_bus>") != -1)
                {
                    strfile = strfile.Replace("<V_bus>", ",");
                    strfile = strfile.Replace("</V_bus>\r", "");
                    strfile = strfile.Insert(0, "V_bus,");
                }
                if (strfile.IndexOf("<V_ext>") != -1)
                {
                    strfile = strfile.Replace("<V_ext>", ",");
                    strfile = strfile.Replace("</V_ext>\r", "");
                    strfile = strfile.Insert(0, "V_ext,");
                }
                if (strfile.IndexOf("<SOC>") != -1)
                {
                    strfile = strfile.Replace("<SOC>", ",");
                    strfile = strfile.Replace("</SOC>\r", "");
                    strfile = strfile.Insert(0, "SOC,");
                }

                if (strfile.IndexOf("<Speed>") != -1)
                {
                    strfile = strfile.Replace("<Speed>", "");
                    strfile = strfile.Replace("</Speed>\r", "");
                    strfile = strfile.Insert(0, "Speed");
                }

                if (strfile.IndexOf("<SN>") != -1)
                {
                    strfile = strfile.Replace("<SN>", ",");
                    strfile = strfile.Replace("</SN>\r", "");
                    strfile = strfile.Insert(0, "SN,");
                }
                if (strfile.IndexOf("<Time1>") != -1)
                {
                    strfile = strfile.Replace("<Time1>", ",");
                    strfile = strfile.Replace("</Time1>\r", "");
                    strfile = strfile.Insert(0, "Time1,");
                }
                if (strfile.IndexOf("<Date1>") != -1)
                {
                    strfile = strfile.Replace("<Date1>", ",");
                    strfile = strfile.Replace("</Date1>\r", "");
                    strfile = strfile.Insert(0, "Date1,");
                }
                if (strfile.IndexOf("<Type>") != -1)
                {
                    strfile = strfile.Replace("<Type>", ",");
                    strfile = strfile.Replace("</Type>\r", "");
                    strfile = strfile.Insert(0, "Type,");
                }

                strfile = strfile.Replace(" ", "");
                strfile = strfile.Replace(",\n,", "\n");
                strfile = strfile.Replace("\n,", "\n");

                FileStream fs1 = File.Create(filetxt);

                StreamWriter w = new StreamWriter(fs1, Encoding.GetEncoding(950));
                w.Write(strfile);
                w.Flush();
                fs1.Close();
                inputpack();
                outputpack();
            }
            catch (System.Exception e2)
            {
                listBox1.Items.Insert(0, "1 "+e2.Message);
            }
        }*/
        public class Xmlfile
        {
            String pack;
            DateTime dtdateold;
            DateTime dtdatenew;
            String CodePath;
            String Dbname;
            //private delegate listBox1="null";
            public Xmlfile(String Strpack, DateTime Ddtdateold, DateTime Ddtdatenew, String StrCodePath, String StrDbname)
            {
                pack=Strpack;
                dtdateold=Ddtdateold;
                dtdatenew = Ddtdatenew;
                CodePath = StrCodePath;
                Dbname = StrDbname;

            }
            public void CreatXml()
            {
                string StrText;

                SqlCeEngine objEg = new SqlCeEngine("Data Source=" + CodePath + "\\" + Dbname);
                SqlCeConnection objCon = new SqlCeConnection("Data Source=" + CodePath + "\\" + Dbname);
                SqlCeCommand objCom = new SqlCeCommand("select * from mytable", objCon);
                SqlCeDataAdapter adapterData = new SqlCeDataAdapter("SELECT * FROM mytable", objCon);
                objCon.Open();
                SqlCeConnection oCon = new SqlCeConnection("Data Source=" + CodePath + "\\" + Dbname);
                StrText = " where Date < @dtdatenew" + " and Type=" + "'" + pack + "'";
                SqlCeDataAdapter oDA = new SqlCeDataAdapter("select * from mytable" + StrText, oCon);
                oDA.SelectCommand.Parameters.Add("@dtdatenew", dtdatenew);
                try
                {
                    DataSet oDS = new DataSet(dtdateold.ToString());
                    oDA.Fill(oDS);
                    oDS.WriteXml(CodePath + "\\" + pack + "-" + dtdateold.Year.ToString().PadLeft(4, '0') + dtdateold.Month.ToString().PadLeft(2, '0') + dtdateold.Day.ToString().PadLeft(2, '0') + "-" + dtdatenew.Year.ToString().PadLeft(4, '0') + dtdatenew.Month.ToString().PadLeft(2, '0') + dtdatenew.Day.ToString().PadLeft(2, '0') + ".xml");
                    //listBox1.Items.Insert(0, pack + "-" + dtdateold.Year.ToString().PadLeft(4, '0') + dtdateold.Month.ToString().PadLeft(2, '0') + dtdateold.Day.ToString().PadLeft(2, '0') + "-" + dtdatenew.Year.ToString().PadLeft(4, '0') + dtdatenew.Month.ToString().PadLeft(2, '0') + dtdatenew.Day.ToString().PadLeft(2, '0') + ".xml Create.");
                    oDS.Dispose();
                }
                catch //(SqlCeException ex)
                {
                    //listBox1.Items.Insert(0, pack + "-" + dtdateold.Year.ToString().PadLeft(4, '0') + dtdateold.Month.ToString().PadLeft(2, '0') + dtdateold.Day.ToString().PadLeft(2, '0') + "-" + dtdatenew.Year.ToString().PadLeft(4, '0') + dtdatenew.Month.ToString().PadLeft(2, '0') + dtdatenew.Day.ToString().PadLeft(2, '0') + ".xml Create error.");
                    //listBox1.Items.Insert(0, ex.Message);
                }
                finally
                {
                    oDA.Dispose();
                }

                try
                {
                    objCom.CommandText = "delete from mytable" + StrText;
                    objCom.Parameters.Add("@dtdatenew", dtdatenew);
                    objCom.ExecuteNonQuery();
                    objCon.Close();
                }
                catch //(System.Exception e1)
                {
                    //listBox1.Items.Insert(0, "3 " + e1.Message);
                }
            }
        }


        //public void CreatXml(string pack, DateTime dtdateold, DateTime dtdatenew)
        //{
        //    string StrText;

        //    SqlCeEngine objEg = new SqlCeEngine("Data Source=" + CodePath + "\\" + Dbname);
        //    SqlCeConnection objCon = new SqlCeConnection("Data Source=" + CodePath + "\\" + Dbname);
        //    SqlCeCommand objCom = new SqlCeCommand("select * from mytable", objCon);
        //    SqlCeDataAdapter adapterData = new SqlCeDataAdapter("SELECT * FROM mytable", objCon);
        //    objCon.Open();
        //    SqlCeConnection oCon = new SqlCeConnection("Data Source=" + CodePath + "\\" + Dbname);
        //    StrText = " where Date < @dtdatenew" + " and Type=" + "'" + pack + "'";
        //    SqlCeDataAdapter oDA = new SqlCeDataAdapter("select * from mytable" + StrText, oCon);
        //    oDA.SelectCommand.Parameters.Add("@dtdatenew", dtdatenew);
        //    try
        //    {
        //        DataSet oDS = new DataSet(dtdateold.ToString());
        //        oDA.Fill(oDS);
        //        oDS.WriteXml(CodePath + "\\" + pack + "-" + dtdateold.Year.ToString().PadLeft(4, '0') + dtdateold.Month.ToString().PadLeft(2, '0') + dtdateold.Day.ToString().PadLeft(2, '0') + "-" + dtdatenew.Year.ToString().PadLeft(4, '0') + dtdatenew.Month.ToString().PadLeft(2, '0') + dtdatenew.Day.ToString().PadLeft(2, '0') + ".xml");
        //        listBox1.Items.Insert(0, pack + "-" + dtdateold.Year.ToString().PadLeft(4, '0') + dtdateold.Month.ToString().PadLeft(2, '0') + dtdateold.Day.ToString().PadLeft(2, '0') + "-" + dtdatenew.Year.ToString().PadLeft(4, '0') + dtdatenew.Month.ToString().PadLeft(2, '0') + dtdatenew.Day.ToString().PadLeft(2, '0') + ".xml Create.");
        //        oDS.Dispose();
        //    }
        //    catch (SqlCeException ex)
        //    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -