Ejemplo n.º 1
0
        private void btnUpdatePribor(object sender, RoutedEventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "XLSX files (*.xlsx, *.xlsm, *.xltx, *.xltm)|*.xlsx;*.xlsm;*.xltx;*.xltm|XLS files (*.xls, *.xlt)|*.xls;*.xlt";
            open.Title  = "Obyektni ochish";
            if (open.ShowDialog() == true)
            {
                try
                {
                    Excel.Application exApp    = new Excel.Application();
                    Excel.Workbook    workbook = exApp.Workbooks.Open(open.FileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);
                    // 1-Listni olish
                    Excel.Worksheet ws = workbook.Worksheets.get_Item(1) as Excel.Worksheet;
                    int             i  = 0;

                    string[] ss = new string[5];

                    int row = ws.UsedRange.Rows.Count;
                    for (i = 2; i <= row; i++)
                    {
                        ss[0] = GetString(ws.Cells[i, 1]);
                        ss[1] = GetString(ws.Cells[i, 2]);
                        ss[2] = GetString(ws.Cells[i, 3]);
                        ss[3] = GetString(ws.Cells[i, 4]);
                        ss[4] = GetString(ws.Cells[i, 5]);

                        Pribor pribor = new Pribor()
                        {
                            Code      = Helper.ClearZeros(ss[0]),
                            Name      = ss[1],
                            Price     = double.Parse(ss[2]),
                            Dimension = ss[3],
                            Percent   = double.Parse(ss[4])
                        };

                        using (var db = new SmetaDbAppContext())
                        {
                            Pribor find = db.Pribors.Where(x => int.Parse(x.Code) == int.Parse(pribor.Code)).FirstOrDefault();
                            if (find != null)
                            {
                                find.Name      = pribor.Name;
                                find.Price     = pribor.Price;
                                find.Dimension = pribor.Dimension;
                                find.Percent   = pribor.Percent;

                                find.Update();
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message + "\n Ошибка");
                }
            }
        }
Ejemplo n.º 2
0
 public static double?ToAmortizationinHour(Pribor pribor)
 {
     if (pribor != null)
     {
         return((pribor.Percent * pribor.Price) / 100 / 12 / ToHourKoef);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
        private void OnClickNew(object sender, RoutedEventArgs e)
        {
            Pribor pribor = new Pribor();

            Windows.Adds.WindowAddPribor window = new Adds.WindowAddPribor(pribor);
            if (window.ShowDialog() == true)
            {
                list.Add(pribor);
                pribor.Save();
            }
        }
Ejemplo n.º 4
0
        private void OnEditing(object sender, RoutedEventArgs e)
        {
            if (data.SelectedItem == null)
            {
                return;
            }
            Pribor pribor = list[data.SelectedIndex];

            Windows.Adds.WindowAddPribor window = new Adds.WindowAddPribor(pribor);
            if (window.ShowDialog() == true)
            {
                pribor.Update();
            }
        }
Ejemplo n.º 5
0
 private void DoWok(object sender, DoWorkEventArgs e)
 {
     try
     {
         using (var db = new SmetaDbAppContext())
         {
             List <Pribor>   pribors   = db.Pribors;
             List <Material> materials = db.Materials;
             int             i         = 0;
             db.Works.ForEach(work =>
             {
                 // Pribors
                 double s = 0;
                 db.PriborGroups.Where(y => y.WorkId == work.Id).ToList().ForEach(group =>
                 {
                     Pribor pribor = pribors.Find(x => x.Id == group.PriborId);
                     s            += ((pribor.Price * pribor.Percent / 100) * group.Count) / 12;
                 });
                 work.PricePribor = s;
                 s = 0;
                 db.MaterialGroups.Where(y => y.WorkId == work.Id).ToList().ForEach(group =>
                 {
                     Material material = materials.Find(x => x.Id == group.MaterialId);
                     s += material.Price;
                 });
                 work.PriceMaterial = s;
                 work.Update();
                 i++;
                 worker.ReportProgress(i);
             });
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show(exc.ToString());
     }
 }
        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());
            }
        }
Ejemplo n.º 7
0
 public PriborContext(Pribor Pribor)
 {
     this.Pribor          = Pribor;
     PriborGroup          = new PriborGroup();
     PriborGroup.PriborId = Pribor.Id;
 }
Ejemplo n.º 8
0
 public WindowAddPribor(Pribor pribor)
 {
     InitializeComponent();
     DataContext = pribor;
 }
Ejemplo n.º 9
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Pribor obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }