private void OnOpenClick() { PressOperation selectedEntity = SelectedEntity; if (selectedEntity == null) { MessageBox.Show(@"Пожалуйста, выберите операцию."); return; } if (selectedEntity.PressOperationData == null) { Dal.LoadPressOperationData(selectedEntity);//загрузим данные длял опреции } ChartForm form = (ChartForm)UiHelper.GetFormSingle(typeof(ChartForm)); form.ChartFormShowMode = ChartFormShowMode.ShowSavedOperation; ChartFormViewModel viewModel = new ChartFormViewModel { PressOperation = selectedEntity }; form.buttonSaveOperation.Visible = true; viewModel.CanSaveOperation = true; form.ViewModel = viewModel; UiHelper.ShowForm(form, UiHelper.GetMdiContainer(this)); }
private static void FireOperationCreated(PressOperation operation) { if (OperationCreated != null) { OperationCreated(operation); } }
public void CreatePassportExcel(PressOperation left, PressOperation right) { application = new Microsoft.Office.Interop.Excel.Application { DisplayAlerts = false }; char[] separ = { ' ', '.', '-' }; //Открываем шаблон //Приложение самого Excel workBook = application.Workbooks.Open(PassportTemplatePath); worksheet = workBook.ActiveSheet as Worksheet; //Заполняем файл (шаблон) //Заполняем дату формирования КП worksheet.Range["B12"].Value = Convert.ToString(DateTime.Now.Month); worksheet.Range["D12"].Value = Convert.ToString(DateTime.Now.Year); worksheet.Range["A28"].Value = String.Format("Паспорт соствален {0} {1} {2}г.", Convert.ToString(DateTime.Now.Day), Convert.ToString(DateTime.Now.Month), Convert.ToString(DateTime.Now.Year)); //Заполняем тип колесной пары worksheet.Range["B5"].Value = left.WheelType; //Заполняем номер диаграммы worksheet.Range["B11"].Value = left.DiagramNumber; //заполняем данные по номеру колесной пары string[] parce_pair = new string[2]; parce_pair = left.AxisNumber.Split(separ); //Заполняем условный номер изготовления черновой оси worksheet.Range["B3"].Value = left.FactoryNumber; //Заполняем порядковый номер черновой оси worksheet.Range["C3"].Value = parce_pair.Length > 0 ? parce_pair[0] : string.Empty; //Заполняем год изготовления черновой оси worksheet.Range["E3"].Value = Convert.ToString(parce_pair.Length > 1 ? parce_pair[1] : string.Empty); string[] parce_left_wheel = left.WheelNumber.Split(separ); worksheet.Cells[17, 4].Value2 = parce_left_wheel.Length > 0 ? parce_left_wheel[0] : string.Empty; worksheet.Cells[19, 4].Value2 = parce_left_wheel.Length > 1 ? parce_left_wheel[1] : string.Empty; worksheet.Cells[18, 4].Value2 = parce_left_wheel.Length > 2 ? parce_left_wheel[2] : string.Empty; worksheet.Cells[15, 4].Value2 = parce_left_wheel.Length > 3 ? parce_left_wheel[3] : string.Empty; worksheet.Cells[16, 4].Value2 = parce_left_wheel.Length > 4 ? parce_left_wheel[4] : string.Empty; string[] parce_right_wheel = right.WheelNumber.Split(separ); worksheet.Cells[17, 2].Value2 = parce_right_wheel.Length > 0 ? parce_right_wheel[0] : string.Empty; worksheet.Cells[19, 2].Value2 = parce_right_wheel.Length > 1 ? parce_right_wheel[1] : string.Empty; worksheet.Cells[18, 2].Value2 = parce_right_wheel.Length > 2 ? parce_right_wheel[2] : string.Empty; worksheet.Cells[15, 2].Value2 = parce_right_wheel.Length > 3 ? parce_right_wheel[3] : string.Empty; worksheet.Cells[16, 2].Value2 = parce_right_wheel.Length > 4 ? parce_right_wheel[4] : string.Empty; //Пока сохраняем workBook.SaveAs(PassportsArhivePath + left.AxisNumber); //Печатаем файл worksheet.PrintOutEx(); CloseExcel(); }
private void OnSaveOperation() { PressOperation operation = ViewModel.PressOperation; if (operation.IsNew) { MessageBox.Show(@"Обновление данной операции невозможно"); return; } Dal.SaveOrUpdatePressOperation(operation); MessageBox.Show(@"Опенрация сохранена"); }
private void OnWriteExcel() { PressOperation operation = ViewModel.PressOperation; if (operation != null) { new ExcelReport().CreateExcel(operation); MessageBox.Show(@"Ok"); } else { MessageBox.Show(@"Пожалуйста, укажите операцию"); } }
private static PressOperation CreatePressOperation() { PressOperation operation = new PressOperation { PressOperationData = new BindingList <PressOperationData>(), OperationStart = DateTime.Now }; operation.Id = _dal.SaveOrUpdatePressOperation(operation); FireOperationCreated(operation); return(operation); }
public void UpdatePressOperationFieldTotal(string fieldName, PressOperation pressOperation, object val, DbType valType) { pressOperation.LengthSopriazh = GetMaxSopr(pressOperation.Id); pressOperation.MaxPower = GetMaxZapress(pressOperation.Id); pressOperation.LengthLines = GetDlinaPramUch(pressOperation.Id); string query = string.Format("UPDATE [dbo].[PressOperations] SET {0} = @val, LengthSopriazh = @LengthSopriazh, Power100mm = @Power100mm, MaxPower = @MaxPower, LengthLines = @LengthLines, FactoryNumber = @FactoryNumber, WheelNumber = @WheelNumber, DiagramNumber = @DiagramNumber, AxisNumber = @AxisNumber, WheelType = @WheelType, Side = @Side, DWheel = @DWheel, DAxis = @DAxis, LengthStup = @LengthStup WHERE ID = @id", fieldName); DbProviderFactory factory = SqlClientFactory.Instance; using (DbConnection conn = OpenConnection(factory, ConnectionString)) { using (DbCommand cmd = CreateTextCommand(conn, query)) { AddParameter(cmd, "@fieldName", fieldName, DbType.String); AddParameter(cmd, "@id", pressOperation.Id, DbType.Int32); AddParameter(cmd, "@val", val, valType); AddParameter(cmd, "@LengthSopriazh", pressOperation.LengthSopriazh, DbType.Int32); AddParameter(cmd, "@Power100mm", pressOperation.Power100Mm, DbType.Decimal); AddParameter(cmd, "@MaxPower", pressOperation.MaxPower, DbType.Decimal); AddParameter(cmd, "@LengthLines", pressOperation.LengthLines, DbType.Int32); AddParameter(cmd, "@FactoryNumber", pressOperation.FactoryNumber, DbType.String); AddParameter(cmd, "@WheelNumber", pressOperation.WheelNumber, DbType.String); AddParameter(cmd, "@DiagramNumber", pressOperation.DiagramNumber, DbType.String); AddParameter(cmd, "@AxisNumber", pressOperation.AxisNumber, DbType.String); AddParameter(cmd, "@Side", pressOperation.Side, DbType.String); AddParameter(cmd, "@WheelType", pressOperation.WheelType, DbType.String); AddParameter(cmd, "@DWheel", pressOperation.DWheel, DbType.Decimal); AddParameter(cmd, "@DAxis", pressOperation.DAxis, DbType.Decimal); AddParameter(cmd, "@LengthStup", pressOperation.LengthStup, DbType.Int32); System.Diagnostics.Trace.WriteLine("pressOperation.Id " + pressOperation.Id); //System.Diagnostics.Trace.WriteLine(" pressOperation.FactoryNumber " + pressOperation.FactoryNumber); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Logger.Log.Error("Не удалось обновить операцию", ex); throw; } } } }
private void CreatePassport() { PressOperation operation1 = ViewModel.PressOperation; PressOperation operation2 = Dal.GetOperationForPassport(operation1.AxisNumber, operation1.Side); if (operation1.Side == @"левая") { new ExcelReport().CreatePassportExcel(operation1, operation2); } else { new ExcelReport().CreatePassportExcel(operation2, operation1); } MessageBox.Show(@"Ok"); }
public void LoadPressOperationData(PressOperation pressOperation) { int operationId = pressOperation.Id; string query = "SELECT [ID], [DispPress], [DlinaSopr], [PressOperationId], [DateInsert] FROM [ZDPress].[dbo].[PressOperationData] WHERE [PressOperationId] = @pressOperationId"; List <PressOperationData> data = new List <PressOperationData>(); DbProviderFactory factory = SqlClientFactory.Instance; using (DbConnection conn = OpenConnection(factory, ConnectionString)) { using (DbCommand cmd = CreateTextCommand(conn, query)) { AddParameter(cmd, "@pressOperationId", operationId, DbType.Int32); try { DbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader["ID"]); decimal dispPress = Convert.ToDecimal(reader["DispPress"]); int dlinaSopr = Convert.ToInt32(reader["DlinaSopr"]); int pressOperationId = Convert.ToInt32(reader["PressOperationId"]); DateTime dateInsert = Convert.ToDateTime(reader["DateInsert"]); PressOperationData item = new PressOperationData { Id = id, PressOperationId = pressOperationId, DispPress = dispPress, DlinaSopr = dlinaSopr, DateInsert = dateInsert }; data.Add(item); } } catch (Exception ex) { Logger.Log.Error("Error PageOperation", ex); throw; } } } pressOperation.PressOperationData = new BindingList <PressOperationData>(data); }
public int SaveOrUpdatePressOperation(PressOperation pressOperation) { Logger.Log.Info("Создаём новую операцию в БД ConnectionString = " + ConnectionString); DbProviderFactory factory = SqlClientFactory.Instance; using (DbConnection conn = OpenConnection(factory, ConnectionString)) { using (DbCommand cmd = CreateTextCommand(conn, pressOperation.IsNew ? InsertPressOperationCommandAsText() : UpdatePressOperationCommandAsText())) { AddParameter(cmd, "@OperationStart", pressOperation.OperationStart, DbType.DateTime); AddParameter(cmd, "@OperationStop", pressOperation.OperationStop, DbType.DateTime); AddParameter(cmd, "@FactoryNumber", pressOperation.FactoryNumber, DbType.String); AddParameter(cmd, "@WheelNumber", pressOperation.WheelNumber, DbType.String); AddParameter(cmd, "@DiagramNumber", pressOperation.DiagramNumber, DbType.String); AddParameter(cmd, "@AxisNumber", pressOperation.AxisNumber, DbType.String); AddParameter(cmd, "@WheelType", pressOperation.WheelType, DbType.String); AddParameter(cmd, "@Side", pressOperation.Side, DbType.String); AddParameter(cmd, "@DWheel", pressOperation.DWheel, DbType.Decimal); AddParameter(cmd, "@DAxis", pressOperation.DAxis, DbType.Decimal); AddParameter(cmd, "@LengthStup", pressOperation.LengthStup, DbType.Int32); AddParameter(cmd, "@Natiag", pressOperation.Natiag, DbType.Decimal); AddParameter(cmd, "@LengthSopriazh", pressOperation.LengthSopriazh, DbType.Decimal); AddParameter(cmd, "@Power100mm", pressOperation.Power100Mm, DbType.Decimal); AddParameter(cmd, "@MaxPower", pressOperation.MaxPower, DbType.Decimal); AddParameter(cmd, "@LengthLines", pressOperation.LengthLines, DbType.Int32); if (!pressOperation.IsNew) { AddParameter(cmd, "@Id", pressOperation.Id, DbType.Int32); } object res = cmd.ExecuteScalar(); int id = (int?)res ?? pressOperation.Id; cmd.Parameters.Clear(); return(id); } } }
public PressOperation GetOperationForPassport(string axisNum, string sideParam) { const string query = "SELECT TOP 1 " + " [ID] " + ",[OperationStart] " + ",[OperationStop] " + ",[WheelNumber] " + ",[FactoryNumber] " + ",[DiagramNumber] " + ",[AxisNumber] " + ",[WheelType] " + ",[Side] " + ",[DWheel] " + ",[DAxis] " + ",[LengthStup] " + ",[Natiag] " + ",[LengthSopriazh] " + ",[Power100mm] " + ",[MaxPower] " + ",[LengthLines] " + " FROM [dbo].[PressOperations] " + " WHERE UPPER([AxisNumber]) = UPPER(@axisNumber) AND UPPER([Side]) <> UPPER(@side) " + " ORDER BY [OperationStart] DESC "; DbProviderFactory factory = SqlClientFactory.Instance; using (DbConnection conn = OpenConnection(factory, ConnectionString)) { using (DbCommand cmd = CreateTextCommand(conn, query)) { AddParameter(cmd, "@axisNumber", axisNum, DbType.String); AddParameter(cmd, "@side", sideParam, DbType.String); try { PressOperation operation = new PressOperation(); DbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader["ID"]); DateTime operationStart = Convert.ToDateTime(reader["OperationStart"]); DateTime?operationStop = !string.IsNullOrEmpty(reader["OperationStop"].ToString()) ? (DateTime?)Convert.ToDateTime(reader["OperationStop"]) : null; string factoryNumber = !string.IsNullOrEmpty(reader["FactoryNumber"].ToString()) ? Convert.ToString(reader["FactoryNumber"]) : null; string wheelNumber = !string.IsNullOrEmpty(reader["WheelNumber"].ToString()) ? Convert.ToString(reader["WheelNumber"]) : null; string diagramNumber = !string.IsNullOrEmpty(reader["DiagramNumber"].ToString()) ? Convert.ToString(reader["DiagramNumber"]) : null; string axisNumber = !string.IsNullOrEmpty(reader["AxisNumber"].ToString()) ? Convert.ToString(reader["AxisNumber"]) : null; string wheelType = !string.IsNullOrEmpty(reader["WheelType"].ToString()) ? Convert.ToString(reader["WheelType"]) : null; string side = !string.IsNullOrEmpty(reader["Side"].ToString()) ? Convert.ToString(reader["Side"]) : null; decimal dWheel = !string.IsNullOrEmpty(reader["DWheel"].ToString()) ? Convert.ToDecimal(reader["DWheel"]) : 0; decimal dAxis = !string.IsNullOrEmpty(reader["DAxis"].ToString()) ? Convert.ToDecimal(reader["DAxis"]) : 0; int lengthStup = !string.IsNullOrEmpty(reader["LengthStup"].ToString()) ? Convert.ToInt32(reader["LengthStup"]) : 0; decimal natiag = !string.IsNullOrEmpty(reader["Natiag"].ToString()) ? Convert.ToDecimal(reader["Natiag"]) : 0; int lengthSopriazh = !string.IsNullOrEmpty(reader["LengthSopriazh"].ToString()) ? Convert.ToInt32(reader["LengthSopriazh"]) : 0; decimal power100Mm = !string.IsNullOrEmpty(reader["Power100mm"].ToString()) ? Convert.ToDecimal(reader["Power100mm"]) : 0; decimal maxPower = !string.IsNullOrEmpty(reader["MaxPower"].ToString()) ? Convert.ToDecimal(reader["MaxPower"]) : 0; int lengthLines = !string.IsNullOrEmpty(reader["LengthLines"].ToString()) ? Convert.ToInt32(reader["LengthLines"]) : 0; operation.Id = id; operation.OperationStart = operationStart; operation.OperationStop = operationStop; operation.FactoryNumber = factoryNumber; operation.WheelNumber = wheelNumber; operation.DiagramNumber = diagramNumber; operation.AxisNumber = axisNumber; operation.WheelType = wheelType; operation.LengthSopriazh = lengthSopriazh; operation.Side = side; operation.DWheel = dWheel; operation.DAxis = dAxis; operation.LengthStup = lengthStup; operation.MaxPower = maxPower; operation.LengthLines = lengthLines; } return(operation); } catch (Exception ex) { Logger.Log.Error("Error GetOperationForPassport", ex); throw; } } } }
public List <PressOperation> PageOperation(int pageSize, int pageNumber) { string query = " SELECT " + " [ID] " + ",[OperationStart] " + ",[OperationStop] " + ",[WheelNumber] " + ",[FactoryNumber] " + ",[DiagramNumber] " + ",[AxisNumber] " + ",[WheelType] " + ",[Side] " + ",[DWheel] " + ",[DAxis] " + ",[LengthStup] " + ",[Natiag] " + ",[LengthSopriazh] " + ",[Power100mm] " + ",[MaxPower] " + ",[LengthLines] " + ", [TotalRows] " + "FROM " + "(SELECT ROW_NUMBER() OVER (ORDER BY [ID] DESC) AS RowNum, " + " [ID] " + ",[OperationStart] " + ",[OperationStop] " + ",[WheelNumber] " + ",[FactoryNumber] " + ",[DiagramNumber] " + ",[AxisNumber] " + ",[WheelType] " + ",[Side] " + ",[DWheel] " + ",[DAxis] " + ",[LengthStup] " + ",[Natiag] " + ",[LengthSopriazh] " + ",[Power100mm] " + ",[MaxPower] " + ",[LengthLines] " + " ,COUNT(*) OVER() AS TotalRows " + " from [dbo].[PressOperations] " + ") AS PressOperations " + "WHERE RowNum BETWEEN (((@pageNumber - 1) * @pageSize )+ 1) AND (@pageNumber * @pageSize) "; List <PressOperation> operations = new List <PressOperation>(); DbProviderFactory factory = SqlClientFactory.Instance; using (DbConnection conn = OpenConnection(factory, ConnectionString)) { using (DbCommand cmd = CreateTextCommand(conn, query)) { AddParameter(cmd, "@pageSize", pageSize, DbType.Int32); AddParameter(cmd, "@pageNumber", pageNumber, DbType.Int32); try { DbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader["ID"]); DateTime operationStart = Convert.ToDateTime(reader["OperationStart"]); DateTime?operationStop = !string.IsNullOrEmpty(reader["OperationStop"].ToString()) ? (DateTime?)Convert.ToDateTime(reader["OperationStop"]) : null; string factoryNumber = !string.IsNullOrEmpty(reader["FactoryNumber"].ToString()) ? Convert.ToString(reader["FactoryNumber"]) : null; string wheelNumber = !string.IsNullOrEmpty(reader["WheelNumber"].ToString()) ? Convert.ToString(reader["WheelNumber"]) : null; string diagramNumber = !string.IsNullOrEmpty(reader["DiagramNumber"].ToString()) ? Convert.ToString(reader["DiagramNumber"]) : null; string axisNumber = !string.IsNullOrEmpty(reader["AxisNumber"].ToString()) ? Convert.ToString(reader["AxisNumber"]) : null; string wheelType = !string.IsNullOrEmpty(reader["WheelType"].ToString()) ? Convert.ToString(reader["WheelType"]) : null; string side = !string.IsNullOrEmpty(reader["Side"].ToString()) ? Convert.ToString(reader["Side"]) : null; decimal dWheel = !string.IsNullOrEmpty(reader["DWheel"].ToString()) ? Convert.ToDecimal(reader["DWheel"]) : 0; decimal dAxis = !string.IsNullOrEmpty(reader["DAxis"].ToString()) ? Convert.ToDecimal(reader["DAxis"]) : 0; int lengthStup = !string.IsNullOrEmpty(reader["LengthStup"].ToString()) ? Convert.ToInt32(reader["LengthStup"]) : 0; decimal natiag = !string.IsNullOrEmpty(reader["Natiag"].ToString()) ? Convert.ToDecimal(reader["Natiag"]) : 0; int lengthSopriazh = !string.IsNullOrEmpty(reader["LengthSopriazh"].ToString()) ? Convert.ToInt32(reader["LengthSopriazh"]) : 0; decimal power100Mm = !string.IsNullOrEmpty(reader["Power100mm"].ToString()) ? Convert.ToDecimal(reader["Power100mm"]) : 0; decimal maxPower = !string.IsNullOrEmpty(reader["MaxPower"].ToString()) ? Convert.ToDecimal(reader["MaxPower"]) : 0; int lengthLines = GetDlinaPramUch(id);//!string.IsNullOrEmpty(reader["LengthLines"].ToString()) ? Convert.ToInt32(reader["LengthLines"]) : 0; int totalRows = !string.IsNullOrEmpty(reader["TotalRows"].ToString()) ? Convert.ToInt32(reader["TotalRows"]) : 0; PressOperation operation = new PressOperation(); operation.Id = id; operation.OperationStart = operationStart; operation.OperationStop = operationStop; operation.FactoryNumber = factoryNumber; operation.WheelNumber = wheelNumber; operation.DiagramNumber = diagramNumber; operation.AxisNumber = axisNumber; operation.WheelType = wheelType; operation.Side = side; operation.DWheel = dWheel; operation.DAxis = dAxis; operation.LengthStup = lengthStup; operation.LengthSopriazh = lengthSopriazh; operation.MaxPower = maxPower; operation.LengthLines = lengthLines; operation.TotalRows = totalRows; operations.Add(operation); } } catch (Exception ex) { Logger.Log.Error("Error PageOperation", ex); throw; } } } return(operations); }
private static void SavePressOperationData(PressOperationData data) { bool needCreatePressOperation = data.ShowGraph && CurrentPressOperation.Id == 0; if (needCreatePressOperation) { CurrentPressOperation = CreatePressOperation(); } //bool badStart = needCreatePressOperation && data.DlinaSopr != 0; bool changeSopr = _lastDlinaSopr != data.DlinaSopr && data.DlinaSopr < 300; System.Diagnostics.Trace.WriteLine(string.Format("_lastDlinaSopr")); _lastDlinaSopr = data.DlinaSopr; bool needCreatePressOperationData = data.ShowGraph && changeSopr; if (needCreatePressOperationData) { if (CurrentPressOperation.Id == 0) { throw new Exception("Press operaion was not created!"); } data.PressOperationId = CurrentPressOperation.Id; data.DispPress = data.DispPress / 100;//потому что надо _dal.InsertPressOperationData(data); if (CurrentPressOperation.PressOperationData == null) { CurrentPressOperation.PressOperationData = new BindingList <PressOperationData>(); } //CurrentPressOperation.PressOperationData.Add(data); // FireOperationDataCreated(data); } bool pressOperationWasFinished = !data.ShowGraph && CurrentPressOperation.Id != 0; if (pressOperationWasFinished) { // TODO: проверить что обновилось на форме ChartForm form = (ChartForm)UiHelper.GetFormSingle(typeof(ChartForm)); var operation = form.ViewModel.PressOperation; ReportDto reportDto = form.GetReportDto(); /*operation.AxisNumber = reportDto.NomerOsi; * operation.FactoryNumber = reportDto.NomerZavoda; * System.Diagnostics.Trace.WriteLine(" reportDto.NomerZavoda" + reportDto.NomerZavoda); * operation.WheelType = reportDto.TipKolesPar; * operation.Side = reportDto.Storona; * operation.WheelNumber = reportDto.NomerKolesa; * if (!string.IsNullOrWhiteSpace(reportDto.DiametrPodsChasti)) * { * operation.DWheel = Decimal.Parse(reportDto.DiametrPodsChasti); * } * if (!string.IsNullOrWhiteSpace(reportDto.DiametrOtvStupici)) * { * operation.DAxis = Decimal.Parse(reportDto.DiametrOtvStupici); * } * * if (!string.IsNullOrWhiteSpace(reportDto.DlinaStupici)) * { * operation.LengthStup = int.Parse(reportDto.DlinaStupici); * } * * //operation.Natiag = reportDto.Natag; * if (!string.IsNullOrWhiteSpace(reportDto.DlinaSoprag)) * { * operation.LengthSopriazh = int.Parse(reportDto.DlinaSoprag); * } * if (!string.IsNullOrWhiteSpace(reportDto.UsilZapres100)) * { * //operation.Power100Mm = Decimal.Parse(reportDto.UsilZapres100); * } * if (!string.IsNullOrWhiteSpace(reportDto.MaxUsilZapres)) * { * //operation.MaxPower = int.Parse(reportDto.MaxUsilZapres); * } * if (!string.IsNullOrWhiteSpace(reportDto.DlinaPramUch)) * { * //operation.LengthLines = int.Parse(reportDto.DlinaPramUch); * } */ //textBoxPods.DataBindings.Add(new Binding("Text", ViewModel, "PressOperation.DWheel", true, DataSourceUpdateMode.OnPropertyChanged)); //textBoxOtv.DataBindings.Add(new Binding("Text", ViewModel, "PressOperation.DAxis", true, DataSourceUpdateMode.OnPropertyChanged)); //textBoxDlin.DataBindings.Add(new Binding("Text", ViewModel, "PressOperation.LengthStup", true, DataSourceUpdateMode.OnPropertyChanged)); operation.Id = CurrentPressOperation.Id; _dal.UpdatePressOperationFieldTotal("OperationStop", operation, DateTime.Now, DbType.DateTime); _lastDlinaSopr = 0; using (AutoPrint demo = new AutoPrint(reportDto)) { demo.Run(); } CurrentPressOperation.Id = 0; } }
public void CreateExcel(PressOperation operation) { //Открываем шаблон //Приложение самого Excel application = new Microsoft.Office.Interop.Excel.Application { DisplayAlerts = false // Visible = false }; workBook = application.Workbooks.Open(Filename: RegisterTemplatePath); worksheet = workBook.ActiveSheet as Worksheet; //Cчитаем мколичество заполненных строк на листе int iRows = worksheet.Cells[3, 1].CurrentRegion.Rows.Count + 1; //Ищем строку с таким-же номером оси char[] separ = { ' ', '.', '-' }; int flag = 0; for (int i = 4; i <= iRows; i++) { if (Convert.ToString(worksheet.Cells[i, 2].Value) == Convert.ToString(operation.DiagramNumber)) { flag = i; break; } } //Если такой строки еще нет if (flag == 0) { //Заполняем все общие строки //Заполняем дату worksheet.Cells[iRows + 1, 1].Value = DateTime.Now.ToShortDateString(); //Заполняем номер диаграммы worksheet.Cells[iRows + 1, 2].Value = operation.DiagramNumber; //номор диаграммы //Заполняем номер оси (колесной пары) worksheet.Cells[iRows + 1, 4].Value = operation.FactoryNumber + operation.AxisNumber; //1 номор завода 2 номер колесной пары //Заполняем тип колесной пары worksheet.Cells[iRows + 1, 5].Value = operation.WheelType; // тип колесной пары //Заполняем следующий столбец константой worksheet.Cells[iRows + 1, 6].Value = 20; //Определяем какую сторону необходимо заполнять int col = 0; if (string.Compare(operation.Side, "левая", true) == 0) { col = 14; } else if (string.Compare(operation.Side, "правая", true) == 0) { col = 7; } else { col = 7;//default falue } //Заполняем номер ЦКК (номер колеса) worksheet.Cells[iRows + 1, col].Value = operation.WheelNumber; //Заполняем диаметр подступичной части worksheet.Cells[iRows + 1, col + 1].Value = operation.DWheel; //Заполняем внутренний диаметр ступицы worksheet.Cells[iRows + 1, col + 2].Value = operation.DAxis; //Заполняем длину ступицы worksheet.Cells[iRows + 1, col + 3].Value = operation.LengthStup; //Заполняем принятый натяг worksheet.Cells[iRows + 1, col + 4].Value = operation.Natiag; //Заполняем конечное давление worksheet.Cells[iRows + 1, col + 5].Value = operation.MaxPower; } //Если строка уже есть else { //Определяем какую сторону необходимо заполнять int col = 7; if (string.Compare(operation.Side, "левая", true) == 0) { col = 14; } //else if (string.Compare(operation.Side, "правая", true) == 0) //{ // col = 7; //} //Заполняем номер ЦКК worksheet.Cells[flag, col].Value = operation.WheelNumber; //Заполняем диаметр подступичной части worksheet.Cells[flag, col + 1].Value = operation.DWheel; //Заполняем внутренний диаметр ступицы worksheet.Cells[flag, col + 2].Value = operation.DAxis; //Заполняем длину ступицы worksheet.Cells[flag, col + 3].Value = operation.LengthStup; //Заполняем принятый натяг worksheet.Cells[flag, col + 4].Value = operation.Natiag; //Заполняем конечное давление worksheet.Cells[flag, col + 5].Value = operation.MaxPower; //Тут же проверяем заполненность всех строк на листе //на шапку добавляем 4 строки //Если заполнены все необходимые строки if (iRows == max_rows_in_sheet + 4) { //Проверяем заполненность столбцов bool flag_data = true; for (int j = 5; j <= iRows; j++) { if (worksheet.Cells[j, 7].Value == null || worksheet.Cells[j, 13].Value == null) { flag_data = false; } } //Если заполнены и правая и левая стороны для всех строк if (flag_data == true) { //Печатаем файл worksheet.PrintOutEx(); //!!!!!!!!!!!!!!!!!!!!!!!!!ТУТ ФОРМИРУЕТСЯ ИМЯ СОХРАНЯЕМОГО ФАЙЛА И ПУТЬ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //Сохраняем файл в архив //формат названия файла: год - от 01 до 99, месяц - от 01 до 12, день - от 01 до 31, часы - от 00 до 23 и т.д. workBook.SaveCopyAs(@"D:\registerArchive\" + DateTime.Now.ToString("yy_M_dd_HH_mm_ss") + ".xlsx"); //Очищаем файл от данных for (int k = max_rows_in_sheet + 4; k > 4; k--) { worksheet.Cells[k, 1].EntireRow.Delete(); } worksheet.PageSetup.PrintArea = "$A$1:$T$" + (max_rows_in_sheet + 4); } } } workBook.Save(); //Закрываем Excel CloseExcel(); //Перемещаем обработанный файл csv //string[] name = t[0].Split('\\'); // File.Delete(arch_path + name[name.GetUpperBound(0)]); // File.Move(t[0], arch_path + name[name.GetUpperBound(0)]); //Удаляем прочитанный файл из каталога //File.Delete(t[0]); }