Ejemplo n.º 1
0
        private void InButton_Click(object sender, EventArgs e)
        {
            try
            {
                int delivery;
                if (DeliveryNo.Checked)
                {
                    delivery = 0;
                }
                else
                {
                    delivery = 1;
                }
                if (!checkFields())
                {
                }
                else
                {
                    int Visiting = getWorker();
                    int res      = -1;
                    res = getPerson();
                    if (res <= 0)
                    {
                        MessageBox.Show("-----");
                        addPerson();
                        res = getPerson();
                    }
                    int           company = getCompany();
                    StringBuilder sb      = new StringBuilder();
                    sb.Append("INSERT INTO Visits(PersonID,CompanyID,Delivery,Entrance,Out,WorkerId,cardNumber,VisitingCompany,State,Address, Comment) " +
                              "VALUES(@PersonID,@CompanyID,@Delivery,@Entrance,@Out,@WorkerId,@cardNumber,@VisitingCompany,@State,@Address,@Comment)");

                    using (SqlCommand com = new SqlCommand(sb.ToString(), connection))
                    {
                        com.Parameters.Add("@PersonID", SqlDbType.Int).Value             = res;
                        com.Parameters.Add("@CompanyID", SqlDbType.Int).Value            = company;
                        com.Parameters.Add("@Delivery", SqlDbType.Bit).Value             = delivery;
                        com.Parameters.Add("@Entrance", SqlDbType.DateTime).Value        = DateTime.Now;
                        com.Parameters.Add("@Out", SqlDbType.DateTime).Value             = DBNull.Value;
                        com.Parameters.Add("@WorkerId", SqlDbType.Int).Value             = Visiting;
                        com.Parameters.Add("@cardNumber", SqlDbType.Int).Value           = checkCard(cardNBox.Text);
                        com.Parameters.Add("@VisitingCompany", SqlDbType.NVarChar).Value = valuesCheck(Companybox.Text);
                        com.Parameters.Add("@State", SqlDbType.Bit).Value        = 0;
                        com.Parameters.Add("@Address", SqlDbType.NVarChar).Value = addressBox.Text;
                        com.Parameters.Add("@Comment", SqlDbType.NVarChar).Value = commentBox.Text;

                        com.CommandType = CommandType.Text;

                        com.Connection = connection;

                        connection.Open();

                        String output = com.CommandText.ToString();
                        com.ExecuteNonQuery();
                        SqlTransaction trans = connection.BeginTransaction();
                        trans.Commit();
                        MessageBox.Show("Data Inserted!");
                    }
                    connection.Close();
                    clearFields();
                    groupBox1.Hide();
                    VisitingCombo.Hide();
                    VCompAdd.Hide();
                    CompCombo.Hide();
                    VisitingAdd.Hide();
                    VisitingLabel.Hide();
                    CompLabel.Hide();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            connection.Close();

            VisitorsLabel.Text = getVisitors();
        }
Ejemplo n.º 2
0
        public PostisVisitor()
        {
            this.Name = null;
            using (StreamReader reader = new StreamReader("daysToReset.txt"))
            {
                String line = reader.ReadLine();
                days = Int32.Parse(line.Split(null)[3]);
            }
            this.Name = null;

            using (StreamReader reader = new StreamReader("connectDBstring.txt"))
            {
                string line = reader.ReadLine();
                //line.Replace("/", "\\");
                connectStr = line;
            }
            //connectStr = "Data Source=192.168.1.101"+@"\MSSQLSERVER01"+ ",1433;Network Library=DBMSSOCN;Initial Catalog=PostisVisitor;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            InitializeComponent();

            connection = new SqlConnection(connectStr);

            Login log = new Login(connection);

            log.ShowDialog();
            admin = log.getType();
            log.Close();
            visitorsTime();

            if (!admin)
            {
                Configure.Hide();
                Report.Hide();
            }
            groupBox1.Hide();
            VCompAdd.Enabled    = admin;
            VisitingAdd.Enabled = admin;
            fillCompany();
            fillVisitor();

            VisitingCombo.Hide();
            VCompAdd.Hide();
            CompCombo.Hide();
            VisitingAdd.Hide();
            VisitingLabel.Hide();
            CompLabel.Hide();

            fieldEnabler();

            CompCombo.DropDownStyle     = ComboBoxStyle.DropDownList;
            VisitingCombo.DropDownStyle = ComboBoxStyle.DropDownList;
            cardNBox.Text = null;

            //ICAR
            Iconstants = new IcarConstants.IcarConstants();
            Icar       = new ICAR();
            Icar.initialize();
            checkIcarError();
            config = false;

            Configurations conf = new Configurations(Icar, connection);

            conf.configure();

            this.Size        = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            this.MaximizeBox = false;

            float Xratio = (float)(Screen.PrimaryScreen.Bounds.Width) / (float)(this.MinimumSize.Width);
            float Yratio = (float)(Screen.PrimaryScreen.Bounds.Height) / (float)(this.MinimumSize.Height);

            foreach (Control c in this.Controls)
            {
                float x = (float)c.Location.X * Xratio;
                float y = (float)c.Location.Y * Yratio;
                c.Location = new Point((int)x, (int)y);

                int w = c.Width * (int)Xratio;
                int h = c.Height * (int)Yratio;
                c.Size = new Size(w, h);
            }

            Scan.Image        = Image.FromFile("images/scan.png");
            Exit.Image        = Image.FromFile("images/exit.png");
            InButton.Image    = Image.FromFile("images/ok.png");
            Configure.Image   = Image.FromFile("images/config.png");
            Visitors.Image    = Image.FromFile("images/visitors.png");
            Report.Image      = Image.FromFile("images/report.png");
            pictureBox1.Image = Image.FromFile("images/company.jpg");

            groupBox2.Height   = Height;
            VisitorsLabel.Text = getVisitors();
        }