コード例 #1
0
ファイル: ManagerService.cs プロジェクト: jakuste/CarWorkshop
 public static void UpdateObject(DataLayer.Object obj)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = (from el in dc.Object
                       where
                       el.id_object == obj.id_object
                       select el).SingleOrDefault();
         if (result == null)
         {
             return;
         }
         result.name         = obj.name;
         result.body_type    = obj.body_type;
         result.id_client    = obj.id_client;
         result.manufacturer = obj.manufacturer;
         result.model        = obj.model;
         result.other        = obj.other;
         result.year         = obj.year;
         result.engine       = obj.engine;
         dc.SaveChanges();
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
コード例 #2
0
ファイル: ManagerSection.cs プロジェクト: luszula/BD_Project
 public static string EditObject(int currentId, string selected, string name, string clientId)
 {
     using (DataClasses1DataContext connection = new DataClasses1DataContext())
     {
         DataLayer.Object updtObj = connection.Object.SingleOrDefault(x => x.id_obj == currentId);
         updtObj.name      = name;
         updtObj.code_type = (from obj in connection.Obj_Type
                              where obj.name_type == selected
                              select obj.code_type).SingleOrDefault();
         int cid = 0;
         if (Int32.TryParse(clientId, out cid))
         {
             updtObj.id_cli = cid;
         }
         try
         {
             connection.SubmitChanges();
             return("Zakończono powodzeniem");
         }
         catch
         {
             return("Zakończono niepowodzeniem");
         }
     }
 }
コード例 #3
0
ファイル: ManagerService.cs プロジェクト: jakuste/CarWorkshop
 public static IQueryable <DataLayer.Object> GetObjects(DataLayer.Object searchCrit)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var result = from el in dc.Object
                      where
                      String.IsNullOrEmpty(searchCrit.body_type) || el.body_type.StartsWith(searchCrit.body_type)
                      &&
                      (searchCrit.id_client == null) || (el.id_client == searchCrit.id_client)
                      &&
                      String.IsNullOrEmpty(searchCrit.manufacturer) || el.manufacturer.StartsWith(searchCrit.manufacturer)
                      &&
                      String.IsNullOrEmpty(searchCrit.model) || el.model.StartsWith(searchCrit.model)
                      &&
                      String.IsNullOrEmpty(searchCrit.name) || el.name.StartsWith(searchCrit.name)
                      &&
                      String.IsNullOrEmpty(searchCrit.other) || el.other.StartsWith(searchCrit.other)
                      &&
                      String.IsNullOrEmpty(searchCrit.engine) || el.other.StartsWith(searchCrit.engine)
                      &&
                      (searchCrit.year == null) || (el.year == searchCrit.year)
                      select el;
         return(result);
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
コード例 #4
0
ファイル: ManagerSection.cs プロジェクト: luszula/BD_Project
        ///KAROL SZUSTER

        public static string AddNewObject(string nameNew, string name_typeNew, int clientIdNew)
        {
            using (DataClasses1DataContext connection = new DataClasses1DataContext())
            {
                string code = (from obj in connection.Obj_Type
                               where obj.name_type == name_typeNew
                               select obj.code_type).SingleOrDefault();

                DataLayer.Object addNew = new DataLayer.Object
                {
                    name      = nameNew,
                    code_type = code,
                    id_cli    = clientIdNew,
                };

                if (code == null)
                {
                    return("Wybrano niepoprawny obiekt");
                }
                else
                {
                    try
                    {
                        connection.Object.InsertOnSubmit(addNew);
                        connection.SubmitChanges();
                        return("Zakończono powodzeniem");
                    }
                    catch
                    {
                        return("Zakończono niepowodzeniem");
                    }
                }
            }
        }
コード例 #5
0
 private void SearchObjects_Button_Click(object sender, EventArgs e)
 {
     DataLayer.Object obj = new DataLayer.Object();
     obj.name                = Name_TextBox.Text;
     obj.manufacturer        = Manufacturer_TextBox.Text;
     obj.registration_number = RegistrationNo_TextBox.Text;
     obj.model               = Model_TextBox.Text;
     GetObjects(obj);
 }
コード例 #6
0
 private void ShowObjects_Button_Click(object sender, EventArgs e)
 {
     if (Customers_DataGridView.CurrentRow == null)
     {
         Alert.DisplayError("No item selected!");
         return;
     }
     DataLayer.Object obj = new DataLayer.Object();
     obj.id_client = ((Client)Customers_DataGridView.CurrentRow.DataBoundItem).id_client;
     GetObjects(obj);
     //change the tab
     ManagerMainWindow_TabControl.SelectedIndex = 1;
 }
コード例 #7
0
        public ObjectEditor(DataLayer.Object obj)
        {
            InitializeComponent();
            this.obj = obj;
            GetTypes();

            Type_ComboBox.Text = (from el in types where el.code_type == obj.code_type select el.name_type).SingleOrDefault();
            Name_TextBox.Text  = obj.name;
            RegistrationNumber_TextBox.Text = obj.registration_number;
            Manufacturer_TextBox.Text       = obj.manufacturer;
            Model_TextBox.Text    = obj.model;
            BodyType_TextBox.Text = obj.body_type;
            Engine_TextBox.Text   = obj.engine;
            Year_textBox.Text     = obj.year.ToString();
            Other_TextBox.Text    = obj.other;
        }
コード例 #8
0
        public RequestEditor(DataLayer.Object obj)
        {
            InitializeComponent();
            this.obj = obj;
            BodyType_TextBox.Text           = obj.body_type;
            Name_TextBox.Text               = obj.name;
            Engine_TextBox.Text             = obj.engine;
            Manufacturer_TextBox.Text       = obj.manufacturer;
            Year_TextBox.Text               = obj.year.ToString();
            Model_TextBox.Text              = obj.model;
            Other_TextBox.Text              = obj.other;
            RegistrationNumber_TextBox.Text = obj.registration_number;
            Status_TextBox.Text             = "In progress";

            AddActivity_Button.Enabled    = false;
            DeleteActivity_Button.Enabled = false;
        }
