private void btnExecute_Click(object sender, RoutedEventArgs e)
        {
            var x = this.DataContext as ItemCriteria;

            if (x != null)
            {
                x.CriteriaItem = cmboItems.SelectedItem as Item;
                if (radAdd.IsChecked == true)
                {
                    if (isValidateByControls(x) && x.IsValidate() && ItemCriteria.InsertData(x))
                    {
                        MyMessage.InsertMessage();
                        dgMain.ItemsSource = ItemCriteria.GetAllItemCriteria();
                    }
                }
                else if (radUpdate.IsChecked == true)
                {
                    if (isValidateByControls(x) && x.IsValidate() && ItemCriteria.UpdateData(x))
                    {
                        MyMessage.UpdateMessage();
                        dgMain.ItemsSource = ItemCriteria.GetAllItemCriteria();
                    }
                }
                else if (radDelete.IsChecked == true)
                {
                    if (MyMessageBox.Show("هل تريد تأكيد حذف المعيار", MessageBoxButton.YesNo) == MessageBoxResult.Yes && ItemCriteria.DeleteData(x))
                    {
                        MyMessage.DeleteMessage();
                        dgMain.ItemsSource = ItemCriteria.GetAllItemCriteria();
                    }
                }
            }
        }
        public ItemCriteriaControl()
        {
            InitializeComponent();

            cmboItems.ItemsSource = (from x in Item.AllItems orderby x.Name select x).ToList();
            this.DataContext      = new ItemCriteria();
            dgMain.ItemsSource    = ItemCriteria.GetAllItemCriteria();
        }
예제 #3
0
        public static List <ItemCriteria> GetAllItemCriteria()
        {
            List <ItemCriteria> xx  = new List <ItemCriteria>();
            SqlConnection       con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand          com = new SqlCommand("sp_Get_All_ItemCriteria", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                while (rd.Read())
                {
                    ItemCriteria x = new ItemCriteria();

                    if (!(rd["ID"] is DBNull))
                    {
                        x.ID = int.Parse(rd["ID"].ToString());
                    }

                    if (!(rd["ItemID"] is DBNull))
                    {
                        x.CriteriaItem = Item.GetItemByID(int.Parse(rd["ItemID"].ToString()));
                    }

                    if (!(rd["StartCriteria"] is DBNull))
                    {
                        x.StartCriteria = int.Parse(rd["StartCriteria"].ToString());
                    }
                    if (!(rd["EndCriteria"] is DBNull))
                    {
                        x.EndCriteria = int.Parse(rd["EndCriteria"].ToString());
                    }
                    x.CriteriaType = rd["CriteriaType"].ToString();
                    if (!(rd["Count"] is DBNull))
                    {
                        x.Count = int.Parse(rd["Count"].ToString());
                    }
                    x.Evaluation = rd["Evaluation"].ToString();
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                    xx.Add(x);
                }
                rd.Close();
            }
            catch
            {
                xx = null;
            }
            finally
            {
                con.Close();
            }
            return(xx);
        }
예제 #4
0
        public static ItemCriteria GetItemCriteriaByID(int id)
        {
            ItemCriteria  x   = new ItemCriteria();
            SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand    com = new SqlCommand("sp_Get_ID_ItemCriteria", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr = new SqlParameter("@ID", id);

            com.Parameters.Add(pr);
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    if (!(rd["ID"] is DBNull))
                    {
                        x.ID = int.Parse(rd["ID"].ToString());
                    }

                    if (!(rd["ItemID"] is DBNull))
                    {
                        x.CriteriaItem = Item.GetItemByID(int.Parse(rd["ItemID"].ToString()));
                    }

                    if (!(rd["StartCriteria"] is DBNull))
                    {
                        x.StartCriteria = int.Parse(rd["StartCriteria"].ToString());
                    }
                    if (!(rd["EndCriteria"] is DBNull))
                    {
                        x.EndCriteria = int.Parse(rd["EndCriteria"].ToString());
                    }
                    x.CriteriaType = rd["CriteriaType"].ToString();
                    if (!(rd["Count"] is DBNull))
                    {
                        x.Count = int.Parse(rd["Count"].ToString());
                    }
                    x.Evaluation = rd["Evaluation"].ToString();
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                }
                rd.Close();
            }
            catch
            {
                x = null;
            }
            finally
            {
                con.Close();
            }
            return(x);
        }
