예제 #1
0
 private void SubmitButton_Click(object sender, RoutedEventArgs e)
 {
     // 读取list
     // 将归还数量写入
     // 将钱数写入
     // 减少没有归还的数量
     // 如果没有归还的数量为0,将finish改为1,写入归还时间
     // 设备数增加
     if (lrlis.Count == 0)
     {
         return;
     }
     using (var context = new EMDBEntities())
     {
         foreach (var item in lrlis)
         {
             if (item.IsReturn && item.Num > 0)
             {
                 Record r = context.Records.First(m => m.Id == item.id);
                 r.ReturnNum += item.Num;
                 r.LendNum   -= item.Num;
                 r.Total     += item.Money;
                 if (r.LendNum == 0)
                 {
                     r.Finish = 1;
                     r.End    = DateTime.Now;
                 }
                 r.Equipment.Num += item.Num;
                 context.SaveChanges();
             }
         }
     }
     MessageBox.Show("归还成功");
     Close();
 }
        public LeaseWindow()
        {
            InitializeComponent();
            try
            {
                using (var context = new EMDBEntities())
                {
                    List <Equipment> les = context.Equipments.ToList();

                    foreach (var item in les)
                    {
                        lelis.Add(new MyListItem {
                            Equipment = item, Num = 0, Remain = item.Num
                        });
                    }
                    DataGrid1.ItemsSource = lelis;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message);
            }

            TimeTextBox.Text = DateTime.Now.ToString();
        }
 private void Button_Click_3(object sender, RoutedEventArgs e)
 {
     using (var db = new EMDBEntities())
     {
         string           s  = SearchTextBox.Text.Trim();
         List <Equipment> le = db.Equipments.SqlQuery("select * from Equipments where name like '%" + s + "%'").ToList();
         ecs = new ObservableCollection <Equipment>(le);
         DataGrid1.ItemsSource = ecs;
     }
 }
        public EquipmentListPage()
        {
            InitializeComponent();

            using (var context = new EMDBEntities())
            {
                ecs = new ObservableCollection <Equipment>(context.Equipments.ToList());

                DataGrid1.ItemsSource = ecs;
            }
        }
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Equipment        ec  = (sender as Button).Tag as Equipment;
            MessageBoxResult mbr = MessageBox.Show("是否删除" + ec.Name, "删除", MessageBoxButton.OKCancel, MessageBoxImage.Warning);

            if (mbr == MessageBoxResult.OK)
            {
                using (var context = new EMDBEntities())
                {
                    context.Entry(ec).State = EntityState.Deleted;
                    context.SaveChanges();
                    ecs.Remove(ec);
                }
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            using (var db = new EMDBEntities())
            {
                Key k   = db.Keys.FirstOrDefault();
                MD5 md5 = new MD5CryptoServiceProvider();
                if (k == null)
                {
                    MessageBox.Show("当前版本未激活,可免费试用15天");
                    Key key = new Key();

                    string str    = Guid.NewGuid().ToString();
                    string result = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(str)), 4, 8);
                    result         = result.Replace("-", "").ToLower();
                    key.Serial     = result;
                    key.Activation = "请输入激活码";
                    key.Time       = DateTime.Today;
                    db.Keys.Add(key);
                    db.SaveChanges();
                }
                else
                {
                    if (k.Activation == "请输入激活码")
                    {
                        TimeSpan ts = DateTime.Today - k.Time;
                        if (ts.Days > 15)
                        {
                            MessageBox.Show("试用期已到");
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("还可试用" + (15 - ts.Days) + "天");
                        }
                    }
                    else
                    {
                        string result = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(k.Serial + "xzjs")), 4, 8);
                        result = result.Replace("-", "").ToLower();
                        if (result != k.Activation)
                        {
                            MessageBox.Show("激活码错误");
                            Close();
                        }
                    }
                }
            }
        }
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     using (var db = new EMDBEntities())
     {
         Key k = db.Keys.First();
         if (k.Activation == "请输入激活码")
         {
             SerialTextBox.Text = k.Serial;
         }
         else
         {
             isActiveStackPanel.Visibility  = Visibility.Visible;
             notActiveStackPanel.Visibility = Visibility.Hidden;
         }
     }
 }
