Exemplo n.º 1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            UserLibrary u      = new UserLibrary();
            int         Upload = 0;

            foreach (DataGridViewRow row in dgvUserUpload.Rows)
            {
                u.GENID = u.UserID();

                for (int i = 0; i < row.Cells.Count; i++)
                {
                    if (row.Cells[i].Value == null || row.Cells[i].Value == DBNull.Value || String.IsNullOrWhiteSpace(row.Cells[i].Value.ToString()))
                    {
                    }
                    else
                    {
                        if (Convert.ToInt32(row.Cells[5].Value) == 110)
                        {
                            u.ID = "AD-" + (u.UserID() + 1).ToString().PadLeft(5, '0');
                        }
                        else if (Convert.ToInt32(row.Cells[5].Value) == 111)
                        {
                            u.ID = "TR-" + (u.UserID() + 1).ToString().PadLeft(5, '0');
                        }
                        else if (Convert.ToInt32(row.Cells[5].Value) == 112)
                        {
                            u.ID = "ST-" + (u.UserID() + 1).ToString().PadLeft(5, '0');
                        }

                        u.Username      = row.Cells[0].Value.ToString();
                        u.Password      = "******";
                        u.FirstName     = row.Cells[1].Value.ToString();
                        u.MiddleName    = row.Cells[2].Value.ToString();
                        u.LastName      = row.Cells[3].Value.ToString();
                        u.ContactNumber = row.Cells[4].Value.ToString();
                        u.Usertype      = Convert.ToInt32(row.Cells[5].Value);

                        Upload = 1;
                    }
                }

                if (Upload == 1)
                {
                    u.UserInsert();
                    Upload = 0;
                }
            }
        }