コード例 #1
0
        protected void ONCLICK_BulkRemove(object sender, EventArgs e)
        {
            if (this.FileUpload_BulkRemove.HasFile)
            {
                string pathTempFolder = System.IO.Path.GetTempPath();
                string pathTempFile   = System.IO.Path.GetTempFileName();
                FileUpload_BulkRemove.SaveAs(pathTempFile);
                DataTable dt = HELPERS.LoadCsv(pathTempFolder,
                                               System.IO.Path.GetFileName(pathTempFile));
                if (dt != null)
                {
                    if (dt.Columns.Count != 2)
                    {
                        throw new Exception("The uploaded CSV file has more than two columns.");
                    }


                    Queue RETmsgs = new Queue();

                    IEnumerator <System.Data.DataRow> x =
                        (IEnumerator <System.Data.DataRow>)dt.Rows.GetEnumerator();

                    int recordseq = 0;
                    int okCount   = 0;

                    IBusRole       ENGINEbusrole = new IBusRole(HELPERS.NewOdbcConn());
                    IEntitlement   ENGINE        = new IEntitlement(HELPERS.NewOdbcConn());
                    IEntAssignment IEA           = new IEntAssignment(HELPERS.NewOdbcConn());


                    while (x.MoveNext())
                    {
                        recordseq++;

                        string rolename   = x.Current[0].ToString();
                        string privstring = x.Current[1].ToString();

                        try
                        {
                            HELPERS.RemoveEntitlementFromRole(rolename, privstring, ENGINEbusrole, ENGINE, IEA);
                            okCount++;
                        }
                        catch (Exception ee)
                        {
                            RETmsgs.Enqueue("REC#" + recordseq.ToString() + ": " + ee.Message);
                        }
                    }
                    RETmsgs.Enqueue("------------------");
                    RETmsgs.Enqueue("Number of records processed without message: " + okCount.ToString());
                    if (RETmsgs.Count > 0)
                    {
                        string strMsgs = "";
                        foreach (object objMsg in RETmsgs.ToArray())
                        {
                            strMsgs += "\n" + objMsg.ToString();
                        }
                        TXTimportEngineMessages.Text  = strMsgs;
                        DIVimportFeeback.Visible      = true;
                        PANELcond_AbortUpload.Visible = false;
                        PANELcond_AllowUpload.Visible = false;
                    }
                }
            }
        }