Exemple #1
0
        private void frmPrint_Load(object sender, EventArgs e)
        {
            this.Text += Application.ProductVersion;
            Control ctrl;
            string  txt;

            Model.refreshRestr(false);
            pnlProgressBar.SendToBack();

            RSComm.sErrorInfo sErr = Model.comm.openPort();
            if (sErr.hasError)
            {
                MessageBox.Show(sErr.errorMsg + "\r\n" + sErr.exceptionMsg, "Error opening serial port!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            }

            clLog.openLog(Model.OP, Model.Serial.Substring(0, 9));
            clLog.doLog(string.Format("==============={0}===============", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")));
            clLog.doLog("---------------> DATABASE DATA");

            pnlIntegral.Enabled     = chkIntegral.Checked = chkIntegral.Enabled = Model.hasIntegral;
            pnlRemoteSensor.Enabled = chkRemoteSensor.Checked = chkRemoteSensor.Enabled = Model.hasRemoteSensor;
            pnlTAG.Enabled          = chkTAG.Checked = chkTAG.Enabled = Model.hasTag;

            if (Debugger.IsAttached)
            {
                chkIntegral.Enabled     = true;
                chkRemoteSensor.Enabled = true;
                chkTAG.Enabled          = true;
            }

            // check if user can fill or change fields manually
            txt = Model.RestrSoft.getProp("manualFill").CurrValue;
            if (txt.Equals("Sim"))
            {
                pnlVariables.Enabled = true;
                txt = Model.RestrSoft.getProp("manualFillDate").CurrValue;
                if (!txt.isEmpty())
                {
                    DateTime dt;
                    if (DateTime.TryParse(txt, out dt))
                    {
                        pnlVariables.Enabled = ((DateTime.Now - dt).Minutes <= 0);
                    }
                }
                txt = Model.RestrSoft.getProp("manualFillOP").CurrValue;
                if (!txt.isEmpty())
                {
                    pnlVariables.Enabled = (Model.OP.StartsWith(txt));
                }
            }
            if (Debugger.IsAttached)
            {
                pnlVariables.Enabled = true;
            }
            txt = Model.RestrSoft.getProp("onlyUpload").CurrValue;
            chkOnlyUpload.Visible = chkSimulate.Visible = txt.AsString().Equals("Sim") || Debugger.IsAttached;
            chkSimulate.Checked   = Debugger.IsAttached;

            clLog.doLog("Integral enabled: " + Model.hasIntegral);
            clLog.doLog("Remote Sensor enabled: " + Model.hasRemoteSensor);
            clLog.doLog("Tag enabled: " + Model.hasTag);
            clLog.doLog("Only Tag:" + Model.hasOnlyTag);


            if (Model.hasIntegral)
            {
                ctrl = pnlIntegral;
                putText(ctrl, "MODEL", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("MODEL")).Value);
                putText(ctrl, "SUFFIX1", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SUFFIX1")).Value);
                putText(ctrl, "SUFFIX2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SUFFIX2")).Value);
                putText(ctrl, "STYLE", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("STYLE")).Value);
                putText(ctrl, "SIZE", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SIZE")).Value);
                putText(ctrl, "METERFACTORL", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("METERFACTORL")).Value);
                putText(ctrl, "METERFACTORH", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("METERFACTORH")).Value);
                putText(ctrl, "FLUIDPRESS", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("FLUIDPRESS")).Value);
                putText(ctrl, "FLUIDTEMP", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("FLUIDTEMP")).Value);
                putText(ctrl, "AMBTEMP", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("AMBTEMP")).Value);
                putText(ctrl, "SUPPLY1", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SUPPLY1")).Value);
                putText(ctrl, "SUPPLY2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SUPPLY2")).Value);
                putText(ctrl, "OUTPUT1", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("OUTPUT1")).Value);
                putText(ctrl, "OUTPUT2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("OUTPUT2")).Value);
                putText(ctrl, "OUTPUT3", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("OUTPUT3")).Value);
                putText(ctrl, "OUTPUT4", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("OUTPUT4")).Value);
                putText(ctrl, "YEARMONTH", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("YEARMONTH")).Value);
                putText(ctrl, "SERIAL", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SERIAL")).Value);
                putText(ctrl, "SERIAL2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SERIAL2")).Value);
                putText(ctrl, "TAG1", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("TAG1")).Value);
                //putText(ctrl, "TAG2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("TAG2")).Value);
            }
            if (Model.hasRemoteSensor)
            {
                ctrl = pnlRemoteSensor;
                putText(ctrl, "MODEL", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("MODEL")).Value);
                putText(ctrl, "SUFFIX1", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SUFFIX1")).Value);
                putText(ctrl, "SUFFIX2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SUFFIX2")).Value);
                putText(ctrl, "STYLE", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("STYLE")).Value);
                putText(ctrl, "SIZE", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SIZE")).Value);
                putText(ctrl, "METERFACTORL", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("METERFACTORL")).Value);
                putText(ctrl, "METERFACTORH", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("METERFACTORH")).Value);
                putText(ctrl, "FLUIDPRESS", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("FLUIDPRESS")).Value);
                putText(ctrl, "FLUIDTEMP", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("FLUIDTEMP")).Value);
                putText(ctrl, "AMBTEMP", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("AMBTEMP")).Value);
                putText(ctrl, "YEARMONTH", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("YEARMONTH")).Value);
                putText(ctrl, "SERIAL", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SERIAL")).Value);
                putText(ctrl, "SERIAL2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("SERIAL2")).Value);
                putText(ctrl, "TAG1", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("TAG1")).Value);
                //putText(ctrl, "TAG2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("TAG2")).Value);
                putText(ctrl, "COMBNO", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("COMBNO")).Value);
            }
            if (Model.hasTag || Model.hasOnlyTag)
            {
                ctrl = pnlTAG;
                putText(ctrl, "TAG1", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("TAG_TAG1")).Value);
                putText(ctrl, "TAG2", Model.PrintFieldData.FirstOrDefault(x => x.Key.Equals("TAG_TAG2")).Value);
            }
        }
