Beispiel #1
0
        private void updateStatusBar()
        {
            String avaliableDays = (Codes.inAvaliationMode() ? " - " + Codes.getAvaliableDays() + " dias restantes" : "");

            main_version_label.Text = "Versão: " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + " - " + (Codes.checkValidation() ? "Ativado" : "Em periodo de avaliação" + avaliableDays);
        }
Beispiel #2
0
        private void keyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control)
            {
                if (e.KeyCode == Keys.S)   // Ctrl + S
                {
                    MessageBox.Show("dfs");
                }
                else
                if (e.KeyCode == Keys.F2)   // Ctrl + F2
                {
                    if (!(Codes.checkValidation()))
                    {
                        new ValidationForm().ShowDialog();
                    }
                    updateStatusBar();
                }
            }
            else
            if (e.KeyCode == Keys.F1)
            {
                //Properties.Settings.Default.AVALIATION_DATE = "02/02/2017 00:00:00";
                new AjudaForm().ShowDialog();
            }
            else
            if (e.KeyCode == Keys.F2)
            {
                /*SqlConnection connection;
                 * try {
                 *  connection = new SqlConnection("Data Source = banco_de_dados.sdf");
                 *  connection.Open();
                 *  SqlCommand cmd = new SqlCommand("SELECT * FROM dispesas WHERE id = @id", connection);
                 *  cmd.Parameters.AddWithValue("@id", 1);
                 *  SqlDataReader re = cmd.ExecuteReader();
                 *
                 *  if (re.Read()) {
                 *      MessageBox.Show(re ["produto"].ToString());
                 *  } else {
                 *      MessageBox.Show("Please enter a valid item barcode");
                 *  }
                 * } catch (SqlException ex) {
                 *  MessageBox.Show(ex.ToString());
                 * }*/
            }
            else
            if (e.KeyCode == Keys.F5)
            {
                new Cadastro_Orcamento().ShowDialog();
            }
            else
            if (e.KeyCode == Keys.F6)
            {
                new Cadastro_Dispesa().ShowDialog();
            }
            else
            if (e.KeyCode == Keys.F7)
            {
                new Cadastro_Cliente().ShowDialog();
            }
            else
            if (e.KeyCode == Keys.F8)
            {
                //new Cadastro_Carro().ShowDialog();
                new Orcamentos().ShowDialog();
            }
            else
            // ************************* //
            if (e.KeyCode == Keys.F9)
            {
                new Dispesas().ShowDialog();
            }
            else
            if (e.KeyCode == Keys.F10)
            {
                new Servicos().ShowDialog();

                /*String placa = new Carros().getCarroPlaca();
                 * SqlCeConnection connection = new SqlCeConnection(Properties.Settings.Default.DataConnectionString);
                 * connection.Open();
                 *
                 * if (!(placa.Length > 0)) { MessageBox.Show("Nenhum carro selecionado", "Carro selecionado"); return; }
                 * SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM carros WHERE placa = @placa", connection);
                 * cmd.Parameters.AddWithValue("@placa", placa);
                 * SqlCeDataReader re = cmd.ExecuteReader();
                 *
                 * if (re.Read()) {
                 *  MessageBox.Show(re ["placa"].ToString() + "\n" + re ["modelo"].ToString(), "Carro selecionado");
                 * } else {
                 *  MessageBox.Show("Please enter a valid item barcode");
                 * }
                 *
                 * re.Close();
                 *
                 * connection.Close();
                 * /*int id = new Clientes().getClienteID();
                 * SqlCeConnection connection = new SqlCeConnection(Properties.Settings.Default.DataConnectionString);
                 * connection.Open();
                 *
                 * if (!(id > 0)) { MessageBox.Show("Nenhum cliente selecionado", "Cliente selecionado"); return; }
                 * SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM clientes WHERE id = @id", connection);
                 * cmd.Parameters.AddWithValue("@id", id);
                 * SqlCeDataReader re = cmd.ExecuteReader();
                 *
                 * if (re.Read()) {
                 *  MessageBox.Show(re ["nome"].ToString(), "Cliente selecionado");
                 * } else {
                 *  MessageBox.Show("Please enter a valid item barcode");
                 * }
                 *
                 * re.Close();
                 *
                 * connection.Close();*/
            }
            else
            if (e.KeyCode == Keys.F11)
            {
                new Clientes().ShowDialog();
            }
            else
            if (e.KeyCode == Keys.F12)
            {
                new Carros().ShowDialog();
            }
        }
