コード例 #1
0
        /// <summary>
        /// To add a new Area
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_addArea_Click(object sender, EventArgs e)
        {
            //Performing Validation
            if (textBox_area.Text.Length == 0 && textBox_editArea.Text.Length == 0)
            {
                MessageBox.Show("Please Enter a Valid Value", "Error");
                return;
            }

               int textValue;

               if (textBox_editArea.Text.Trim().Length  != 0)
               {
               String areaName = comboBox_areas.SelectedValue.ToString();
               if (db.Areas.Select(x => x.AreaName).Contains(textBox_editArea.Text))
               {
                   MessageBox.Show("Already Exists.", "Error");
                   return;
               }
               db.Areas.Where(x => x.AreaName == areaName).Single().AreaName = textBox_editArea.Text;
               db.SaveChanges();
               //Refersh the Area combo-box.
               CommonUtilities.populateAreas(comboBox_areas);
               MessageBox.Show("Updated Successfully", "Success");
               textBox_editArea.Text = "";
               return;
               }

               if (Int32.TryParse(textBox_area.Text.Trim(), out textValue))
               {
               MessageBox.Show("Not a Valid Name", "Error");
               return;
               }

            if (db.Areas.Select(x => x.AreaName).Contains(textBox_area.Text))
            {
                MessageBox.Show("Already Exists.", "Error");
                return;
            }

            //Validation succeeded.
            if (textBox_area.Text.Trim().Length != 0)
            {
                int lastAreaId = 0;

                if (db.Areas.Count() != 0)
                lastAreaId = db.Areas.Select(x => x.AreaId).Max();

                Area newArea = new Area();
                newArea.AreaId = lastAreaId + 1;
                newArea.AreaName = textBox_area.Text;

                db.Areas.AddObject(newArea);
                MessageBox.Show("Added Successfully", "Success");
                db.SaveChanges();
                //Refersh the Area combo-box.
                CommonUtilities.populateAreas(comboBox_areas);
                textBox_area.Text = "";
            }
        }
コード例 #2
0
        /// <summary>
        /// The Submit button was clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_addNewArea_Click(object sender, EventArgs e)
        {
            //If the linklabel which led us to this form was for adding a new value for the Area master table.
            if (clickedLinkName.Contains("Area"))
            {
                //Validation
                if (textBox_addNewMaster.Text.Length == 0 )
                {
                    MessageBox.Show("Please enter a value.", "Error");
                    return;
                }
                int textValue;
                if (Int32.TryParse(textBox_addNewMaster.Text.Trim(), out textValue))
                {
                    MessageBox.Show("Please enter a valid value.", "Error");
                    return;
                }
                if (db.Areas.Select(x => x.AreaName).Contains(textBox_addNewMaster.Text))
                {
                    MessageBox.Show("This value already exists.", "Error");
                    return;
                }

                int areaId = 0;

                if (db.Areas.Count() != 0)
                areaId = db.Areas.Select(x => x.AreaId).Max();

                //Validation was successful.
                Area newArea = new Area();
                newArea.AreaName = textBox_addNewMaster.Text;
                newArea.AreaId = areaId + 1;
                db.Areas.AddObject(newArea);
            }

            //If the linklabel which led us to this form was for adding a new value for the MealPlan master table.
            if (clickedLinkName.Contains("MealPlan"))
            {
                //Validation
                if (textBox_addNewMaster.Text.Length == 0 )
                {
                    MessageBox.Show("Please enter a value.", "Error");
                    return;
                }
                int textValue=0;
                if (!Int32.TryParse(textBox_addNewMaster.Text.Trim(), out textValue))
                {
                    MessageBox.Show("Please enter a valid number.", "Error");
                    return;
                }
                if (Int32.Parse(textBox_addNewMaster.Text) <= 0)
                {
                    MessageBox.Show("Please enter a positive value for Meal Plan.", "Error");
                    return;
                }
                if (db.MealPlans.Select(x => x.MealAmount).Contains(Int32.Parse(textBox_addNewMaster.Text)))
                {
                    MessageBox.Show("This Meal Plan already exists.", "Error");
                    return;
                }

                int lastMealPlanId = 0;
                if (db.MealPlans.Count() != 0)
                    lastMealPlanId = db.MealPlans.Select(x => x.MealPlanId).Max();

                //Validation was successful.
                MealPlan newMealPlan = new MealPlan();
                newMealPlan.MealAmount = Int32.Parse(textBox_addNewMaster.Text);
                newMealPlan.MealPlanId = lastMealPlanId + 1;
                db.MealPlans.AddObject(newMealPlan);
            }

            db.SaveChanges();
            MessageBox.Show("Added Successfully.", "Success");
            this.Close(); //close the window.
        }
コード例 #3
0
 /// <summary>
 /// Populates the Area combo-box.
 /// </summary>
 private void populateAreas()
 {
     List<Area> areas = new List<Area>();
     Area blankAreaValue = new Area();
     blankAreaValue.AreaId = -1;
     areas.Add(blankAreaValue);
     areas.AddRange(db.Areas.ToList());
     comboBox_Area.DataSource = areas;
     comboBox_Area.DisplayMember = "AreaName";
     comboBox_Area.ValueMember = "AreaName";
 }
コード例 #4
0
 /// <summary>
 /// Create a new Area object.
 /// </summary>
 /// <param name="areaId">Initial value of the AreaId property.</param>
 /// <param name="areaName">Initial value of the AreaName property.</param>
 public static Area CreateArea(global::System.Int32 areaId, global::System.String areaName)
 {
     Area area = new Area();
     area.AreaId = areaId;
     area.AreaName = areaName;
     return area;
 }
コード例 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Areas EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAreas(Area area)
 {
     base.AddObject("Areas", area);
 }