protected void uiGridViewAirLines_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "DeleteAirLine")
     {
         AirLines objData = new AirLines();
         objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));
         objData.MarkAsDeleted();
         objData.Save();
         BindData();
     }
 }
        protected void uiLinkButtonAdd_Click(object sender, EventArgs e)
        {
            AirLines objData = new AirLines();
            objData.AddNew();
            objData.CompanyID = Convert.ToInt32(uiDropDownListCompanies.SelectedValue);
            objData.FromAirPortID = Convert.ToInt32(uiDropDownListFromCity.SelectedValue);
            objData.ToAirPortID = Convert.ToInt32(uiDropDownListToCity.SelectedValue);
            objData.Save();

            BindData();
        }
        protected void uiLinkButtonUpload_Click(object sender, EventArgs e)
        {
            if (uiFileUploadAirLines.HasFile)
            {
                ArrayList nonUploaded = new ArrayList();
                uiFileUploadAirLines.SaveAs(Server.MapPath("~/FileUploads/" + uiFileUploadAirLines.FileName));
                string connectionString = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=NO;""", Server.MapPath("~/FileUploads/" + uiFileUploadAirLines.FileName));

                string strSQL = "SELECT * FROM [sheet1$]";
                OleDbConnection excelConnection = new OleDbConnection(connectionString);
                excelConnection.Open();
                OleDbCommand dbCommand = new OleDbCommand(strSQL, excelConnection);
                OleDbDataAdapter dataAdapter = new OleDbDataAdapter(dbCommand);

                DataTable dTable = new DataTable();

                dataAdapter.Fill(dTable);
                AirLines objData = new AirLines();
                if (uiDropDownListUploadType.SelectedValue == "1")
                {

                    foreach (DataRow item in dTable.Rows)
                    {
                        AirPorts Fcity = new AirPorts();
                        Fcity.GetAirPortByCode(item[0].ToString());

                        AirPorts Tcity = new AirPorts();
                        Tcity.GetAirPortByCode(item[1].ToString());

                        if (Fcity.RowCount == 0 || Tcity.RowCount == 0)
                        {
                            nonUploaded.Add("From : " + item[0].ToString() + " - To : " + item[1].ToString());
                            continue;
                        }
                        else
                        {
                            objData.AddNew();
                            objData.CompanyID = Convert.ToInt32(uiDropDownListCompanyUpload.SelectedValue);
                            objData.FromAirPortID = Fcity.AirPortID;
                            objData.ToAirPortID = Tcity.AirPortID;
                        }
                    }
                }
                else if (uiDropDownListUploadType.SelectedValue == "2")
                {

                    foreach (DataRow item in dTable.Rows)
                    {

                        AirPorts Fcity = new AirPorts();
                        Fcity.GetAirPortByName(item[0].ToString());

                        AirPorts Tcity = new AirPorts();
                        Tcity.GetAirPortByName(item[1].ToString());

                        if (Fcity.RowCount == 0 || Tcity.RowCount == 0)
                        {
                            nonUploaded.Add("From : " + item[0].ToString() + " - To : " + item[1].ToString());
                            continue;
                        }
                        else
                        {
                            objData.AddNew();
                            objData.CompanyID = Convert.ToInt32(uiDropDownListCompanyUpload.SelectedValue);
                            objData.FromAirPortID = Fcity.AirPortID;
                            objData.ToAirPortID = Tcity.AirPortID;
                        }
                    }
                }

                objData.Save();
                BindData();

                uiGridViewLog.DataSource = nonUploaded;
                //uiGridViewLog.Columns[1].HeaderText = "These items faild to insert";
                uiGridViewLog.DataBind();
            }
        }
 private void BindData()
 {
     AirLines objData = new AirLines();
     objData.LoadAll();
     uiGridViewAirLines.DataSource = objData.DefaultView;
     uiGridViewAirLines.DataBind();
 }