Exemple #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string[] startDate = this.txtStartDate.PersianDate.Split('/');
            string[] endDate = this.txtEndDate.PersianDate.Split('/');

            if (Public.ToInt(startDate[0]) < Public.ToInt(endDate[0])) // Both dates are not in the same year
            {
                if (Public.MonthsInStartYear(Public.ToInt(startDate[1]), Public.ToInt(startDate[0]), Public.ToInt(endDate[1]), Public.ToInt(endDate[0])).Count > 11)
                {
                    this.lblMessage.Text = "محدوده دوره نباید بیشتر از یازده ماه باشد!";
                    return;
                }
            }

            if (this.drpActivation.SelectedIndex == 1)
            {
                foreach (SupplySystem.Cycle item in db.Cycles)
                {
                    item.IsActive = false;
                }
            }

            SupplySystem.Cycle cycle = null;
            int cycleId = 0;
            if (string.IsNullOrEmpty(this.hdnCycleID.Value)) // Add mode
            {
                cycle = new SupplySystem.Cycle();
                db.Cycles.InsertOnSubmit(cycle);
            }
            else if (int.TryParse(this.hdnCycleID.Value, out cycleId))
            {
                cycle = db.Cycles.First<SupplySystem.Cycle>(c => c.CycleID == cycleId);
            }

            cycle.CycleName = this.txtCycleName.Text;
            cycle.StartDate = this.txtStartDate.GeorgianDate.GetValueOrDefault();
            cycle.EndDate = this.txtEndDate.GeorgianDate.GetValueOrDefault();
            cycle.SubmitDate = DateTime.Now;
            cycle.IsActive = this.drpActivation.SelectedIndex == 1 ? true : false;
            db.SubmitChanges();
            this.lblMessage.Text = Public.SUCCESSMESSAGE;
            FillGrid();
            ClearControls();
            if (cycle.IsActive)
            {
                System.Web.HttpContext.Current.Cache.Insert("ActiveCycle", cycle, null, DateTime.MaxValue, TimeSpan.FromMinutes(10));
            }
        }
    }
Exemple #2
0
 partial void DeleteCycle(Cycle instance);
Exemple #3
0
 partial void UpdateCycle(Cycle instance);
Exemple #4
0
 partial void InsertCycle(Cycle instance);