private void ButtonAdd_Click(object sender, RoutedEventArgs e) { if (Validation()) { Darkhastha darkhast = new Darkhastha(); darkhast.DarkhastGUID = Guid.NewGuid(); darkhast.DarkhastName = TextBoxDarkhastName.Text; darkhast.ShomareFani = TextBoxShomareFani.Text; if (ComboBoxDastgahName.SelectedIndex != -1) { darkhast.DastgahGUID = ((Dastgahha)ComboBoxDastgahName.SelectedItem).DastgahGUID; } darkhast.VahedShomaresh = TextBoxVahedShomaresh.Text; darkhast.TedadDarkhast = Convert.ToInt32(NumericUpDownTedadDarkhast.Value); darkhast.Tarikh = DateTime.Now; darkhast.Tozihat = TextBoxTozihat.Text; darkhast.BarghkarGUID = Lib.Global.CurrentUserGuid; if (Lib.Global.CurrentUserRole == (int)UserRole.Admin) { darkhast.Vaziat = (int)VaziatDarkhast.TaeedShode; } Entities.Darkhasthas.AddObject(darkhast); if (Entities.SaveChanges() > 0) { Darkhastha_Log2.InsertLog(darkhast, RevisionOperation.Insert); StatusBar1.Items.Clear(); StatusBar1.Items.Add("درخواست جديد با موفقيت ثبت شد"); ClearAllInputs(); OnDarkhastAdded(new EventArgs()); } else { StatusBar1.Items.Clear(); StatusBar1.Items.Add("خطا در ثبت"); } TimerClearStatusBar.Interval = new TimeSpan(0, 0, 10); TimerClearStatusBar.Tick += new EventHandler(TimerClearStatusBar_Tick); TimerClearStatusBar.Start(); } }
private void ButtonAdd_Click(object sender, RoutedEventArgs e) { if (Validation()) { var darkhastQuery = from d in Entities.Darkhasthas where d.DarkhastGUID == Darkhast.DarkhastGUID select d; Darkhastha darkhast = darkhastQuery.FirstOrDefault(); darkhast.DarkhastName = TextBoxDarkhastName.Text; darkhast.ShomareFani = TextBoxShomareFani.Text; if (ComboBoxDastgahName.SelectedIndex != -1) { darkhast.DastgahGUID = ((Dastgahha)ComboBoxDastgahName.SelectedItem).DastgahGUID; } darkhast.VahedShomaresh = TextBoxVahedShomaresh.Text; darkhast.TedadDarkhast = Convert.ToInt32(NumericUpDownTedadDarkhast.Value); //darkhast.Tarikh = DateTime.Now; darkhast.Tozihat = TextBoxTozihat.Text; darkhast.BarghkarGUID = Lib.Global.CurrentUserGuid; if (Lib.Global.CurrentUserRole == (int)UserRole.Admin) { darkhast.Vaziat = (int)VaziatDarkhast.TaeedShode; } //Entities.Darkhasthas.AddObject(Darkhast); Darkhastha_Log2.InsertLog(darkhast, RevisionOperation.Update); Entities.SaveChanges(); StatusBar1.Items.Clear(); StatusBar1.Items.Add("درخواست با موفقيت ویرایش شد"); //ClearAllInputs(); OnDarkhastEdited(new EventArgs()); //StatusBar1.Items.Clear(); //StatusBar1.Items.Add("خطا در ثبت"); TimerClearStatusBar.Interval = new TimeSpan(0, 0, 10); TimerClearStatusBar.Tick += new EventHandler(TimerClearStatusBar_Tick); TimerClearStatusBar.Start(); } }