Ejemplo n.º 1
0
        private void btnDeleteTask_Click(object sender)
        {
            if (projectproject_template_detailViewSource.View != null)
            {
                projectproject_template_detailViewSource.View.Filter = null;
                List <project_template_detail> project_template_detailLIST = treeProject.ItemsSource.Cast <project_template_detail>().ToList();
                project_template_detailLIST = project_template_detailLIST.Where(x => x.IsSelected == true).ToList();
                using (db db = new db())
                {
                    foreach (project_template_detail project_template_detail in project_template_detailLIST)
                    {
                        project_template_detail _project_template_detail = db.project_template_detail.Where(x => x.id_template_detail == project_template_detail.id_template_detail).FirstOrDefault();

                        db.project_template_detail.Remove(_project_template_detail);
                    }
                    db.SaveChanges();
                }

                ProjectTemplateDB          = new ProjectTemplateDB();
                project_templateViewSource = ((CollectionViewSource)(FindResource("project_templateViewSource")));
                ProjectTemplateDB.project_template.Where(a => a.id_company == CurrentSession.Id_Company).Load();
                project_templateViewSource.Source = ProjectTemplateDB.project_template.Local;
                filter_task();
            }
        }
Ejemplo n.º 2
0
 public void filter_task()
 {
     if (projectproject_template_detailViewSource != null)
     {
         if (projectproject_template_detailViewSource.View != null)
         {
             projectproject_template_detailViewSource.View.Filter = i =>
             {
                 project_template_detail project_template_detail = (project_template_detail)i;
                 if (project_template_detail.State != EntityState.Deleted)
                 {
                     if (project_template_detail.parent == null)
                     {
                         return(true);
                     }
                     else
                     {
                         return(false);
                     }
                 }
                 else
                 {
                     return(false);
                 }
             };
         }
     }
 }
Ejemplo n.º 3
0
        private void btnAddParentTask_Click(object sender)
        {
            stpcode.IsEnabled = true;
            //itemSearchViewSource.View.Filter = i =>
            //{
            //    item item = (item)i;
            //    if (item.is_active == true)
            //        return true;
            //    else
            //        return false;
            //};
            project_template project_template = project_templateViewSource.View.CurrentItem as project_template;

            project_template_detail n_project_template = new project_template_detail();

            n_project_template.id_project_template = project_template.id_project_template;
            n_project_template.status = Status.Project.Pending;
            ProjectTemplateDB.project_template_detail.Add(n_project_template);

            projectproject_template_detailViewSource.View.Filter = null;

            filter_task();
            projectproject_template_detailViewSource.View.MoveCurrentToLast();
            treeProject.SelectedItem_ = n_project_template;
        }
Ejemplo n.º 4
0
 private void item_Select(object sender, EventArgs e)
 {
     if (sbxItem.ItemID > 0)
     {
         item item = ProjectTemplateDB.items.Where(x => x.id_item == sbxItem.ItemID).FirstOrDefault();
         project_template_detail project_template_detail = (project_template_detail)treeProject.SelectedItem_;
         project_template_detail.id_item = item.id_item;
         project_template_detail.item    = item;
     }
 }
Ejemplo n.º 5
0
        private void btnNewTask_Click(object sender)
        {
            stpcode.IsEnabled = true;
            //itemSearchViewSource.View.Filter = i =>
            //{
            //    item item = (item)i;
            //    if (item.is_active == true)
            //        return true;
            //    else
            //        return false;
            //};


            project_template        project_template        = project_templateViewSource.View.CurrentItem as project_template;
            project_template_detail project_template_detail = treeProject.SelectedItem_ as project_template_detail;

            if (project_template_detail != null && project_template_detail.item.id_item_type == entity.item.item_type.Task)
            {
                //Adding a Child Item.
                project_template_detail n_project_template = new project_template_detail();
                n_project_template.id_project_template = project_template.id_project_template;
                n_project_template.status = Status.Project.Pending;
                project_template_detail.child.Add(n_project_template);

                ProjectTemplateDB.project_template_detail.Add(n_project_template);

                projectproject_template_detailViewSource.View.Filter = null;

                filter_task();
                treeProject.SelectedItem_ = n_project_template;
            }
            else
            {
                toolBar.msgWarning("Please Select Task");
            }
            projectproject_template_detailViewSource.View.MoveCurrentToLast();
        }
