Exemplo n.º 1
0
        public void StartServer(User user)
        {
            try
            {
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    var server          = new NamedPipeServerStream("Tekla21.1");
                    StreamReader reader = new StreamReader(server);
                    while (true)
                    {
                        server.WaitForConnection();

                        logger.Info("Клиент подключился");

                        Loading Load = new Loading();
                        Load.Show();

                        Tekla tekla = new Tekla(Load);
                        if (tekla.CheckConnect())
                        {
                            logger.Info("Модель подключена");

                            tekla.GetData(user);
                        }
                        else
                        {
                            logger.Info("Модель не подключена");

                            MessageBox.Show("Ошибка подключения модели", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        server.Disconnect();
                    }
                });
            }
            catch (Exception E)
            {
                maillogger.SendErrorLog(E.ToString());
                logger.Error(E.ToString());
                StartServer(user);
            }
        }
        public void GetData(Shared.Models.User user)
        {
            try
            {
                DrawingEnumerator SelectedDrawings = CourretDrawingHandler.GetDrawingSelector().GetSelected();

                logger.Info("Чертежи успешно получены");

                Drawings = new List <Shared.Models.Drawing>();

                DrawingErrors   = new List <StringErrorBindingModel>();
                DetailsErrors   = new List <StringErrorBindingModel>();
                DetailsWarnings = new List <StringErrorBindingModel>();

                while (SelectedDrawings.MoveNext())
                {
                    try
                    {
                        if (SelectedDrawings.Current is AssemblyDrawing)
                        {
                            Assembly assembly = model.SelectModelObject(((SelectedDrawings.Current as AssemblyDrawing)).AssemblyIdentifier) as Assembly;

                            if (!ChechedDate(assembly))
                            {
                                throw new Exception("Не заполнено поле \"Дата\"");
                            }

                            GetDrawing(assembly, SelectedDrawings.Current as AssemblyDrawing);
                        }
                    }
                    catch (Exception E)
                    {
                        String   Number   = "";
                        String   List     = "";
                        Assembly assembly = model.SelectModelObject(((SelectedDrawings.Current as AssemblyDrawing)).AssemblyIdentifier) as Assembly;
                        assembly.GetReportProperty("CUSTOM.Zakaz", ref Number);
                        assembly.GetReportProperty("CUSTOM.Drw_SheetRev", ref List);
                        logger.Error(E.ToString());
                        DrawingErrors.Add(new StringErrorBindingModel {
                            Order = Number, List = List, Error = E.Message
                        });
                    }
                }

                logger.Info("Чертежи добавлены");

                ModelInfo modelInfo = model.GetInfo();
                string    ModelPath = modelInfo.ModelPath;

                if (ModelPath.Substring(0, 2) != @"\\")
                {
                    using (var managementObject = new ManagementObject())
                    {
                        managementObject.Path = new ManagementPath($"Win32_LogicalDisk='{ModelPath.Substring(0, 2)}'");
                        var driveType   = (DriveType)(uint)managementObject["DriveType"];
                        var networkPath = Convert.ToString(managementObject["ProviderName"]);

                        ModelPath = networkPath + ModelPath.Remove(0, 2);
                    }
                }

                ModelPath = ModelPath.Replace("tekla-fs", "10.0.7.249");

                Model = new Shared.Models.Model {
                    DateCreate = DateTime.Now, Path = ModelPath, Drawings = Drawings
                };


                notify.Close();

                if (DetailsWarnings.Count > 0)
                {
                    ReportWarnings Report = new ReportWarnings();
                    Report.Report_DGV.AutoGenerateColumns = false;
                    Report.Report_DGV.DataSource          = DetailsWarnings;

                    if (Report.ShowDialog() != DialogResult.OK)
                    {
                        for (int i = 0; i < DetailsWarnings.Count; i++)
                        {
                            Drawings.RemoveAll(p => p.Order == DetailsWarnings[i].Order && p.List == DetailsWarnings[i].List);
                        }
                    }
                }

                if (DetailsErrors.Count > 0)
                {
                    ReportErrors Report = new ReportErrors();
                    Report.Text        = "Отчет об ошибках деталей";
                    Report.label1.Text = "Отчет об ошибках деталей";
                    Report.Report_DGV.AutoGenerateColumns = false;
                    Report.Report_DGV.DataSource          = DetailsErrors;

                    Report.ShowDialog();
                }

                if (DrawingErrors.Count > 0)
                {
                    ReportErrors Report = new ReportErrors();
                    Report.Text        = "Отчет об ошибках чертежей";
                    Report.label1.Text = "Отчет об ошибках чертежей";
                    Report.Report_DGV.AutoGenerateColumns = false;
                    Report.Report_DGV.DataSource          = DrawingErrors;

                    Report.ShowDialog();
                }

                if (Model.Drawings.Count() > 0)
                {
                    logger.Info("Начат показ чертежей");

                    Operations operations = new Operations();
                    operations.ShowData(Model, user);
                }
            }
            catch (Exception E)
            {
                maillogger.SendErrorLog(E.ToString());
                logger.Error(E.ToString());
                MessageBox.Show("Ошибка операции", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        public void GetData(Shared.Models.User user)
        {
            try
            {
                DrawingEnumerator SelectedDrawings = CourretDrawingHandler.GetDrawingSelector().GetSelected();

                logger.Info("Чертежи успешно получены");

                Drawings = new List <Shared.Models.Drawing>();

                Errors = new List <StringErrorBindingModel>();

                while (SelectedDrawings.MoveNext())
                {
                    try
                    {
                        if (SelectedDrawings.Current is AssemblyDrawing)
                        {
                            String Number = "";

                            Assembly assembly = model.SelectModelObject(((SelectedDrawings.Current as AssemblyDrawing)).AssemblyIdentifier) as Assembly;

                            if (!ChechedDate(assembly))
                            {
                                assembly.GetReportProperty("CUSTOM.Zakaz", ref Number);
                                Errors.Add(new StringErrorBindingModel {
                                    Data = $"Заказ: {Number}, Марка: {SelectedDrawings.Current.Mark}", Error = "Не заполнено поле \"Дата\""
                                });
                                continue;
                            }

                            GetDrawing(assembly, SelectedDrawings.Current as AssemblyDrawing);
                        }
                    }
                    catch (Exception E)
                    {
                        String   Number   = "";
                        String   List     = "";
                        Assembly assembly = model.SelectModelObject(((SelectedDrawings.Current as AssemblyDrawing)).AssemblyIdentifier) as Assembly;
                        assembly.GetReportProperty("CUSTOM.Zakaz", ref Number);
                        assembly.GetReportProperty("CUSTOM.Drw_SheetRev", ref List);
                        logger.Error(E.ToString());
                        Errors.Add(new StringErrorBindingModel {
                            Data = $"Заказ: {Number}, Лист: {List}", Error = E.Message
                        });
                    }
                }

                logger.Info("Чертежи добавлены");

                ModelInfo modelInfo = model.GetInfo();
                Model = new Shared.Models.Model {
                    DateCreate = DateTime.Now, Path = modelInfo.ModelPath, Drawings = Drawings
                };

                notify.Close();

                if (Errors.Count > 0)
                {
                    ReportErrors Report = new ReportErrors();
                    Report.Report_DGV.AutoGenerateColumns = false;
                    Report.Report_DGV.DataSource          = Errors;

                    Report.ShowDialog();
                }

                if (Model.Drawings.Count() > 0)
                {
                    logger.Info("Начат показ чертежей");

                    Operations operations = new Operations();
                    operations.ShowData(Model, user);
                }
            }
            catch (Exception E)
            {
                maillogger.SendErrorLog(E.ToString());
                logger.Error(E.ToString());
                MessageBox.Show("Ошибка операции", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }