public void InsertCategory(Category item) { if (item != null) { _context.Categories.InsertOnSubmit(item); _context.SubmitChanges(); } }
private void button_Click(object sender, RoutedEventArgs e) { using (AppDataContext context = new AppDataContext(AppDataContext.DbConnectionString)) { bool doesExist = context.Incomes.Any(o => o.IncomeId == Int32.Parse(IdTextBox.Text) && o.CreatedBy == GlobalClass.whoIsLoggedIn); var delIncome = context.Incomes.Where(o => o.IncomeId == Int32.Parse(IdTextBox.Text) && o.CreatedBy == GlobalClass.whoIsLoggedIn) .ToList(); if (doesExist) { foreach (var del in delIncome) { context.Incomes.DeleteAllOnSubmit(delIncome); } context.SubmitChanges(); MessageBox.Show("Income entry deleted"); NavigationService.Navigate(new Uri("/Views/Income.xaml", UriKind.Relative)); } else { MessageBox.Show("This entry does not exist"); } } }
private void submitButton_Click(object sender, RoutedEventArgs e) { double?enteredId = Double.Parse(IdTextBox.Text); bool isOwnedByUser = context.Expenditures.Any(o => o.CreatedBy == GlobalClass.whoIsLoggedIn && o.ExpenditureId == enteredId); if (isOwnedByUser) { var entryToEdit = context.Expenditures.SingleOrDefault(o => o.ExpenditureId == enteredId); if (amountTextBox.Text != "") { entryToEdit.Amount = double.Parse(amountTextBox.Text); } if (descriptionTextBox.Text != "") { entryToEdit.Description = descriptionTextBox.Text; } context.SubmitChanges(); MessageBox.Show("Expenditure successfully amended"); NavigationService.Navigate(new Uri("/Views/Expenditure.xaml", UriKind.Relative)); } else { MessageBox.Show("No entry exists with this ID"); } }
private void addButton_Click(object sender, RoutedEventArgs e) { if (amountTextBox.Text == "") { MessageBox.Show("Please enter an amount"); } else if (descriptionTextBox.Text == "") { MessageBox.Show("Please enter a description"); } else { using (AppDataContext context = new AppDataContext(AppDataContext.DbConnectionString)) { Model.Income exp = new Model.Income(); exp.Amount = Double.Parse(amountTextBox.Text); exp.Description = descriptionTextBox.Text; exp.CreatedBy = GlobalClass.whoIsLoggedIn; context.Incomes.InsertOnSubmit(exp); context.SubmitChanges(); } MessageBox.Show("Income added"); NavigationService.Navigate(new Uri("/Views/Income.xaml", UriKind.Relative)); } }
private void button_Click(object sender, RoutedEventArgs e) { bool changesMade = false; var user = context.Users.SingleOrDefault(o => o.Username == GlobalClass.whoIsLoggedIn); if (emailField.Text != "") { user.Email = emailField.Text; changesMade = true; } if (salaryField.Text != "") { user.Salary = Double.Parse(salaryField.Text); changesMade = true; } if (passwordBox.Password != "") { user.Password = passwordBox.Password; changesMade = true; } if (changesMade) { context.SubmitChanges(); MessageBox.Show("Details successfully amended"); NavigationService.Navigate(new Uri("/Views/Account.xaml", UriKind.Relative)); } else { MessageBox.Show("You have not made any changes, please try again or touch back to return to the account screen"); } }
private void button_Click(object sender, RoutedEventArgs e) { using (AppDataContext context = new AppDataContext(AppDataContext.DbConnectionString)) { bool userTaken = context.Users.Any(o => o.Username == userNameField.Text); if (passwordBox.Password == "") { MessageBox.Show("Please enter a password"); } else if (userNameField.Text == "") { MessageBox.Show("Please enter a user name"); } else if ( !Regex.IsMatch(emailField.Text.Trim(), @"^([a-zA-Z_])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$")) { MessageBox.Show("Please enter a valid email format"); } else if (userTaken) { MessageBox.Show("User name already taken"); } else { User du = new User(); du.Username = userNameField.Text; du.Email = emailField.Text; du.Password = passwordBox.Password; du.Salary = Double.Parse(salaryField.Text); context.Users.InsertOnSubmit(du); context.SubmitChanges(); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } } }
// Thêm tài khoản vào bảng TAIKHOAN public void Them(int imatk, String itentk, String imatKhau, int iloai) { HS.usp_InsertTaiKhoan(imatk, itentk, imatKhau, iloai); HS.SubmitChanges(); }
protected void startLocating_Click(object sender, EventArgs e) { if (!this.IsLocatingServiceAvailable) { feedbacks.Items.AddError("请求失败,请检查 LocatingService 是否可被连接。"); LoadRepeater(); return; } int[] tagIdArray = Strings.ParseToArray <int>(selectedTagIds.Value); if (tagIdArray.Length == 0) { feedbacks.Items.AddError("操作失败,没有选中任何记录行。"); LoadRepeater(); return; } IList <string> selectedChannels = new List <string>(); foreach (ListItem item in scanChannels.Items) { if (item.Selected) { selectedChannels.Add(item.Value); } } //自定将标签启动定位,从配置文件中加载数据 XDocument xDoc = XDocument.Load(Server.MapPath(PathUtil.ResolveUrl("Settings/LocateParameters.xml"))); XElement root = xDoc.Element("Parameters"); int surveyGroupId = int.Parse(root.Element("SurveyGroup").Value); using (AppDataContext db = new AppDataContext()) { SurveyGroup surveryGroupValue = db.SurveyGroups.FirstOrDefault(); if (surveryGroupValue != null) { surveyGroupId = surveryGroupValue.Id; } } TagLocateSetting useSettingModel = new TagLocateSetting { LocatingMode = byte.Parse(root.Element("LocatingMode").Value), RssiBackCount = int.Parse(root.Element("RssiBackCount").Value), ScanInterval = int.Parse(root.Element("ScanInterval").Value), ScanMode = byte.Parse(root.Element("ScanMode").Value), ScanSsid = root.Element("ScanSsid").Value, ScanChannels = root.Element("ScanChannels").Value, ScanTarget = byte.Parse(root.Element("ScanTarget").Value), SurveyGroupId = surveyGroupId, UpdateTime = DateTime.Now, CommandState = (byte)LocatingCommandState.WaitToStart }; //TagLocateSetting useSettingModel = new TagLocateSetting { // LocatingMode = byte.Parse(locatingMode.SelectedValue), // RssiBackCount = int.Parse(rssiBackCount.SelectedValue), // ScanInterval = int.Parse(scanInterval.SelectedValue), // ScanMode = 2, // ScanSsid = scanSsid.Text.Trim(), // ScanChannels = string.Join(",", selectedChannels.ToArray()), // ScanTarget = byte.Parse(scanTarget.SelectedValue), // SurveyGroupId = int.Parse(surveyGroup.SelectedValue), // UpdateTime = DateTime.Now, // CommandState = (byte)LocatingCommandState.WaitToStart //}; if (Config.Settings.ProjectType == ProjectTypeEnum.WXFactory) { useSettingModel.ScanMode = 1; TagSetting useSetting = new TagSetting { ScanMarkEnable = true, ScanMarkDetectInterval = Convert.ToInt32(this.detectInterval.Text.Trim()), ScanMarkScanTime = Convert.ToInt32(this.scanTime.Text.Trim()), ScanMarkScanInterval = Convert.ToInt32(this.wscanInterval.Text.Trim()), ScanMarkScanCount = Convert.ToInt32(this.scanCount.Text.Trim()), ScanMarkGoodSignal = Convert.ToInt32(this.goodSignal.Text.Trim()), ScanMarkLocatingInterval = Convert.ToInt32(this.locatingInterval.Text.Trim()) }; foreach (var id in tagIdArray) { if (id > 0) { using (AppDataContext db = new AppDataContext()) { var dbTagSet = db.TagSettings.SingleOrDefault(t => t.TagId == id); if (dbTagSet != null) { dbTagSet.ScanMarkEnable = true; dbTagSet.ScanMarkDetectInterval = useSetting.ScanMarkDetectInterval; dbTagSet.ScanMarkScanTime = useSetting.ScanMarkScanTime; dbTagSet.ScanMarkScanInterval = useSetting.ScanMarkScanInterval; dbTagSet.ScanMarkScanCount = useSetting.ScanMarkScanCount; dbTagSet.ScanMarkGoodSignal = useSetting.ScanMarkGoodSignal; dbTagSet.ScanMarkLocatingInterval = useSetting.ScanMarkLocatingInterval; db.SubmitChanges(); } //else if (dbTagSet.ScanMarkDetectInterval != 0 && dbTagSet.ScanMarkGoodSignal != 0) //{ // this.detectInterval.Text = dbTagSet.ScanMarkDetectInterval.ToString(); // this.scanTime.Text = dbTagSet.ScanMarkScanTime.ToString(); // this.wscanInterval.Text = dbTagSet.ScanMarkScanInterval.ToString(); // this.scanCount.Text = dbTagSet.ScanMarkScanCount.ToString(); // this.goodSignal.Text = dbTagSet.ScanMarkGoodSignal.ToString(); // this.locatingInterval.Text = dbTagSet.ScanMarkLocatingInterval.ToString(); //} } } } } TagLocateSetting.StartLocating(tagIdArray, useSettingModel); // Send a command to LocatingService. LocatingServiceUtil.Instance <IServiceApi>().StartStopLocating(); // Reload List LoadRepeater(); }