protected void LoadDatabase_Click(object sender, EventArgs e)
        {
            lblMsg.ForeColor = Color.Black;
            lblMsg.Text      = "Upload A CSV File";
            string fileType = ddl_fileType.SelectedValue;

            if (fileType == "1")
            {
                if (fu_UploadFile.HasFile)
                {
                    FileInfo fileInfo = new FileInfo(fu_UploadFile.PostedFile.FileName);
                    if (fileInfo.Name.Contains(".csv"))
                    {
                        lblMsg.ForeColor = Color.Black; //reset label color
                        string fileName    = fileInfo.Name.Replace(".csv", "").ToString();
                        string csvFilePath = Server.MapPath("Files") + "\\" + fileInfo.Name;
                        //save the csv file on the server in 'UpLoadedCSVFiles'
                        //fu_UploadFile.SaveAs(csvFilePath);
                        SqlProvider sqlProvider = new SqlProvider();
                        sqlProvider.LoadClassListFile(csvFilePath);
                        lblMsg.ForeColor = Color.Black;
                        lblMsg.Text      = "CSV File Uploaded to Database";
                    }
                    else
                    {
                        //alert user that file is not a csv file
                        lblMsg.ForeColor = Color.Red;
                        lblMsg.Text      = "Uploaded file is not CSV file";
                    }
                }
                else
                {
                    //alert user no file found
                    lblMsg.ForeColor = Color.Red;
                    lblMsg.Text      = "No File Found, Try To Re-Upload";
                }
            }
            if (fileType == "2")
            {
                if (fu_UploadFile.HasFile)
                {
                    FileInfo fileInfo = new FileInfo(fu_UploadFile.PostedFile.FileName);
                    if (fileInfo.Name.Contains(".csv"))
                    {
                        lblMsg.ForeColor = Color.Black; //reset label color
                        string fileName    = fileInfo.Name.Replace(".csv", "").ToString();
                        string csvFilePath = Server.MapPath("Files") + "\\" + fileInfo.Name;
                        //save the csv file on the server in 'MyCSVFolder'
                        //fu_UploadFile.SaveAs(csvFilePath);
                        SqlProvider sqlProvider = new SqlProvider();
                        sqlProvider.LoadSESFile(csvFilePath);
                        lblMsg.ForeColor = Color.Black;
                        lblMsg.Text      = "CSV File Uploaded to Database";
                    }
                    else
                    {
                        //alert user that file is not a csv file
                        lblMsg.ForeColor = Color.Red;
                        lblMsg.Text      = "Uploaded file is not CSV file";
                    }
                }
                else
                {
                    //alert user no file found
                    lblMsg.ForeColor = Color.Red;
                    lblMsg.Text      = "No File Found, Try To Re-Upload";
                }
            }
        }
Esempio n. 2
0
        protected void Btn_UnionSearch_Click(object sender, EventArgs e)
        {
            string subUnionQuery = string.Empty; string UnionQuery = string.Empty; lb_ResultFeedback.Text = ""; lb_Error.Text = "";

            if (cb_SavedSearchList.SelectedIndex != -1)    //if an item in check box list as been selected
            {
                if (cb_SavedSearchList.SelectedIndex >= 0) //if more than one item in the check box list selected
                {
                    try
                    {
                        int check = 0;
                        //Loop through Check Box List and Build Selected Save Search for each save search
                        foreach (ListItem lt in cb_SavedSearchList.Items)
                        {
                            //get where clause from daabase
                            string      queryString = string.Empty;
                            SqlProvider sqlProvider = new SqlProvider();
                            string      query       = "EXEC dbo.Proc_GetWhereClauseBySearchID @SearchID = " + lt.Value + ", @UserName = '******'";
                            queryString = Convert.ToString(sqlProvider.ExecuteSqlScalarCommand(query));
                            if (lt.Selected && check == 0)
                            {
                                subUnionQuery += "   " + this.BuildAdvanceQuery() + queryString; check++;
                            }
                            else if (lt.Selected && check > 0)
                            {
                                subUnionQuery += "  UNION   " + this.BuildAdvanceQuery() + queryString;
                            }
                        }
                        //Build Union Query String
                        UnionQuery = this.BuildUnionSQLQuery(subUnionQuery);
                        //Populate gridview
                        gv_StudentData.Height = 310;
                        gv_Result.Height      = 310;
                        try { this.PopulateGridView(gv_StudentData, lb_Error, UnionQuery); }
                        catch (Exception ex) { lb_Error.Text = "Invalid Query String"; }
                        if (gv_StudentData.Rows.Count > 0)
                        {
                            lb_ResultFeedback.Visible = true;
                            lb_ResultFeedback.Text    = gv_StudentData.Rows.Count.ToString() + " Record(s) Found";
                        }
                        else
                        {
                            lb_ResultFeedback.Visible = true;
                            lb_ResultFeedback.Text    = "No Record(s) Found";
                        }
                    }
                    catch (Exception ex)
                    {
                        lb_Error.Text = "Opppsss!!! Something Went Wrong";
                    }
                }
                else
                {
                    lb_Error.Text = "To View A Union Search Result, Select Two Or More Search";
                }
            }
            else
            {
                lb_Error.Text             = "No Search Selected";
                lb_ResultFeedback.Text    = "";
                gv_StudentData.DataSource = null; gv_StudentData.DataBind();
            }

            //Build Union Search
        }