private void cmbOk_Click(object sender, EventArgs e) { if (!edit) { try { if (String.IsNullOrEmpty(txtPrice.Text)) { MessageBox.Show("Пожалуйста, заполните все поля!", "Ошибка ввода данных", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { deliveryAdapter.Insert((int)(long)cmbProvider.SelectedValue, (int)(long)cmbAuto.SelectedValue, dateTimePicker1.Value, Decimal.Parse(txtPrice.Text)); object count = autoCount.GetAutoCount((int)(long)cmbAuto.SelectedValue); if (count == null) { autoCount.Insert((int)(long)cmbAuto.SelectedValue, 1); } else { int cnt = (int)count; autoCount.UpdateAutoCount(++cnt, (int)(long)cmbAuto.SelectedValue); } this.Close(); } } catch (Exception ex) { MessageBox.Show("Пожалуйста, проверьте корректность введенных данных! \n" + ex.Message, "Неверный формат данных", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { try { if (String.IsNullOrEmpty(txtPrice.Text)) { MessageBox.Show("Пожалуйста, заполните все поля!", "Ошибка ввода данных", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { deliveryAdapter.Update((int)(long)cmbProvider.SelectedValue, (int)(long)cmbAuto.SelectedValue, dateTimePicker1.Value, Decimal.Parse(txtPrice.Text), (int)deliveryID); this.Close(); } } catch (Exception /*ex*/) { MessageBox.Show("Пожалуйста, проверьте корректность введенных данных!", "Неверный формат данных", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void btnApply_Click(object sender, EventArgs e) { if (dateTimePicker1.Value == null) { MessageBox.Show("Пожалуйста, укажите дату продажи автомобиля", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (cmbPerson.SelectedValue == null) { MessageBox.Show("Пожалуйста, укажите клиента", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (cmbEmployee.SelectedValue == null) { MessageBox.Show("Пожалуйста, укажите сотрудника, осуществляющего продажу автомобиля", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (String.IsNullOrEmpty(tbPrice.Text)) { MessageBox.Show("Пожалуйста, укажите цену", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (cmbPay.SelectedValue == null) { MessageBox.Show("Пожалуйста, укажите способ оплаты", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { Decimal.Parse(tbPrice.Text); } catch (Exception /*ex*/) { MessageBox.Show("Пожалуйста, укажите корректную цену продажи", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { autoDataSet.CHECK_SALE_PRICEDataTable checkData = checkAdapter.GetData(autoID, decimal.Parse(tbPrice.Text)); autoDataSet.CHECK_SALE_PRICERow checkRow = checkData.Rows[0] as autoDataSet.CHECK_SALE_PRICERow; if (checkRow.OUT_RES != 0) { if (MessageBox.Show("Цена продажи автомобиля меньше закупочной! Продолжить?", "Подтверждение продажи", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } saleAdapter.InsertQuery(dateTimePicker1.Value, Int32.Parse(cmbPerson.SelectedValue.ToString()), Int32.Parse(cmbEmployee.SelectedValue.ToString()), autoID, Decimal.Parse(tbPrice.Text), Int32.Parse(cmbPay.SelectedValue.ToString()) ); auto.autoDataSet.EMPLOYEERow employeeRow = ((cmbEmployee.SelectedItem as DataRowView).Row as auto.autoDataSet.EMPLOYEERow); DateTime empBD = employeeRow.PERSONRow.PERSON_BIRTHDAY; string empPS = employeeRow.PERSONRow.PERSON_PASSPORT_SERIAL; string empPN = employeeRow.PERSONRow.PERSON_PASSPORT_NUMBER; DateTime empPD = employeeRow.PERSONRow.PERSON_P_DATE; string empPP = employeeRow.PERSONRow.PERSON_P_PLACE; auto.autoDataSet.PERSONRow client = ((cmbPerson.SelectedItem as DataRowView).Row as auto.autoDataSet.PERSONRow); DateTime cliBD = client.PERSON_BIRTHDAY; string cliPS = client.PERSON_PASSPORT_SERIAL; string cliPN = client.PERSON_PASSPORT_NUMBER; DateTime cliPD = client.PERSON_P_DATE; string cliPP = client.PERSON_P_PLACE; FastReport.TextObject repEmpBD = report1.FindObject("repTxtEBD") as FastReport.TextObject; repEmpBD.Text = empBD.ToShortDateString(); FastReport.TextObject repEmpPS = report1.FindObject("repTxtEPS") as FastReport.TextObject; repEmpPS.Text = empPS.ToString(); FastReport.TextObject repEmpPN = report1.FindObject("repTxtEPN") as FastReport.TextObject; repEmpPN.Text = empPN.ToString(); FastReport.TextObject repEmpPD = report1.FindObject("repTxtEPD") as FastReport.TextObject; repEmpPD.Text = empPD.ToShortDateString(); FastReport.TextObject repEmpPP = report1.FindObject("repTxtEPP") as FastReport.TextObject; repEmpPP.Text = empPP; FastReport.TextObject repCliBD = report1.FindObject("repTxtCBD") as FastReport.TextObject; repCliBD.Text = cliBD.ToShortDateString(); FastReport.TextObject repCliPS = report1.FindObject("repTxtCPS") as FastReport.TextObject; repCliPS.Text = cliPS.ToString(); FastReport.TextObject repCliPN = report1.FindObject("repTxtCPN") as FastReport.TextObject; repCliPN.Text = cliPN.ToString(); FastReport.TextObject repCliPD = report1.FindObject("repTxtCPD") as FastReport.TextObject; repCliPD.Text = cliPD.ToShortDateString(); FastReport.TextObject repCliPP = report1.FindObject("repTxtCPP") as FastReport.TextObject; repCliPP.Text = cliPP; autoDataSet.AUTODataTable table = aUTOTableAdapter.GetDataByAutoID(autoID); auto.autoDataSet.AUTORow aObj = table.Rows[0] as autoDataSet.AUTORow; autoDataSet.MODELDataTable mdlTable = modelAdapter.GetDataByModelID(Int32.Parse(aObj.MODEL_ID.ToString())); string modelFull = (mdlTable.Rows[0] as auto.autoDataSet.MODELRow).MODEL_FULL.ToString(); MessageBox.Show("Продажа успешно оформлена!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); String file = File.ReadAllText("reports\\BuySale2.rdl"); file = file.Replace("REP_DATE", dateTimePicker1.Value.ToShortDateString()); FastReport.TextObject text = report1.FindObject("repTxtDate") as FastReport.TextObject; text.Text = dateTimePicker1.Value.ToShortDateString(); auto.autoDataSet.PERSONRow obj = ((cmbPerson.SelectedItem as DataRowView).Row as auto.autoDataSet.PERSONRow); file = file.Replace("REP_PERSON", obj.PERSON_FULL.ToString()); auto.autoDataSet.EMPLOYEERow emp = ((cmbEmployee.SelectedItem as DataRowView).Row as auto.autoDataSet.EMPLOYEERow); FastReport.TextObject employee = report1.FindObject("repTxtEmployee") as FastReport.TextObject; if (emp.EMPLOYEE_FULL.ToString().IndexOf(',') > 0) { employee.Text = emp.EMPLOYEE_FULL.ToString().Substring(0, emp.EMPLOYEE_FULL.ToString().IndexOf(',')); } else { employee.Text = emp.EMPLOYEE_FULL.ToString(); } FastReport.TextObject person = report1.FindObject("repTxtPerson") as FastReport.TextObject; person.Text = obj.PERSON_FULL.ToString(); file = file.Replace("REP_MODEL", modelFull); FastReport.TextObject model = report1.FindObject("repTxtModel") as FastReport.TextObject; model.Text = modelFull; FastReport.TextObject modelPrice = report1.FindObject("repModelPrice") as FastReport.TextObject; modelPrice.Text = (mdlTable.Rows[0] as auto.autoDataSet.MODELRow).MODEL_PRICE.ToString() + " руб."; FastReport.TextObject engine = report1.FindObject("repTxtEngine") as FastReport.TextObject; engine.Text = (((System.Data.DataRowView)(cmbEngine.SelectedItem)).Row as autoDataSet.ENGINERow).ENGINE_FULL; FastReport.TextObject enginePrice = report1.FindObject("repEnginePrice") as FastReport.TextObject; enginePrice.Text = (((System.Data.DataRowView)(cmbEngine.SelectedItem)).Row as autoDataSet.ENGINERow).ENGINE_PRICE.ToString() + " руб."; FastReport.TextObject modification = report1.FindObject("repTxtModification") as FastReport.TextObject; modification.Text = (((System.Data.DataRowView)(cmbMod.SelectedItem)).Row as autoDataSet.MODIFICATIONRow).FULL; FastReport.TextObject modificationPrice = report1.FindObject("repModificationPrice") as FastReport.TextObject; modificationPrice.Text = (((System.Data.DataRowView)(cmbMod.SelectedItem)).Row as autoDataSet.MODIFICATIONRow).MODIFICATION_PRICE.ToString() + " руб."; auto.autoDataSet.AUTORow obj2 = aObj; file = file.Replace("REP_COLOR", obj2.AUTO_COLOR.ToString()); FastReport.TextObject color = report1.FindObject("repTxtColor") as FastReport.TextObject; color.Text = obj2.AUTO_COLOR.ToString(); file = file.Replace("REP_VIN", obj2.AUTO_VIN.ToString()); FastReport.TextObject vin = report1.FindObject("repTxtVin") as FastReport.TextObject; vin.Text = obj2.AUTO_VIN.ToString(); FastReport.TextObject vin2 = report1.FindObject("repTxtVin2") as FastReport.TextObject; vin2.Text = obj2.AUTO_VIN.ToString(); file = file.Replace("REP_PRICE", tbPrice.Text + " руб."); FastReport.TextObject sum = report1.FindObject("repTxtSum") as FastReport.TextObject; sum.Text = tbPrice.Text + " руб."; FastReport.TextObject sum2 = report1.FindObject("repTxtSum2") as FastReport.TextObject; sum2.Text = txtCatalogPrice.Text + " руб."; FastReport.TextObject priceMethod = report1.FindObject("repTxtPriceMethod") as FastReport.TextObject; auto.autoDataSet.PAYRow payRow = ((cmbPay.SelectedItem as DataRowView).Row as auto.autoDataSet.PAYRow); priceMethod.Text = payRow.PAY_NAME; File.WriteAllText("reports\\BuySale2_tmp.rdl", file); string filepath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "reports\\BuySale2_tmp.rdl"); //this.rdlViewer1.SourceFile = new Uri(filepath); //this.rdlViewer1.Rebuild(); this.clientAdapter.Insert((int)(long)cmbPerson.SelectedValue, autoID); object count = autoCount.GetAutoCount(autoID); int cnt = (int)count; autoCount.UpdateAutoCount(--cnt, autoID); SaleEventForm_Load(sender, e); report1.Show(); } catch (Exception ex) { MessageBox.Show("Ошибка оформления продажи. \n" + ex.Message, "Ошибка обработки", MessageBoxButtons.OK, MessageBoxIcon.Error); } }