예제 #5
0
 public static bool UpdateData(ItemCriteria x)
 {
     return(BaseDataBase._StoredProcedure("sp_Update_ItemCriteria"
                                          , new SqlParameter("@ID", x.ID)
                                          , new SqlParameter("@ItemID", x.CriteriaItem.Id.Value)
                                          , new SqlParameter("@StartCriteria", x.StartCriteria)
                                          , new SqlParameter("@EndCriteria", x.EndCriteria)
                                          , new SqlParameter("@CriteriaType", x.CriteriaType)
                                          , new SqlParameter("@Count", x.Count)
                                          , new SqlParameter("@Evaluation", x.Evaluation)
                                          , new SqlParameter("@LastUserID", BaseDataBase.CurrentUser.ID)));
 }
예제 #6
0
 public static bool InsertData(ItemCriteria x)
 {
     x.ID = BaseDataBase._StoredProcedureReturnable("sp_Add_ItemCriteria"
                                                    , new SqlParameter("@ID", System.Data.SqlDbType.Int)
                                                    , new SqlParameter("@ItemID", x.CriteriaItem.Id.Value)
                                                    , new SqlParameter("@StartCriteria", x.StartCriteria)
                                                    , new SqlParameter("@EndCriteria", x.EndCriteria)
                                                    , new SqlParameter("@CriteriaType", x.CriteriaType)
                                                    , new SqlParameter("@Count", x.Count)
                                                    , new SqlParameter("@Evaluation", x.Evaluation)
                                                    , new SqlParameter("@LastUserID", BaseDataBase.CurrentUser.ID));
     return(x.ID.HasValue);
 }
        private bool isValidateByControls(ItemCriteria x)
        {
            if (cmboItems.SelectedItem == null)
            {
                MyMessageBox.Show("يجب اختيار المادة");
                return(false);
            }

            if (x.CriteriaType == "عمر الشخص")
            {
                if (!nudAgeEnd.Value.HasValue || !nudAgeStart.Value.HasValue)
                {
                    MyMessageBox.Show("يجب ادخال مجال العمر");
                    return(false);
                }
                switch (cmboSpan1.SelectedItem.ToString())
                {
                case "يوم":
                    x.StartCriteria = (int)nudAgeStart.Value.Value;
                    break;

                case "شهر":
                    x.StartCriteria = (int)nudAgeStart.Value.Value * 30;
                    break;

                case "سنة":
                    x.StartCriteria = (int)nudAgeStart.Value.Value * 30 * 12;
                    break;
                }

                switch (cmboSpan2.SelectedItem.ToString())
                {
                case "يوم":
                    x.EndCriteria = (int)nudAgeEnd.Value.Value;
                    break;

                case "شهر":
                    x.EndCriteria = (int)nudAgeEnd.Value.Value * 30 - 1;
                    break;

                case "سنة":
                    x.EndCriteria = (int)nudAgeEnd.Value.Value * 30 * 12 - 1;
                    break;
                }
            }
            else if (x.CriteriaType == "بدون معيار")
            {
                x.StartCriteria = null;
                x.EndCriteria   = null;
            }
            else if (x.CriteriaType == "عدد الافراد")
            {
                x.StartCriteria = (int)nudPerosnCountFrom.Value.Value;
                x.EndCriteria   = (int)nudPerosnCountTo.Value.Value;
                if (!nudPerosnCountFrom.Value.HasValue || !nudPerosnCountTo.Value.HasValue)
                {
                    MyMessageBox.Show("يجب ادخال مجال عدد الأفراد");
                    return(false);
                }
            }
            return(true);
        }
예제 #8
0
 public static bool DeleteData(ItemCriteria x)
 {
     return(BaseDataBase._StoredProcedure("sp_Delete_ItemCriteria"
                                          , new SqlParameter("@ID", x.ID)));
 }