public Setting()
 {
     InitializeComponent();
     Expend.LoadImage(btn_Open, @"Texture\pic_File.png");
     settingsAdapter = new AppSettingsAdapter();
     //INI
     if (!File.Exists("Setting.ini") || !File.Exists(INIHelper.ContentValue("ALL", "ExcelPath", ProgramPath + "Setting.ini")))
     {
         MessageBox.Show("这或许是你第一次使用本产品,请从计算机中打开一个Excel表格作为你的计划表");
         StreamWriter writer = new StreamWriter("Setting.ini");
         writer.WriteLine("[ALL]");
         writer.WriteLine("ExcelPath=");
         writer.WriteLine("Sheet=");
         writer.Close();
         OpenFileDialog open = new OpenFileDialog();
         open.ShowDialog();
         while (open.FileName == "")
         {
             open.ShowDialog();
         }
         SourcePath = open.FileName;
         INIHelper.WritePrivateProfileString("ALL", "ExcelPath", SourcePath, ProgramPath + "Setting.ini");
         INIHelper.WritePrivateProfileString("ALL", "Sheet", ChoosenSheet, ProgramPath + "Setting.ini");
     }
     else
     {
         LoadFromINI();
     }
 }
Exemple #2
0
        public TaskSetting(TaskInformation Task)
        {
            InitializeComponent();
            Expend.LoadImage(btn_Open, @"Texture\pic_File.png");

            this.Title = string.Format("{0} - TaskSettings", Task.Name);

            xmlDoc.Load("TaskSetting.xml");
            XmlNode root = xmlDoc.FirstChild;

            txt_Name.Text = Task.Name;
            XmlElement ele = null;

            foreach (XmlElement xe in root.ChildNodes)
            {
                if (Task.Name.Contains(xe.GetAttribute("Name")))
                {
                    if (ele == null || xe.GetAttribute("Name").Length > ele.GetAttribute("Name").Length)
                    {
                        ele = xe;
                    }
                }
            }
            if (ele == null)//如果不在XML表
            {
                ele = xmlDoc.CreateElement("SETTING");
                ele.SetAttribute("Name", Task.Name);
                ele.SetAttribute("AimSource", "");
                root.AppendChild(ele);
            }
            else
            {
                txt_Name.Text      = ele.GetAttribute("Name");
                txt_AimSource.Text = ele.GetAttribute("AimSource");
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //UI

            this.Icon = new BitmapImage(new Uri(@"ICON.ico", UriKind.Relative));
            Expend.LoadImage(btn_Mode_Setting, @"Texture\pic_Setting.png");

            this.Left = SystemParameters.WorkArea.Width - this.Width;
            this.Top  = 0;
            xaml      = System.Windows.Markup.XamlWriter.Save(grid_Task_Exmaple);

            this.ResizeMode = ResizeMode.NoResize;

            lab_Title.Content = "今天是:" + DateTime.Today.Date.ToString().Split(' ')[0];
            grid_Tasks.Children.Remove(grid_Task_Exmaple);

            try
            {
                LoadTaskFromDatabase();
            }
            catch
            {
            }
        }
        private void txt_Confirm_Click(object sender, RoutedEventArgs e)
        {
            string strExcelFileName = @"D:\test.xlsx";
            string strConn;

            if (strExcelFileName.Split('.').Last() == "xls")
            {
                strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strExcelFileName + ";" + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=0\"";
            }
            else
            {
                strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + strExcelFileName + ";" + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=0\"";
            }
            OleDbConnection myConn = new OleDbConnection(strConn);
            string          strCom = "select * from [Sheet1$]";

            myConn.Open();

            OleDbDataAdapter    myCommand = new OleDbDataAdapter(strCom, myConn);
            OleDbCommandBuilder builder   = new OleDbCommandBuilder(myCommand);

            //QuotePrefix和QuoteSuffix主要是对builder生成InsertComment命令时使用。
            builder.QuotePrefix = "["; //获取insert语句中保留字符(起始位置)
            builder.QuoteSuffix = "]"; //获取insert语句中保留字符(结束位置)
            DataSet ds = new DataSet();

            myCommand.Fill(ds, "[Sheet1$]");
            DataTable dt = ds.Tables["[Sheet1$]"];

            dt.PrimaryKey = new DataColumn[1] {
                dt.Columns[0]
            };
            if (!dt.Columns.Contains(txt_Name.Text))
            {
                dt.Columns.Add(txt_Name.Text);
            }
            for (DateTime Date = Expend.DateTimeParse(txt_From_Year, txt_From_Month, txt_From_Day);
                 Date < Expend.DateTimeParse(txt_From_Year, txt_From_Month, txt_From_Day) + TimeSpan.FromDays(int.Parse(txt_Num.Text) * int.Parse(txt_Span.Text));
                 Date += TimeSpan.FromDays(int.Parse(txt_Span.Text)))
            {
                DataRow aimRow = null;
                foreach (DataRow r in dt.Rows)
                {
                    if (r[0] != null || (DateTime)r[0] == Date)
                    {
                        aimRow = r;
                        break;
                    }
                }
                if (aimRow == null)
                {
                    aimRow    = dt.NewRow();
                    aimRow[0] = Date;
                    dt.Rows.Add(aimRow);
                }
                aimRow[txt_Name.Text] = txt_Name.Text;
            }

            myCommand.Update(ds, "[Sheet1$]");
            myConn.Close();
        }