Esempio n. 1
0
        protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
            string month = DateTime.Now.Month.ToString().Trim();
            string autonumber = "";
            if (month.Length == 1)
                month = ('0' + month).Trim();

            Trans Trans = new Trans();
            //Auto Number
            AutoNumberingQuery anQ = new AutoNumberingQuery();
            anQ.SelectAll();
            anQ.Where(anQ.KaMonth == month, anQ.KaYear == DateTime.Now.Year.ToString().Trim());
            AutoNumberingCollection anColl = new AutoNumberingCollection();

            anColl.Load(anQ);
            KelAnggaranQuery kaQ = new KelAnggaranQuery();
            kaQ.SelectAll();
            kaQ.Where(kaQ.KaCode == (userControl.FindControl("cmbTransCODE") as RadComboBox).SelectedValue.Trim());
            KelAnggaranCollection kaColl = new KelAnggaranCollection();

            kaColl.Load(kaQ);
            if (kaColl.Count > 0)
                foreach (KelAnggaran kkk in kaColl)
                    autonumber = kkk.Prefix.Trim();
            else
                return;

            if (anColl.Count == 0)
            {
                AutoNumbering an = new AutoNumbering { KaYear = DateTime.Now.Year.ToString().Trim(), KaMonth = month, LastNumber = 1, PrefixNumber = "000" };
                autonumber = String.Format("{0}{1}{2}-0001", autonumber, DateTime.Now.Year.ToString().Trim(), month);
                an.Save();
            }
            else
                foreach (AutoNumbering aa in anColl)
                {
                    string i = (aa.LastNumber + 1).ToString().Trim();
                    if (i.Length == 1)
                        autonumber = String.Format("{0}{1}{2}-000{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 2)
                        autonumber = String.Format("{0}{1}{2}-00{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 3)
                        autonumber = String.Format("{0}{1}{2}-0{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 4)
                        autonumber = String.Format("{0}{1}{2}-{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    AutoNumbering anb = new AutoNumbering();
                    if (anb.LoadByPrimaryKey((long)aa.Id))
                    {
                        anb.LastNumber = aa.LastNumber + 1;
                        anb.Save();
                    }
                }

            try
            {
                Trans.KaCode = (userControl.FindControl("cmbTransCODE") as RadComboBox).SelectedValue.ToUpper();
                Trans.TransNumber = autonumber.ToUpper();
                Trans.CekBgNumber = (userControl.FindControl("txtCek") as RadTextBox).Text.ToUpper();
                //Trans.Amount = Convert.ToDecimal((userControl.FindControl("txtDebitAmount") as RadNumericTextBox).Value - (userControl.FindControl("txtCreditAmount") as RadNumericTextBox).Value);
                Trans.DebitAmount = Convert.ToDecimal((userControl.FindControl("txtDebitAmount") as RadNumericTextBox).Value);
                Trans.CreditAmount = Convert.ToDecimal((userControl.FindControl("txtCreditAmount") as RadNumericTextBox).Value);
                Trans.Descript = (userControl.FindControl("txtDESC") as RadTextBox).Text.ToUpper();
                Trans.KasId = (userControl.FindControl("cmbKasID") as RadComboBox).SelectedValue.ToUpper();
                Trans.TransDate = (DateTime)(userControl.FindControl("dtpTransDate") as RadDatePicker).DbSelectedDate;
                Trans.UserInsert = "toro";
                Trans.TglInsert = DateTime.Now;
                Trans.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                Trans.Isverified = false;
                Trans.IsClosed = false;
                Trans.Save();
            }
            catch (Exception ex)
            {
                string es = ex.Message;
            }
            finally
            {
                RadGrid1.Rebind();
            }
        }
 private DataTable GetDataTableKA()
 {
     KelAnggaranQuery kaQ = new KelAnggaranQuery();
     kaQ.es2.Connection.Name = "LIVE";
     kaQ.Select(kaQ.KaCode, kaQ.KaName);
     kaQ.Where(kaQ.KaLevel == 3);
     dtKa = kaQ.LoadDataTable();            
     return dtKa;
 }