Ejemplo n.º 6
0
        private void project_Changed()
        {
            List <project_template_detail> _projectTemplate = new List <project_template_detail>();
            int selectid = Convert.ToInt32(id_project);

            _projectTemplate = entity.db.project_template_detail.Where(x => x.id_project_template == selectid).ToList();
            project_template_detail accesories_template       = _projectTemplate.Where(x => x.logic == "Accessory").FirstOrDefault();
            project_template_detail accesories_x_qty_template = _projectTemplate.Where(x => x.logic == "Accessory Per Quantity").FirstOrDefault();
            project_template_detail ink_template     = _projectTemplate.Where(x => x.logic == "ink").FirstOrDefault();
            project_template_detail printer_template = _projectTemplate.Where(x => x.logic == "printer").FirstOrDefault();
            project_template_detail toner_template   = _projectTemplate.Where(x => x.logic == "Toner").FirstOrDefault();
            project_template_detail paper_template   = _projectTemplate.Where(x => x.logic == "paper").FirstOrDefault();
            project_template_detail cut_template     = _projectTemplate.Where(x => x.logic == "Cut").FirstOrDefault();

            //project_template_detail accesory_abc = _projectTemplate.Where(x => x.logic == "accesory_abc").FirstOrDefault();

            if (ink_template != null)
            {
                int _inkTag = Convert.ToInt16(ink_template.id_tag);

                cmbink.SelectedValuePath = "id_item";
                cmbink.DisplayMemberPath = "name";
                cmbink.ItemsSource       = entity.db.items
                                           .Where(x => entity.db.item_tag_detail.Where(y => y.id_tag == _inkTag)
                                                  .Select(z => z.id_item)
                                                  .Contains(x.id_item)).ToList();
                cmbvalue.ItemsSource = ink_Percentage;
            }

            if (printer_template != null)
            {
                _printerTag = Convert.ToInt16(printer_template.id_tag);

                using (db db = new db())
                {
                    List <item> printerlist = entity.db.items.Where(x => entity.db.item_tag_detail
                                                                    .Where(y => y.id_tag == _printerTag)
                                                                    .Select(z => z.id_item)
                                                                    .Contains(x.id_item)).ToList();

                    foreach (item _item in printerlist)
                    {
                        PrintingPress.Printer _printer = new PrintingPress.Printer();
                        _printer.Id          = _item.id_item;
                        _printer.Name        = _item.name;
                        _printer.Min_Long    = (decimal)_item.item_asset.FirstOrDefault().min_width;
                        _printer.Min_Short   = (decimal)_item.item_asset.FirstOrDefault().min_length;
                        _printer.Max_Long    = (decimal)_item.item_asset.FirstOrDefault().max_width;
                        _printer.Max_Short   = (decimal)_item.item_asset.FirstOrDefault().max_length;
                        _printer.Speed       = (int)_item.item_asset.FirstOrDefault().speed;
                        _printer.Color_Limit = (int)_item.item_property.FirstOrDefault().value;
                        _printer.Cost        = (decimal)_item.unit_cost;
                        _printer.Cost_DieSet = (decimal)_item.item_asset.FirstOrDefault().dieset_price;
                        //Adding to List
                        _printerList.Add(_printer);
                        //stpprinter.ItemsSource = _printerList;
                    }
                }
            }

            if (accesories_template != null)
            {
                int         _accessoryTag = Convert.ToInt16(accesories_template.id_tag);
                List <item> _itemList     = entity.db.items.Where(x => entity.db.item_tag_detail
                                                                  .Where(y => y.id_tag == _accessoryTag)
                                                                  .Select(z => z.id_item).Contains(x.id_item)).ToList();

                foreach (item item in _itemList)
                {
                    int id_item = Convert.ToInt32(item.id_item);
                    if (id_item > 0)
                    {
                        PrintingPress.Accessory accessory = new PrintingPress.Accessory();
                        accessory.Id          = (int)item.id_item;
                        accessory.Cost        = (decimal)item.unit_cost;
                        accessory.Name        = item.name;
                        accessory.Consumption = 1;
                        accessory.Calc_Cost   = accessory.Cost * accessory.Consumption;
                        _accessoryList.Add(accessory);
                    }
                }
                itemaccesories.ItemsSource = _accessoryList.ToList();
            }

            if (toner_template != null)
            {
                int  _tonerTag = Convert.ToInt16(toner_template.id_tag);
                item _toner    = entity.db.items
                                 .Where(x => entity.db.item_tag_detail
                                        .Where(y => y.id_tag == _tonerTag)
                                        .Select(z => z.id_item).Contains(x.id_item)).FirstOrDefault();
            }

            if (cut_template != null)
            {
                int  _cutTag = Convert.ToInt16(cut_template.id_tag);
                item _cut    = entity.db.items
                               .Where(x => entity.db.item_tag_detail
                                      .Where(y => y.id_tag == _cutTag)
                                      .Select(z => z.id_item).Contains(x.id_item)).FirstOrDefault();
            }

            if (paper_template != null)
            {
                int _paperTag = Convert.ToInt16(paper_template.id_tag);
                using (db db = new db())
                {
                    List <item> paperlist = entity.db.items
                                            .Where(x => entity.db.item_tag_detail.Where(y => y.id_tag == _paperTag)
                                                   .Select(z => z.id_item)
                                                   .Contains(x.id_item)).ToList();

                    foreach (item _item in paperlist)
                    {
                        PrintingPress.Paper _paper = new PrintingPress.Paper();
                        _paper.Id = _item.id_item;

                        if (_item.item_dimension.Where(x => x.id_app_dimension == id_Weight).FirstOrDefault() != null)
                        {
                            _paper.Weight = (int)_item.item_dimension.Where(x => x.id_app_dimension == id_Weight).FirstOrDefault().value;
                        }
                        else
                        {
                            _paper.Weight = 0;
                        }

                        _paper.Cost = (decimal)_item.unit_cost;

                        if (_item.item_dimension.Where(x => x.id_app_dimension == id_Long).FirstOrDefault() != null)
                        {
                            _paper.Long = (decimal)_item.item_dimension.Where(x => x.id_app_dimension == id_Long).FirstOrDefault().value;
                        }
                        else
                        {
                            _paper.Long = 0;
                        }

                        if (_item.item_dimension.Where(x => x.id_app_dimension == id_Short).FirstOrDefault() != null)
                        {
                            _paper.Short = (decimal)_item.item_dimension.Where(x => x.id_app_dimension == id_Short).FirstOrDefault().value;
                        }
                        else
                        {
                            _paper.Short = 0;
                        }

                        _paper.Name = _paper.Long.ToString() + " x " + _paper.Short.ToString();
                        //Adding Paper to PaperList
                        _paperList.Add(_paper);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void project()
        {
            MySqlConnection conn      = new MySqlConnection(_connString);
            MySqlCommand    cmd       = new MySqlCommand();
            string          sql_count = " select" +
                                        " sum(a.count)" +
                                        " from" +
                                        " ( select count(*) as count from project union all " +
                                        "   select count(*) as count from project_category union all " +
                                        "  select count(*) as count from project_task ) a ";

            conn.Open();
            cmd.Connection  = conn;
            cmd.CommandText = sql_count;
            cmd.CommandType = CommandType.Text;
            int count = Convert.ToInt32(cmd.ExecuteScalar());

            conn.Close();

            int value = 0;

            Dispatcher.BeginInvoke((Action)(() => projectMaximum.Text = count.ToString()));
            Dispatcher.BeginInvoke((Action)(() => projectValue.Text = value.ToString()));
            Dispatcher.BeginInvoke((Action)(() => progProject.Maximum = count));
            Dispatcher.BeginInvoke((Action)(() => progProject.Value = value));

            string sql_proj_category = " SELECT * FROM project_category;";

            conn.Open();
            cmd.Connection  = conn;
            cmd.CommandText = sql_proj_category;
            cmd.CommandType = CommandType.Text;
            MySqlDataReader category_reader = cmd.ExecuteReader();

            while (category_reader.Read())
            {
                using (db db = new db())
                {
                    project_template project_template = new project_template();
                    project_template.name      = category_reader.GetString("category");
                    project_template.is_active = true;

                    db.project_template.Add(project_template);
                    db.SaveChanges();
                    value += 1;
                    Dispatcher.BeginInvoke((Action)(() => progProject.Value = value));
                    Dispatcher.BeginInvoke((Action)(() => projectValue.Text = value.ToString()));
                }
            }
            conn.Close();

            string sql_template = " SELECT project_template.*, project_category.category, item_sku.product FROM project_template "
                                  + " INNER JOIN project_category ON project_template.id_category = project_category.id"
                                  + " INNER JOIN item_sku ON project_template.id_sku = item_sku.id;";

            conn.Open();
            cmd.Connection  = conn;
            cmd.CommandText = sql_template;
            cmd.CommandType = CommandType.Text;
            MySqlDataReader template_reader = cmd.ExecuteReader();

            while (template_reader.Read())
            {
                using (db db = new db())
                {
                    project_template_detail project_template_detail = new project_template_detail();
                    string category = template_reader.GetString("category");
                    project_template_detail.id_project_template = db.project_template.Where(i => i.name == category).FirstOrDefault().id_project_template;
                    project_template_detail.code             = template_reader.GetString("task_number");
                    project_template_detail.item_description = template_reader.GetString("product");
                    if (db.items.Where(i => i.name == project_template_detail.item_description).FirstOrDefault() != null)
                    {
                        project_template_detail.id_item = db.items.Where(i => i.name == project_template_detail.item_description).FirstOrDefault().id_item;
                        if (template_reader.GetInt16("id_task_rel") == 0)
                        {
                            //no parent. do nothing
                        }
                        else
                        {
                            //has parent
                            string code = template_reader.GetString("task_number");
                            int    pos  = code.LastIndexOf('.');
                            if (pos >= 0)
                            {
                                code = code.Substring(0, pos);
                            }
                            project_template_detail.parent = db.project_template_detail.Where(p => p.code == code &&
                                                                                              p.id_project_template == project_template_detail.id_project_template)
                                                             .FirstOrDefault();
                        }
                        //Insert into Context & Save
                        db.project_template_detail.Add(project_template_detail);
                        db.SaveChanges();
                    }
                }
            }
            conn.Close();

            string sql_proj = " SELECT * FROM project";

            conn.Open();
            cmd.Connection  = conn;
            cmd.CommandText = sql_proj;
            cmd.CommandType = CommandType.Text;
            MySqlDataReader proj_reader = cmd.ExecuteReader();

            while (proj_reader.Read())
            {
                using (db db = new db())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;
                    project project = new project();
                    project.id_project     = proj_reader.GetInt32("id");
                    project.est_start_date = proj_reader.GetDateTime("begin_date");

                    if (proj_reader["id_contact"] is DBNull)
                    {
                        value += 1;
                        continue;
                    }
                    else
                    {
                        project.id_contact = proj_reader.GetInt32("id_contact");
                    }

                    project.name = proj_reader.GetString("project");

                    if (project.Error == null)
                    {
                        db.projects.Add(project);
                        db.SaveChanges();
                        value += 1;
                        Dispatcher.BeginInvoke((Action)(() => progProject.Value = value));
                        Dispatcher.BeginInvoke((Action)(() => projectValue.Text = value.ToString()));
                    }
                }
            }
            conn.Close();

            string sql_proj_task = " SELECT project_task.*, project.project, item_sku.product,app_status.status FROM project_task "
                                   + " INNER JOIN project ON project_task.id_project = project.id"
                                   + " INNER JOIN item_sku ON project_task.id_sku = item_sku.id"
                                   + " INNER JOIN app_status ON project_task.id_status = app_status.id";

            conn.Open();
            cmd.Connection  = conn;
            cmd.CommandText = sql_proj_task;
            cmd.CommandType = CommandType.Text;
            MySqlDataReader proj_task_reader = cmd.ExecuteReader();


            while (proj_task_reader.Read())
            {
                using (db db = new db())
                {
                    project_task project_task = new project_task();
                    string       project      = proj_task_reader.GetString("project");
                    project_task.id_project = db.projects.Where(i => i.name == project).FirstOrDefault().id_project;
                    project_task.code       = proj_task_reader.GetString("task_number");

                    string product = proj_task_reader.GetString("product");
                    if (db.items.Where(i => i.name == product).FirstOrDefault() != null)
                    {
                        project_task.item_description = db.items.Where(i => i.name == product).FirstOrDefault().name;
                        project_task.id_item          = db.items.Where(i => i.name == product).FirstOrDefault().id_item;
                        if (proj_task_reader.GetString("status") == "Aprobado")
                        {
                            project_task.status = Status.Project.Approved;
                        }
                        else if (proj_task_reader.GetString("status") == "Pendiente")
                        {
                            project_task.status = Status.Project.Pending;
                        }

                        if (!(proj_task_reader["qty"] is DBNull))
                        {
                            project_task.quantity_est = proj_task_reader.GetInt16("qty");
                        }



                        if (proj_task_reader.GetInt16("id_task_rel") == 0)
                        {
                            //no parent. do nothing
                        }
                        else
                        {
                            //has parent
                            string code = proj_task_reader.GetString("task_number");
                            //logic to have children

                            if (project_task.quantity_est == null)
                            {
                                var pos = code.LastIndexOf('.');
                                if (pos >= 0)
                                {
                                    code = code.Substring(0, pos);
                                    project_task.parent = db.project_task.Where(p => p.code == code &&
                                                                                p.id_project == project_task.id_project
                                                                                ).FirstOrDefault();
                                }
                            }
                            else
                            {
                                project_task.parent = db.project_task.Where(p => p.code == code &&
                                                                            p.id_project == project_task.id_project
                                                                            ).FirstOrDefault();
                            }
                        }

                        //if (project_task.Error == null)
                        //{
                        db.project_task.Add(project_task);
                        //}
                    }
                    else
                    {
                    }



                    string sql_task = "SELECT * FROM project_task_dimension inner join app_dimension on app_dimension.id=project_task_dimension.id_dimension inner join project_task on project_task.id=project_task_dimension.id_task where id_task=" + proj_task_reader.GetInt32("id");
                    try
                    {
                        MySqlConnection conntask = new MySqlConnection(_connString);
                        MySqlCommand    cmdtask  = new MySqlCommand();
                        conntask.Open();
                        cmdtask.Connection  = conntask;
                        cmdtask.CommandText = sql_task;
                        cmdtask.CommandType = CommandType.Text;
                        MySqlDataReader task_reader = cmdtask.ExecuteReader();
                        while (task_reader.Read())
                        {
                            project_task_dimension project_task_dimension = new project_task_dimension();
                            string name = task_reader.GetString("dimension");
                            if (db.app_dimension.Where(x => x.name == name).FirstOrDefault() != null)
                            {
                                project_task_dimension.id_dimension   = db.app_dimension.Where(x => x.name == name).FirstOrDefault().id_dimension;
                                project_task_dimension.project_task   = project_task;
                                project_task_dimension.value          = task_reader.GetInt32("value");
                                project_task_dimension.id_measurement = db.app_measurement.FirstOrDefault().id_measurement;
                                if (project_task_dimension.Error == null)
                                {
                                    db.project_task_dimension.Add(project_task_dimension);
                                }
                            }
                        }
                        task_reader.Close();
                        cmdtask.Dispose();
                        conntask.Close();
                    }
                    catch (Exception ex)
                    { throw ex; }


                    IEnumerable <DbEntityValidationResult> validationresult = db.GetValidationErrors();
                    if (validationresult.Count() == 0)
                    {
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        value += 1;
                        Dispatcher.BeginInvoke((Action)(() => progProject.Value = value));
                        Dispatcher.BeginInvoke((Action)(() => projectValue.Text = value.ToString()));
                    }
                }
            }
            cmd.Dispose();
            conn.Close();
        }