コード例 #1
0
 public PriborGroupView(PriborGroup PriborGroup)
 {
     Id    = PriborGroup.Id;
     count = PriborGroup.Count;
     using (var db = new SmetaApplication.DbContexts.SmetaDbAppContext())
     {
         Pribor = db.Pribors.Where(x => x.Id == PriborGroup.PriborId).SingleOrDefault();
     }
     IsYes = true;
 }
コード例 #2
0
        private void MyCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                if (Clipboard.ContainsData(DataFormats.Text))
                {
                    List <string> lines = Clipboard.GetText().Split('\n').ToList();
                    //for (int i = 0; i < lines.Count; i++)
                    //{
                    //    bool t = true;
                    //    string[] array = lines[i].Split('\t');
                    //    for (int j = 0; j < array.Length - 1; j++)
                    //    {
                    //        //MessageBox.Show("=" + array[j] + "=");
                    //        if (!string.IsNullOrEmpty(array[j]))
                    //        {
                    //            t = false;
                    //            break;
                    //        }
                    //    }
                    //    if (t)
                    //    {
                    //        lines.RemoveAt(i);
                    //        i--;
                    //    }
                    //}

                    for (int i = 0; i < lines.Count - 1;)
                    {
                        string allnumber = lines[i];
                        //MessageBox.Show(allnumber);
                        // next Name
                        i++;
                        // next Measure
                        i++;
                        // next KS
                        i++;
                        // next KS In number
                        i++;
                        // next Numbers
                        i++;
                        // next Part 1
                        i++;

                        // Works
                        i++;
                        string[] array  = lines[i].Split('\t');
                        string   number = array[0];
                        //MessageBox.Show("=" + number + "=");
                        using (var db = new SmetaDbAppContext())
                        {
                            Work work = db.Works.Find(x => int.Parse(x.Number) == int.Parse(number) + 216);
                            work.Number2 = number;

                            if (work != null)
                            {
                                //work.Number = allnumber;
                                // next Part 2
                                i++;
                                // first row of the pribors
                                i    += 1;
                                array = lines[i].Split('\t');
                                Helper.ToTimeFromArray(work, array);
                                int    code;
                                double s = 0;
                                double d;

                                // clear pribors
                                //DBConnection.SqlQuery("Delete From PriborGroups Where WorkId = " + work.Id);
                                db.PriborGroups.Where(x => x.WorkId == work.Id).ToList().ForEach(x =>
                                {
                                    x.Delete();
                                });


                                while (i < lines.Count() && array.Length > 0 && int.TryParse(array[0], out code))
                                {
                                    Pribor pribor = db.Pribors.Find(x => int.Parse(x.Code) == code);
                                    // if the pribor be, then must update. Else entre new pribor.
                                    if (pribor != null)
                                    {
                                        //array[10] = array[0].Remove(array[0].Length - 1);
                                        //MessageBox.Show("=" + array[10] + "=");
                                        if (double.TryParse(array[10], out d))
                                        {
                                            pribor.Price = d;
                                        }
                                        pribor.Update();
                                    }
                                    else
                                    {
                                        pribor = new Pribor()
                                        {
                                            Code      = array[0],
                                            Name      = array[1],
                                            Dimension = array[2],
                                            Percent   = 15,
                                        };
                                        if (double.TryParse(array[10], out d))
                                        {
                                            pribor.Price = d;
                                        }
                                        else
                                        {
                                            pribor.Price = 100;
                                        }
                                        pribor.Save();
                                    }
                                    //MessageBox.Show(array[1]);
                                    // add pribor group
                                    //MessageBox.Show("=" + array[0] + "=");
                                    PriborGroup priborGroup = new PriborGroup()
                                    {
                                        PriborId = pribor.Id,
                                        WorkId   = work.Id,
                                        Count    = double.Parse(array[8].Replace('.', ','))
                                    };
                                    priborGroup.Save();

                                    s += priborGroup.Count * (pribor.Price * pribor.Percent * 0.01) / (12 * 30 * 24);

                                    i++;
                                    array = lines[i].Split('\t');
                                    //MessageBox.Show(array[0]);
                                }

                                //List<Pribor> pribors = new List<Pribor>
                                //{
                                //    new Pribor()
                                //    {
                                //        Code = "5006"
                                //    },
                                //    new Pribor()
                                //    {
                                //        Code = "5007"
                                //    },
                                //    new Pribor()
                                //    {
                                //        Code = "5008"
                                //    },
                                //    new Pribor()
                                //    {
                                //        Code = "5009"
                                //    },
                                //    new Pribor()
                                //    {
                                //        Code = "5010"
                                //    }
                                //};
                                //int team_count = db.WorkTeams.Where(x => x.WorkDemId == work.Id).Sum(x => x.Count);
                                //pribors.ForEach(x =>
                                //{
                                //    x = db.Pribors.Find(y => int.Parse(x.Code) == int.Parse(y.Code));
                                //    PriborGroup priborGroup = new PriborGroup()
                                //    {
                                //        PriborId = x.Id,
                                //        WorkId = work.Id,
                                //        Count = team_count
                                //    };
                                //    priborGroup.Save();

                                //    s += priborGroup.Count * (x.Price * x.Percent * 0.01) / (12 * 30 * 24);
                                //});

                                work.PricePribor = s;

                                // begin material
                                // clear materials
                                //DBConnection.SqlQuery("Delete From MaterialGroups Where WorkId = " + work.Id);
                                db.MaterialGroups.Where(x => x.WorkId == work.Id).ToList().ForEach(x =>
                                {
                                    x.Delete();
                                });
                                i++;
                                array = lines[i].Split('\t');
                                s     = 0;
                                while (i < lines.Count() && array.Length > 0 && int.TryParse(array[0], out code))
                                {
                                    Material material = db.Materials.Find(x => int.Parse(x.Code) == code);
                                    // if the pribor be, then must update. Else entre new pribor.
                                    if (material != null)
                                    {
                                        //MessageBox.Show(material.Id.ToString());
                                        if (double.TryParse(array[10], out d))
                                        {
                                            material.Price = d;
                                        }
                                        material.Update().ToString();
                                    }
                                    else
                                    {
                                        material = new Material()
                                        {
                                            Code      = array[0],
                                            Name      = array[1],
                                            Dimension = array[2],
                                        };
                                        if (double.TryParse(array[10], out d))
                                        {
                                            material.Price = d;
                                        }
                                        else
                                        {
                                            material.Price = 100;
                                        }
                                        material.Save();
                                    }

                                    // add pribor group
                                    MaterialGroup materialGroup = new MaterialGroup()
                                    {
                                        MaterialId = material.Id,
                                        WorkId     = work.Id,
                                    };

                                    Helper.ToTimeFromArray(materialGroup, array);

                                    materialGroup.Save();

                                    s += material.Price * materialGroup.Count1;

                                    i++;
                                    if (i < lines.Count)
                                    {
                                        array = lines[i].Split('\t');
                                    }
                                }
                                work.PriceMaterial = s;

                                work.Update();
                            }
                        }
                    }
                    StreamWriter sw = new StreamWriter(@"D:\Programs\Projects\C#\Smeta\Documents 2\base in.txt", true);
                    lines.ForEach(x => { sw.Write(x); });
                    sw.Close();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }
コード例 #3
0
 public PriborContext(PriborGroup PriborGroup)
 {
     this.PriborGroup = PriborGroup;
 }
コード例 #4
0
 public PriborContext(Pribor Pribor)
 {
     this.Pribor          = Pribor;
     PriborGroup          = new PriborGroup();
     PriborGroup.PriborId = Pribor.Id;
 }