Beispiel #3
0
        //[System.Runtime.InteropServices.DllImport("user32.dll")]
        //[return: MarshalAs(UnmanagedType.Bool)]
        //static extern bool SetForegroundWindow(IntPtr hWnd);
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            String contate = "\nPor favor, contate o suporte técnico.";

            //AppDomain.CurrentDomain.SetData("DataDirectory", "C:\\Users\\Davi\\AppData\\Roaming\\DaviApps\\JC Mecanica");
            //AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DaviApps\\JC Mecanica\\");

            if (!File.Exists("banco_de_dados.sdf"))
            {
                AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DaviApps\\JC Mecanica\\");
                //AppDomain.CurrentDomain.SetData("DataDirectory", "\\");
            }

            // CHECK DCODE DLL

            if (!File.Exists("DCode.dll"))
            {
                MessageBox.Show("Arquivo dll 'DCode' não encontrado." + contate, "DLL Error");
                return;
            }

            String settingsFolder = (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DaviApps\\JC Mecanica\\settings\\");

            validation = new DCodePreferences(new DCodeFile(settingsFolder + "validation.DCode"));
            //_validation = new DCodePreferences(new DCodeFile(settingsFolder + "vali.DCode"));
            settings = new DCodePreferences(new DCodeFile(settingsFolder + "settings.DCode"));

            // DEFINE DEFAULT VALIDATION
            validation.Add("ACTIVED.CODE", "");
            validation.Add("AVALIATION.DATE", "");
            //validation.Set("avaliationDate", "Teste");
            //validation.Set("activeCode", "Teste2");
            validation.save();
            // DEFINE DEFAULT SETTINGS
            //settings.Add("teste", "23");
            //settings.Remove("teste");
            //settings.Set("teste", "f");
            //settings.save();
            //MessageBox.Show(settings.Get("teste", "Não encontrado"));

            //MessageBox.Show(validation.Get("teste", "Não encontrado"));
            //MessageBox.Show(validation.Get("activeCode", "Não encontrado"));

            //AppDomain.CurrentDomain.SetData("SettingsDiretory", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DaviApps\\JC Mecanica\\Settings\\");

            UpdateDB.CHECK();

            /*bool createdNew = true;
             * using (Mutex mutex = new Mutex(true, "JC_Mecanica", out createdNew)) {
             *  if (createdNew) {
             *      Application.EnableVisualStyles();
             *      Application.SetCompatibleTextRenderingDefault(false);
             *      Application.Run(new MainForm());
             *  } else {
             *      Process current = Process.GetCurrentProcess();
             *      foreach (Process process in Process.GetProcessesByName(current.ProcessName)) {
             *          if (process.Id != current.Id) {
             *              //SetForegroundWindow(process.MainWindowHandle);
             *              break;
             *          }
             *      }
             *  }
             * }*/

            /*DB_INFO.INIT();
             *
             * if (DB_INFO.DB_VERSION < Properties.Settings.Default.DB_VERSION) {
             *  if (DB_INFO.DB_VERSION == 1.0) {
             *      //DB_INFO.EXECUTE("UPDATE DB_INFO SET value = 1,5 WHERE name = DB_VERSION");
             *  }
             * }
             *
             * //MessageBox.Show(Codes.getAvaliableDays() + " - " + Codes.inAvaliationMode());*/

            /* Create dispesas table
             * create table dispesas (
             *          id int not null AUTO_INCREMENT,
             *      produto varchar(20) not null,
             *      valor decimal not null,
             *      count int not null,
             *      data timestamp default now(),
             *          primary key (id)
             *  )
             */

            bool close = false;

            if (!Codes.checkValidation())
            {
                if (!Codes.inAvaliationMode())
                {
                    new ValidationForm().ShowDialog();
                }
                close = !Codes.checkValidation() && !Codes.inAvaliationMode();
            }

            if (close)
            {
                return;
            }

            //MessageBox.Show(Codes.removeDot(Assembly.GetExecutingAssembly().GetName().Version.ToString()));

            //UpdateDB.SET_VALUE("DB_VERSION", "1,23");

            //MessageBox.Show(DB_INFO.DB_VERSION + "");
            //MessageBox.Show(UpdateDB.GET_DB_VERSION() + "");

            /*string str;
             *
             * SqlCeConnection mycon = new SqlCeConnection("Data Source = banco_de_dados.sdf");
             * str = "CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] banco_de_dados" +
             *    "";
             * str = "CREATE DATABASE [banco_de_dados2] CONTAINMENT = NONE ON PRIMARY" +
             *          "(NAME=N'Masalehforoshi'," +
             *          @"FILENAME=N'C:\data\Masalehforoshi.mdf' " +
             *          ",SIZE=3072KB,MAXSIZE=UNLIMITED,FILEGROWTH=1024KB)" +
             *          "LOG ON (NAME=N'Masalehforoshi_log.', " +
             *          @"FILENAME=N'C:\Masalehforoshi_log.ldf' " +
             *          ",SIZE=1024KB,MAXSIZE=2048GB,FILEGROWTH=10%)";
             *
             * SqlCeCommand mycommand = new SqlCeCommand(str, mycon);
             *
             * try {
             *  mycommand.Connection.Open();
             *  mycommand.ExecuteNonQuery();
             * } catch (Exception ex) {
             *  MessageBox.Show(ex.ToString(), "myprogram", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             * } finally {
             *  if (mycon.State == ConnectionState.Open) {
             *      mycon.Close();
             *  }
             * }*/
            /*SqlCeConnection connection;
             * try {
             *  connection = new SqlCeConnection(Properties.Settings.Default.DataConnectionString);
             *  connection.Open();
             * } catch (SqlException ex) {
             *  MessageBox.Show("Arquivo de banco de dados não encontrado." + contate, "Erro de inicialização", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *  return;
             * }
             *
             * connection.Close();*/

            if (!File.Exists(AppDomain.CurrentDomain.GetData("DataDirectory") + "banco_de_dados.sdf"))
            {
                MessageBox.Show("Arquivo de banco de dados não encontrado." + contate, "Erro de inicialização", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //Application.Run(new MainForm());
                bool createdNew = true;
                using (Mutex mutex = new Mutex(true, "JC_Mecanica", out createdNew)) {
                    if (createdNew)
                    {
                        Application.Run(new MainForm());
                    }
                    else
                    {
                        Process current = Process.GetCurrentProcess();
                        foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                        {
                            if (process.Id != current.Id)
                            {
                                //BringWindowToFront();

                                /*process.WaitForInputIdle();
                                 * var processes = Process.GetProcessesByName("JC_Mecanica.exe");
                                 * if (processes.Any()){
                                 *  //I can't currently tell the window's state,
                                 *  //so I both restore and activate it
                                 *  var handle = processes.First().MainWindowHandle;
                                 *  ShowWindow(handle, SW_SHOWMAXIMIZED); //GRR!!!
                                 *  SetForegroundWindow(handle);
                                 *  //return true;
                                 * }*/
                                //SetForegroundWindow(process.MainWindowHandle);
                                //process.WindowState = FormWindowState.Maximized;
                                //Invoke(new MethodInvoker(delegate { this.WindowState = FormWindowState.Normal; }));
                                //Invoke(new Action(() => { this.WindowState = FormWindowState.Normal; }));
                                //process.CloseMainWindow();
                                //new MainForm().ShowDialog();
                                //process.Kill();
                                //((Form) process.MainWindowHandle).WindowState = System.Windows.Forms.FormWindowState.Maximized;
                                //process.Start();
                                break;
                            }
                        }
                    }
                }
            }
        }