コード例 #9
0
 private void EditObject_Button_Click(object sender, EventArgs e)
 {
     if (Objects_DataGridView.CurrentRow == null)
     {
         Alert.DisplayError("No item selected!");
         return;
     }
     DataLayer.Object obj = new DataLayer.Object();
     obj.id_object = (int)Objects_DataGridView.CurrentRow.Cells[0].Value;
     try
     {
         obj = ManagerService.GetObjects(obj).SingleOrDefault();
         ObjectEditor objectEditor = new ObjectEditor(obj);
         objectEditor.ShowDialog();
     }catch (ServiceException exc)
     {
         Alert.DisplayError(exc.Message);
     }
 }
コード例 #10
0
ファイル: ManagerService.cs プロジェクト: jakuste/CarWorkshop
 public static void DeleteObject(DataLayer.Object obj)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var res = (from el in dc.Object
                    where el.id_object == obj.id_object
                    select el).SingleOrDefault();
         if (res == null)
         {
             return;
         }
         dc.Object.Remove(res);
         dc.SaveChanges();
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
コード例 #11
0
ファイル: ManagerService.cs プロジェクト: jakuste/CarWorkshop
 public static void NewObject(DataLayer.Object obj)
 {
     try
     {
         CarWorkshopModelContext dc = new CarWorkshopModelContext();
         var res = (from el in dc.Object
                    where el.registration_number == obj.registration_number
                    select el).SingleOrDefault();
         if (res == null)
         {
             dc.Object.Add(obj);
             dc.SaveChanges();
             return;
         }
         throw new ServiceException("Object already exists!");
     }
     catch (System.Data.Entity.Core.EntityException e)
     {
         throw new ServiceException("Database connection error!");
     }
 }
コード例 #12
0
        private void Save_Button_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(RegistrationNumber_TextBox.Text) || String.IsNullOrWhiteSpace(Type_ComboBox.Text))
            {
                Alert.DisplayError("Registration number box must be filled!");
                return;
            }
            try
            {
                if (obj == null)
                {
                    obj = new DataLayer.Object();
                }
                obj.code_type           = (from el in types where el.name_type == Type_ComboBox.Text select el.code_type).SingleOrDefault();
                obj.name                = Name_TextBox.Text;
                obj.registration_number = RegistrationNumber_TextBox.Text;
                obj.manufacturer        = Manufacturer_TextBox.Text;
                obj.model               = Model_TextBox.Text;
                obj.body_type           = BodyType_TextBox.Text;
                obj.engine              = Engine_TextBox.Text;
                obj.year                = Int32.Parse(Year_textBox.Text);
                obj.other               = Other_TextBox.Text;

                if (client == null)
                {
                    ManagerService.UpdateObject(obj);
                }
                else
                {
                    obj.id_client = client.id_client;
                    ManagerService.NewObject(obj);
                }
                this.Close();
                this.Dispose();
            }
            catch (ServiceException exc)
            {
                Alert.DisplayError(exc.Message);
            }
        }
コード例 #13
0
        // Get object from database and display
        private void GetObjects(DataLayer.Object obj)
        {
            try
            {
                var result = ManagerService.GetObjects(obj);
                Objects_DataGridView.Columns.Clear();

                Objects_DataGridView.DataSource = (from ob in result select new {
                    ob.id_object,
                    ob.Client.name,
                    ob.Client.last_name,
                    ObName = ob.name,
                    ob.registration_number,
                    ob.manufacturer,
                    ob.model,
                    ob.body_type,
                    ob.year,
                    ob.engine,
                    ob.Object_type.name_type
                }).ToList();

                Objects_DataGridView.Columns[0].Visible = false;

                Objects_DataGridView.Columns[1].HeaderText  = "Customer's name";
                Objects_DataGridView.Columns[2].HeaderText  = "Customer's surname";
                Objects_DataGridView.Columns[3].HeaderText  = "Name";
                Objects_DataGridView.Columns[4].HeaderText  = "Registration No.";
                Objects_DataGridView.Columns[5].HeaderText  = "Manufacturer";
                Objects_DataGridView.Columns[6].HeaderText  = "Model";
                Objects_DataGridView.Columns[7].HeaderText  = "Body type";
                Objects_DataGridView.Columns[8].HeaderText  = "Year";
                Objects_DataGridView.Columns[9].HeaderText  = "Engine";
                Objects_DataGridView.Columns[10].HeaderText = "Type";
            }
            catch (ServiceException exc)
            {
                Alert.DisplayError(exc.Message);
            }
        }
コード例 #14
0
 private void DeleteObject_Button_Click(object sender, EventArgs e)
 {
     if (Objects_DataGridView.CurrentRow == null)
     {
         Alert.DisplayError("No item selected!");
         return;
     }
     try
     {
         DataLayer.Object obj = new DataLayer.Object();
         obj.id_object = (int)Objects_DataGridView.CurrentRow.Cells[0].Value;
         ManagerService.DeleteObject(obj);
         int             index           = Objects_DataGridView.CurrentRow.Index;
         CurrencyManager currencyManager = (CurrencyManager)BindingContext[Objects_DataGridView.DataSource];
         currencyManager.SuspendBinding();
         Objects_DataGridView.Rows[index].Visible = false;
         currencyManager.ResumeBinding();
     }
     catch (ServiceException exc)
     {
         Alert.DisplayError(exc.Message);
     }
 }
コード例 #15
0
 private void FillObject(DataLayer.Object obj)
 {
 }