Exemple #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string[] Param;
            this.Text += Application.ProductVersion;

            Properties.Settings.Default.drv            = clFacilities.PreparaDrv(Application.StartupPath);
            Properties.Settings.Default.drvProgramData = clFacilities.PreparaDrv(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + Application.ProductName);

            string drvServer;

            drvServer = clFacilities.getDrvServer(Properties.Settings.Default.drv + "Config.xml");
            if (drvServer.Equals(""))
            {
                drvServer = clFacilities.PreparaDrv(clFacilities.getDrvServer(Properties.Settings.Default.drvProgramData + "Config.xml"));
            }

            #region CONFIG.XML
            clXML  xml = new clXML(drvServer + "database\\dlls");
            clXML  xml2 = new clXML(drvServer + "database\\dlls");
            string txt1, txt2 = "";

            // verifica se a data do config.xml instalado é <> do que o do usuário, se sim, copia por cima o arquivo
            txt1 = xml2.getValue("Comum", "ATUALIZADOEM", Properties.Settings.Default.drv + "Config.xml");
            txt2 = xml.getValue("Comum", "ATUALIZADOEM", Properties.Settings.Default.drvProgramData + "Config.xml");
            if (txt1 != txt2 || txt2.Equals(""))
            {
                // cria a pasta
                try {
                    Directory.CreateDirectory(Properties.Settings.Default.drvProgramData);
                    // se o arquivo ainda não existe, então só copia o novo
                    if (!File.Exists(Properties.Settings.Default.drvProgramData + "Config.xml"))
                    {
                        File.Copy(Properties.Settings.Default.drv + "Config.xml", Properties.Settings.Default.drvProgramData + "Config.xml", true);
                    }
                    else
                    {
                        // como o arquivo já existe, então copia somente as chaves dentro de comum que contiverem o atributo de obrigatório
                        string Key   = "ATUALIZADOEM";
                        string Value = "";
                        List <KeyValuePair <string, string> > Attribs;
                        // já grava a primeira informação que é a data
                        xml.setValue("Comum", Key, txt1);
                        xml.setKeyAttrib("Comum", Key, "required", "1");
                        while (xml2.getNextNodeValueAndAttribs("Comum", ref Key, out Value, out Attribs))
                        {
                            try {
                                // don't change value if exists
                                xml.getValue("Comum", Key);
                                if (xml.getLastErrorInfo.hasError)
                                {
                                    xml.setValue("Comum", Key, Value);
                                }
                                // change value even if it exists but only if has attributes
                                foreach (KeyValuePair <string, string> item in Attribs)
                                {
                                    xml.setValue("Comum", Key, Value);
                                    xml.setKeyAttrib("Comum", Key, item.Key, item.Value);
                                }
                            } catch { }
                        }
                        xml.saveFile("");
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message.ToString(), "Erro ao copiar arquivo de definições!");
                    this.Dispose();
                    return;
                }
            }
            xml2.Dispose();
            #endregion

            // pega a localização do servidor de banco de dados
            Properties.Settings.Default.drvServer       = clFacilities.PreparaDrv(xml.getValue("Comum", "drvServer", Properties.Settings.Default.drvProgramData + "Config.xml"));
            Properties.Settings.Default.drvDB           = clFacilities.PreparaDrv(xml.getValue("Comum", "drvDB", Properties.Settings.Default.drvProgramData + "Config.xml"));
            Properties.Settings.Default.drvDatabase     = clFacilities.PreparaDrv(xml.getValue("Comum", "drvDataBase", Properties.Settings.Default.drvProgramData + "Config.xml"));
            Properties.Settings.Default.drvMicrosigaTXT = clFacilities.PreparaDrv(xml.getValue("Comum", "drvMicrosigaTXT", Properties.Settings.Default.drvProgramData + "Config.xml"));

            Properties.Settings.Default.commPort     = xml.getValue("Comum", "CommPort", Properties.Settings.Default.drvProgramData + "Config.xml");
            Properties.Settings.Default.commSettings = xml.getValue("Comum", "CommSettings", Properties.Settings.Default.drvProgramData + "Config.xml");
            if (Properties.Settings.Default.commPort.isEmpty())
            {
                Properties.Settings.Default.commPort = "COM1";
            }
            if (Properties.Settings.Default.commSettings.isEmpty())
            {
                Properties.Settings.Default.commSettings = "9600,n,8,1";
            }

            if (!(txt1 = xml.getValue("Comum", "limitIntegralSUFIX1")).isEmpty())
            {
                Properties.Settings.Default.limitIntegralSUFIX1 = int.Parse(txt1);
            }
            if (!(txt1 = xml.getValue("Comum", "limitIntegralSUFIX2")).isEmpty())
            {
                Properties.Settings.Default.limitIntegralSUFIX2 = int.Parse(txt1);
            }
            if (!(txt1 = xml.getValue("Comum", "limitIntegralTAG1")).isEmpty())
            {
                Properties.Settings.Default.limitIntegralTAG1 = int.Parse(txt1);
            }
            if (!(txt1 = xml.getValue("Comum", "limitIntegralTAG2")).isEmpty())
            {
                Properties.Settings.Default.limitIntegralTAG2 = int.Parse(txt1);
            }
            if (!(txt1 = xml.getValue("Comum", "limitTagTAG1")).isEmpty())
            {
                Properties.Settings.Default.limitTagTAG1 = int.Parse(txt1);
            }
            if (!(txt1 = xml.getValue("Comum", "limitTagTAG2")).isEmpty())
            {
                Properties.Settings.Default.limitTagTAG2 = int.Parse(txt1);
            }
            //Properties.Settings.Default.clearTML = bool.Parse(xml.getValue("Comum", "clearTML"));

            xml.Dispose();
            getConfigData(); // get all restrictions and remote configurations for this software

            txtBarCode.Enabled = DBLayer.Connect(Properties.Settings.Default.drvDB + "PRODUCT.mdb");

            Model.comm = new RSComm.cRSComm(Properties.Settings.Default.drvDatabase + "dlls");
            Model.comm.dataReceived += Comm_dataReceived;
            Model.comm.timeOutEvent += Comm_timeOutEvent;
            Param = Properties.Settings.Default.commSettings.Split(',');
            System.IO.Ports.StopBits sb = System.IO.Ports.StopBits.None;
            System.IO.Ports.Parity   pt = System.IO.Ports.Parity.None;
            switch (Param[3])
            {
            case "0": sb = System.IO.Ports.StopBits.None; break;

            case "1": sb = System.IO.Ports.StopBits.One; break;

            case "2": sb = System.IO.Ports.StopBits.Two; break;
            }
            switch (Param[1])
            {
            case "n": pt = System.IO.Ports.Parity.None; break;

            case "e": pt = System.IO.Ports.Parity.Even; break;

            case "o": pt = System.IO.Ports.Parity.Odd; break;
            }
            RSComm.sErrorInfo sError = Model.comm.openPort(Properties.Settings.Default.commPort, int.Parse(Param[0]), int.Parse(Param[2]), sb, 5000, false, false, Encoding.UTF8, System.IO.Ports.Handshake.None, pt);
            if (sError.hasError)
            {
                MessageBox.Show(sError.errorMsg + "\r\n" + sError.exceptionMsg, "Serial port invalid!" + Properties.Settings.Default.commPort);
                //Application.Exit();
                //return;
            }
            Model.comm.closePort(); // keep it closed and free to use by another applications

            txtBarCode.Tag = "";

            Model.refreshRestr(true);

            // examples to test
            // B1V201531, B1V290001   INTEGRAL
            // B1V201963    REMOTE SENSOR
        }