Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using MaterialSkin;
  12. using MaterialSkin.Controls;
  13. using SQLite;
  14.  
  15. namespace Auto
  16. {
  17. public partial class Form1 : MaterialForm
  18. {
  19. public SQLiteConnection connection;
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. var materialSkinManager = MaterialSkinManager.Instance;
  24. materialSkinManager.AddFormToManage(this);
  25. materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
  26. // Configure color schema
  27. materialSkinManager.ColorScheme = new ColorScheme(
  28. Primary.Blue400, Primary.Blue500,
  29. Primary.Blue500, Accent.LightBlue200,
  30. TextShade.WHITE
  31. );
  32.  
  33. }
  34.  
  35. private void Form1_Load(object sender, EventArgs e)
  36. {
  37. initialize();
  38. using (connection)
  39. {
  40. connection.CreateTable<Helpers.Clients>();
  41. }
  42. UpdateListView();
  43. }
  44.  
  45. private void materialFlatButton1_Click(object sender, EventArgs e)
  46. {
  47. using (Form2 form2 = new Form2())
  48. {
  49. if (form2.ShowDialog() == DialogResult.OK)
  50. {
  51. UpdateListView();
  52. }
  53. }
  54. }
  55.  
  56. private void UpdateListView()
  57. {
  58. initialize();
  59. materialListView1.Items.Clear();
  60. var table = connection.Table<Helpers.Clients>();
  61. foreach (var client in table.Reverse())
  62. {
  63. ListViewItem item = new ListViewItem(client.id.ToString());
  64. item.SubItems.Add(client.name);
  65. item.SubItems.Add(client.phone);
  66. materialListView1.Items.Add(item);
  67. }
  68. }
  69.  
  70. private void initialize()
  71. {
  72.  
  73. string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
  74. path = path + @"\AutoBase";
  75. if (!Directory.Exists(path))
  76. {
  77. DirectoryInfo di = Directory.CreateDirectory(path);
  78. }
  79. string db_path = Path.Combine(path, "clients.db3");
  80. connection = new SQLiteConnection(db_path);
  81. }
  82.  
  83. private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
  84. {
  85. initialize();
  86. using (connection)
  87. {
  88. for (int i = 0; i < materialListView1.SelectedItems.Count; i++)
  89. {
  90. Console.WriteLine(materialListView1.SelectedItems[i].Text);
  91. connection.Query<Helpers.Clients>("delete from Clients where id = " + materialListView1.SelectedItems[i].Text);
  92.  
  93. }
  94. }
  95. UpdateListView();
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement