protected void m_grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                string commandName = e.CommandName;
                GridViewRow row = m_grid.FooterRow;
                if (commandName == "Insert")
                {
                    cls_Catalog_Report objReport = new cls_Catalog_Report();

                    string eName = ((TextBox)row.FindControl("txtIName")).Text;
                    string eFilePath = ((TextBox)row.FindControl("txtIFilePath")).Text;
                    string eSP = ((TextBox)row.FindControl("txtISP")).Text;
                    string eDetail = ((TextBox)row.FindControl("txtIDetail")).Text;
                    objReport.ID_Module = Convert.ToInt32(cboModule.SelectedValue);
                    objReport.Report_Name = eName;
                    objReport.File_Path = eFilePath;
                    objReport.SPName = eSP;
                    objReport.Note = eDetail;
                    int _result = objReport.Insert();
                    if (_result >= 1)
                    {
                        ltlAnnouncement.Text = "Thêm mới báo cáo '" + eName + "' thành công!";
                    }
                    if (_result == -1)
                    {
                        ltlAnnouncement.Text = "báo cáo '" + eName + "' đã tồn tại, bạn nên kiểm tra lại!";
                    }
                    if (_result == 0)
                    {
                        ltlAnnouncement.Text = "Có lỗi trong quá trình thêm mới!";
                    }
                    bindData(-1);
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong them moi duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }
        }
        protected void m_grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                int id = e.RowIndex;
                m_grid.EditIndex = id;

                int delId =Convert.ToInt32(m_grid.DataKeys[e.RowIndex].Value);
                if (delId != 0)
                {
                    cls_Catalog_Report objReport = new cls_Catalog_Report();
                    objReport.ID_Report = delId;

                    int status_Delete = objReport.Delete();
                    if (status_Delete == 1)
                    {
                        ltlAnnouncement.Text = "Xóa thành công báo cáo!";
                    }
                    if (status_Delete <= 0)
                    {
                        ltlAnnouncement.Text = "Không xóa được báo cáo đã chọn.";
                    }
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Lỗi trong quá trình xóa báo cáo: " + ex.ToString();
            }
            bindData(-1);
        }
        private void bindData(int index)
        {
            try
            {
                //LAY DANH SACH CAC QUOC GIA RA

                cls_Catalog_Report objReport = new cls_Catalog_Report();
                dsReport = objReport.GetData( cboModule.SelectedValue);
                objReport.ID_Report =0;

                m_grid.EditIndex = index;
                m_grid.DataSource = dsReport;
                bool add = false;
                if (dsReport.Rows.Count <= 0)
                {
                    dsReport.Rows.Add(dsReport.NewRow());
                    add = true;

                }
              //
                m_grid.DataBind();
                if(add)
                    m_grid.Rows[0].Visible = false;
                if (m_grid.Rows.Count > 0)
                {
                    string confirm = "return confirm('Bạn thật sự muốn xóa row này?')";

                    for (int i = 0; i < m_grid.Rows.Count; i++)
                    {
                        GridViewRow row = m_grid.Rows[i];
                        LinkButton lbutton1 = (LinkButton)row.FindControl("cmdDelete");
                        if (lbutton1 != null)
                        {
                            lbutton1.Visible = D_Option;
                            lbutton1.Attributes.Add("onclick", confirm);
                            //lbutton1.Enabled = D_Option;
                        }

                        LinkButton lbutton2 = (LinkButton)row.FindControl("cmdEdit");
                        if (lbutton2 != null)
                            lbutton2.Visible = U_Option;
                    }
                }

                //XET QUYETN CHO CHUC NANG INSERT
                GridViewRow row1 = m_grid.FooterRow;
                if (row1 != null)
                {
                    row1.Visible = I_Option;
                }
            }
            catch (Exception ex)
            {
            }
        }
        protected void m_grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                int id = e.RowIndex;
                m_grid.EditIndex = id;
                GridViewRow row = m_grid.Rows[id];

                string eName = ((TextBox)row.FindControl("txtUName")).Text;
                string eFilePath = ((TextBox)row.FindControl("txtUFilePath")).Text;
                string eSP = ((TextBox)row.FindControl("txtUSP")).Text;
                string eDetail = ((TextBox)row.FindControl("txtUDetail")).Text;

                short updateId = Int16.Parse(m_grid.DataKeys[id].Value.ToString());
                if (updateId > 0)
                {
                    cls_Catalog_Report objReport = new cls_Catalog_Report();
                    objReport.ID_Report = updateId;
                    objReport.ID_Module = Convert.ToInt32(cboModule.SelectedValue);
                    objReport.Report_Name = eName;
                    objReport.File_Path = eFilePath;
                    objReport.SPName = eSP;
                    objReport.Note = eDetail;

                    int _result = objReport.Update();
                    if (_result == 1)
                    {
                        ltlAnnouncement.Text = "Sửa báo cáo '" + eName + "' thành công!";
                    }
                    if (_result < 0)
                    {
                        ltlAnnouncement.Text = "Có lỗi trong quá trình sửa dữ liệu!";
                    }
                }
            }
            catch (Exception ex)
            {
                ltlAnnouncement.Text = "Khong cap nhat duoc du lieu. Vui long lien he voi quan tri<br>" + ex.Message;
            }

            bindData(-1);
        }
 private void LoadListReport()
 {
     DataTable _dt = new cls_Catalog_Report().SelectByModuleCode(ConfigurationSettings.AppSettings["Emp_Module"]);
     gridReport.DataSource = _dt;
     gridReport.DataBind();
 }
 private void LoadReport()
 {
     cls_Catalog_Report objRe = new cls_Catalog_Report();
     DataTable _dt = objRe.GetData( cboModule.SelectedValue);
     cboReport.DataSource = _dt;
     cboReport.DataValueField = "ID_Report";
        cboReport.DataTextField = "Report_Name";
     cboReport.DataBind();
     if (cboReport.Items.Count > 0)
     {
         cboReport.SelectedIndex = 0;
         LoadParameter(cboReport.SelectedValue);
     }
 }
        private void ViewReport()
        {
            try
            {
                ReportDocument reportDocument = new ReportDocument();
                string sReportID = Request.QueryString["ID_Report"].ToString();
                cls_Catalog_Report objRe = new cls_Catalog_Report();
                DataTable _dtRe = objRe.GetReport(sReportID);
                DataTable _dtPara = Session["ReportPara"] == null ? null : (DataTable)(Session["ReportPara"]);
                DataTable _dtP = _dtPara.Clone();
                DataTable _dtPReport = _dtPara.Clone();
                DataTable _dtSource;
                string[] sArr = _dtRe.Rows[0]["SPName"].ToString().Split('@');
                cls_Report_User objUser = new cls_Report_User();
                if (sArr.Length > 1)
                {
                    for (int i = 0; i < _dtPara.Rows.Count; i++)
                    {
                        bool Exist = false;
                        for (int k = 1; k < sArr.Length; k++)
                            if (_dtPara.Rows[i]["ParaName"].ToString().ToUpper() == sArr[k].ToUpper())
                            {
                                Exist = true;
                                break;
                            }
                        if (Exist)
                        {
                            _dtP.ImportRow(_dtPara.Rows[i]);
                        }
                        else
                            _dtPReport.ImportRow(_dtPara.Rows[i]);
                    }
                  _dtSource = objUser.GetDataSourceReport(_dtP, sArr[0]);
                }
                else
                    _dtSource = objUser.GetSP(sArr[0]);
                //
                if (sArr.Length >= 1 && sArr[0].Length <= 0)
                    _dtPReport = _dtPara;

                string sPath = ConfigurationManager.AppSettings["Report_File"].ToString() + _dtRe.Rows[0]["File_Path"].ToString();
                reportDocument.Load(sPath);
                //tham so bao cao

                if (_dtSource != null)
                    reportDocument.SetDataSource(_dtSource);

                for (int k = 0; k < _dtP.Rows.Count; k++)
                {
                    for (int i = 0; i < reportDocument.ParameterFields.Count; i++)
                    {
                        if (reportDocument.ParameterFields[i].Name.ToUpper() == _dtP.Rows[k]["ParaName"].ToString().ToUpper())
                            reportDocument.SetParameterValue(reportDocument.ParameterFields[i].Name, _dtP.Rows[k]["ParaValue"]);
                    }
                }
                if (_dtPReport.Rows.Count > 0)
                    for (int i = 0; i < _dtPReport.Rows.Count; i++)
                        reportDocument.SetParameterValue(_dtPReport.Rows[i]["ParaName"].ToString(), _dtPReport.Rows[i]["ParaValue"]);

                CrystalReportViewer.ReportSource = reportDocument;

                CrystalReportViewer.DataBind();
            }
            catch (Exception ex)
            {
            }
        }