public void btnSearch_Click()
 {
     DateTime from;
     DateTime to;
     string nomorsurat;
     if (dfTo.IsEmpty)
     {
         X.Msg.Alert("error", "To Date must be FILLED").Show();
         return;
     }
     if (dfFrom.SelectedDate > dfTo.SelectedDate)
     {
         X.Msg.Alert("error", "From Date can not BIGGER than To Date").Show();
         return;
     }
     if (dfFrom.IsEmpty)
         from = new DateTime(1453, 12, 31);
     else
         from = dfFrom.SelectedDate;
     this.ReportViewer1.Visible = true;
     to = dfTo.SelectedDate;
     DisposisiQuery dQ = new DisposisiQuery("a");
     dQ.Select(dQ.Agendanomor, dQ.Tanggal,dQ.Biasa,dQ.Segera,dQ.Penting,dQ.Rahasia, dQ.Perihal, dQ.Asalsurat, dQ.Diteruskanke, dQ.Catatan);
     if (string.IsNullOrEmpty(txtNomorSurat.Text))
         dQ.Where(dQ.Tanggal.Between(from, to));
     else
     {
         nomorsurat = txtNomorSurat.Text.Trim();
         dQ.Where(dQ.Tanggal.Between(from, to) && dQ.Nomorsurat.Like("%" + nomorsurat + "%"));
     }
     DisposisiCollection dC = new DisposisiCollection();
     dC.Load(dQ);
     if (dC.Count > 0)
     {
         rptPrintOutDisposisi rptDisposisi = new rptPrintOutDisposisi();
         rptDisposisi.DataSource = dC;
         //ReportViewer1.ReportSource = rptDisposisi;
         //ReportViewer1.RefreshReport();
         //Telerik.Reporting.Report rptDisposisi = new Telerik.Reporting.Report();
         Telerik.Reporting.InstanceReportSource inst = new Telerik.Reporting.InstanceReportSource();
         inst.ReportDocument = rptDisposisi;
         this.ReportViewer1.ReportSource = inst;
         this.ReportViewer1.RefreshReport();
         this.ReportViewer1.Update();
     }
 }
        public void btnSave_Click()
        {
            if (string.IsNullOrEmpty(txtPerihal.Text) || string.IsNullOrEmpty(txtAsalSurat.Text) || string.IsNullOrEmpty(txtDiteruskanKe.Text) || string.IsNullOrEmpty(txtHtmlCatatan.Text))
                return;
            int disposisiId = 0;
            DisposisiQuery dQ = new DisposisiQuery("a");
            dQ.SelectAll();
            dQ.Where(dQ.Nomorsurat == txtSuratNo.Text.Trim());
            DisposisiCollection dC = new DisposisiCollection();
            dC.Load(dQ);
            if (dC.Count > 0)
            {
                foreach (Disposisi D in dC)
                {
                    disposisiId = (int)D.Disposisiid;
                }
            }

            // SAVE NEW
            Disposisi d = new Disposisi();
            if (disposisiId == 0)
            {
                d.Agendanomor = txtAgendaNo.Text;
                d.Nomorsurat = txtSuratNo.Text;
                d.Tanggal = dfTanggal.SelectedDate;
                if (rdoBiasa.Checked)
                {
                    d.Sifatsuratid = 1;

                }
                if (rdoPenting.Checked)
                    d.Sifatsuratid = 3;
                if (rdoRahasia.Checked)
                    d.Sifatsuratid = 4;
                if (rdoSegera.Checked)
                    d.Sifatsuratid = 2;
                d.Biasa = rdoBiasa.Checked;
                d.Segera = rdoSegera.Checked;
                d.Penting = rdoPenting.Checked;
                d.Rahasia = rdoRahasia.Checked;
                d.Perihal = txtPerihal.Text;
                d.Asalsurat = txtAsalSurat.Text;
                d.Diteruskanke = txtDiteruskanKe.Text;
                d.Catatan = txtHtmlCatatan.Text;
                d.Userid = HttpContext.Current.Session["user"].ToString().Trim();
                d.Lastedit = DateTime.Now;
                d.Save();
            }
            //SAVE EDIT
            else
            {
                if (d.LoadByPrimaryKey(disposisiId))
                {
                    d.Agendanomor = txtAgendaNo.Text;
                    d.Nomorsurat = txtSuratNo.Text;
                    d.Tanggal = dfTanggal.SelectedDate;
                    if (rdoBiasa.Checked)
                        d.Sifatsuratid = 1;
                    if (rdoPenting.Checked)
                        d.Sifatsuratid = 3;
                    if (rdoRahasia.Checked)
                        d.Sifatsuratid = 4;
                    if (rdoSegera.Checked)
                        d.Sifatsuratid = 2;
                    d.Perihal = txtPerihal.Text;
                    d.Asalsurat = txtAsalSurat.Text;
                    d.Diteruskanke = txtDiteruskanKe.Text;
                    d.Catatan = txtHtmlCatatan.Text;
                    d.Userid = HttpContext.Current.Session["user"].ToString().Trim();
                    d.Lastedit = DateTime.Now;
                    d.Save();
                }
            }
            HttpContext.Current.Session["isEditInbox"] = true;
            HttpContext.Current.Session["isAddDisposition"] = false;
            X.AddScript("parentAutoLoadControl.close(); Delay='2' ");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                if (Request.QueryString.Count == 0)
                    Response.Redirect("Default.aspx");
                //Show disposition from main surat masuk form
                if (Request.QueryString["masukid"] != null)
                    masukid = Request.QueryString["masukid"].ToString().Trim();
                else
                {
                    //show add new disposition from after new surat masuk save process
                    if (Request.QueryString["nomorsurat"] != null)
                        nomorsurat = Request.QueryString["nomorsurat"].ToString().Trim();
                }
                HttpContext.Current.Session["isEditInbox"] = false;
                HttpContext.Current.Session["isAddDisposition"] = false;

                if (!int.TryParse(masukid, out masukID))
                    masukID = 0;
                Suratmasuk sm = new Suratmasuk();
                //This for Edit Disposition
                if (sm.LoadByPrimaryKey(masukID))
                {
                    this.txtSuratNo.Text = sm.Nomor;
                    nomorsurat = sm.Nomor;
                    DisposisiQuery dQ = new DisposisiQuery("a");
                    dQ.SelectAll();
                    dQ.Where(dQ.Nomorsurat == sm.Nomor);
                    //get total dispositions records
                    DisposisiCollection dC = new DisposisiCollection();
                    dC.Load(dQ);
                    //Disposition already exist, edit instead
                    if (dC.Count > 0)
                    {

                        foreach (Disposisi d in dC)
                        {
                            rdoBiasa.Checked = (bool)d.Biasa;
                            rdoPenting.Checked = (bool)d.Penting;
                            rdoRahasia.Checked = (bool)d.Rahasia;
                            rdoSegera.Checked = (bool)d.Segera;
                            this.pnlMain.Title = "Edit Disposition for letter : " + d.Nomorsurat;
                            txtPerihal.Text = d.Perihal;
                            txtAgendaNo.Text = d.Agendanomor;
                            txtAsalSurat.Text = d.Asalsurat;
                            txtDiteruskanKe.Text = d.Diteruskanke;
                            txtHtmlCatatan.Text = d.Catatan;
                            txtSuratNo.Text = d.Nomorsurat;
                            dfTanggal.SelectedDate = (DateTime)d.Tanggal;
                        }
                    }
                }
                else
                {
                    this.pnlMain.Title = "Add new Disposition for letter ; " + nomorsurat;
                    this.txtSuratNo.Text = nomorsurat;
                    //HttpContext.Current.Session["isEditInbox"] = true;
                    //HttpContext.Current.Session["isAddDisposition"] = false;
                    //X.AddScript("parentAutoLoadControl.close(); Delay='2' ");
                }
                HttpContext.Current.Session["isEditInbox"] = false;
                HttpContext.Current.Session["isAddDisposition"] = false;
            }
        }