예제 #8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            List <TextBox> ltb = new List <TextBox>
            {
                Num, Price
            };

            foreach (var item in ltb)
            {
                if (Validation.GetHasError(item))
                {
                    List <ValidationError> lv = Validation.GetErrors(item).ToList();
                    foreach (var v in lv)
                    {
                        MessageBox.Show(v.ErrorContent.ToString());
                    }
                    return;
                }
            }
            try
            {
                using (var context = new EMDBEntities())
                {
                    if (ec.Id == 0)
                    {
                        context.Equipments.Add(ec);
                        context.SaveChanges();
                        ocec.Add(ec);
                    }
                    else
                    {
                        ec.Remark += "。";
                        context.Entry(ec).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                }
                MessageBox.Show("操作成功");
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #9
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     lrlis = new List <ReturnListItem>();
     using (var context = new EMDBEntities())
     {
         List <Record> lrs        = new List <Record>();
         string        card       = CardPhoneTextBox.Text.Trim();
         double        totalMoney = 0;
         if (Combobox1.SelectedIndex == 1)
         {
             lrs = context.Records.Where(m => m.Card == "NO." + card).Where(m => m.Finish == 0).ToList();
         }
         else
         {
             lrs = context.Records.Where(m => m.Phone == "Phone." + card).Where(m => m.Finish == 0).ToList();
         }
         foreach (var item in lrs)
         {
             ReturnListItem rli = new ReturnListItem();
             rli.id        = item.Id;
             rli.IsReturn  = true;
             rli.dateTime  = Convert.ToDateTime(item.Start);
             rli.time      = Convert.ToInt32((DateTime.Now - rli.dateTime).TotalMinutes);
             rli.name      = item.Equipment.Name;
             rli.Remain    = item.LendNum;
             rli.Num       = item.LendNum;
             rli.Equipment = item.Equipment;
             // 计算钱数
             rli.Money   = rli.GetTotal();
             totalMoney += rli.Money;
             lrlis.Add(rli);
         }
         ReturnListDataGrid.DataContext = lrlis;
         TotalMoneyTextBlock.Text       = totalMoney.ToString();
         if (lrlis.Count == 0)
         {
             MessageBox.Show("没有检测到租赁记录");
         }
     }
 }
 public AccountPage()
 {
     InitializeComponent();
     try
     {
         using (var context = new EMDBEntities())
         {
             List <Record> lr = context.Records.Include("Equipment").OrderByDescending(m => m.Start).ToList();
             //RecordListDataGrid.ItemsSource = lr;
             recordRepoter.Load_Data(lr);
         }
         StartDate.SelectedDate = DateTime.Today;
         EndDate.SelectedDate   = DateTime.Today.AddDays(1);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         if (ex.InnerException != null)
         {
             MessageBox.Show(ex.InnerException.Message);
         }
     }
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Set_Button(ref AllButton);
            Set_Button(ref FinishButton);
            Set_Button(ref UnFinishButton);
            Button b = sender as Button;

            Set_Button(ref b, "#FF3399FF", "White");
            DateTime?startDate = StartDate.SelectedDate;
            DateTime?endDate   = EndDate.SelectedDate;

            if (endDate < startDate)
            {
                MessageBox.Show("结束日期必须大于等于开始日期");
                return;
            }
            using (var context = new EMDBEntities())
            {
                var records = context.Records.Include("Equipment").Where(m => m.Start >= startDate && m.Start <= endDate);
                if (b.Content.ToString() != "全部订单")
                {
                    int flag = 0;
                    if (b.Content.ToString() == "已完成订单")
                    {
                        flag = 1;
                    }
                    records = records.Where(m => m.Finish == flag);
                }
                List <Record> lr = records.OrderByDescending(m => m.Start).ToList();
                //RecordListDataGrid.ItemsSource = lr;
                recordRepoter.Load_Data(lr);
                if (lr.Count == 0)
                {
                    MessageBox.Show("没有相关记录");
                }
            }
        }
예제 #12
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MD5    md5    = new MD5CryptoServiceProvider();
            string str    = SerialTextBox.Text + "xzjs";
            string result = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(str)), 4, 8);

            result = result.Replace("-", "").ToLower();
            if (result == ActiveTextBox.Text)
            {
                using (var db = new EMDBEntities())
                {
                    Key k = db.Keys.First();
                    k.Activation = ActiveTextBox.Text;
                    db.SaveChanges();
                    MessageBox.Show("激活成功");
                    notActiveStackPanel.Visibility = Visibility.Hidden;
                    isActiveStackPanel.Visibility  = Visibility.Visible;
                }
            }
            else
            {
                MessageBox.Show("激活码错误");
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (CardTextBox.Text.Trim() == "" && PhoneTextBox.Text.Trim() == "")
            {
                MessageBox.Show("一卡通和手机号不可都为空");
                return;
            }
            int i = 0;

            if (int.TryParse(NameTextBox.Text, out i))
            {
                MessageBox.Show("租借人姓名不可为纯数字");
                return;
            }
            try
            {
                List <Record> lrs = new List <Record>();
                foreach (var item in lelis)
                {
                    if (item.Num > 0)
                    {
                        lrs.Add(new Record
                        {
                            Name        = NameTextBox.Text,
                            Card        = "NO." + CardTextBox.Text,
                            Phone       = "Phone." + PhoneTextBox.Text,
                            Start       = DateTime.Now,
                            EquipmentId = item.Equipment.Id,
                            LendNum     = item.Num,
                            ReturnNum   = 0,
                            Finish      = 0,
                            Total       = 0
                        });
                    }
                }
                if (lrs.Count > 0)
                {
                    using (var context = new EMDBEntities())
                    {
                        context.Records.AddRange(lrs);
                        context.SaveChanges();
                        foreach (var item in lelis)
                        {
                            Equipment eq = context.Equipments.First(m => m.Id == item.Equipment.Id);
                            eq.Num -= item.Num;
                            context.SaveChanges();
                        }
                    }
                    MessageBox.Show("租赁成功");
                    Close();
                }
                else
                {
                    throw new Exception("请选择租赁设备");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }