/// <summary> /// Создать контрагента /// </summary> /// <returns>возвращает TRUE, если контрагент успешно создан</returns> public bool CreateCounterparty() { bool result = false; try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"INSERT INTO `COUNTERPARTY` (`SURNAME`, `NAME`, `PATRONYMIC`, `ADRESS`, `PHONE`, `NOMINATION`, `IS_PROVIDER`, `IS_ANNULATED`, `CODE`) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}')", Surname, Name, Patronymic, Conversion.ToCriptString(Adress), Conversion.ToCriptString(Phone), Nomination, Conversion.ToString(IsProvider), 0, Code); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); ID = (int)command.LastInsertedId; } string name = (Nomination != "") ? Nomination : Surname + " " + Name; Journal.CreateJournal("создал", "контрагента " + name, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка создания контрагента", ex.Message); } return(result); }
/// <summary> /// Создать товар /// </summary> /// <returns>возвращает TRUE если товар создан успешно</returns> public bool CreateProduct() { bool result = false; try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"INSERT INTO `PRODUCT` (`PRODUCT_CODE`, `NOMINATION`, `COUNT_IN_PACKAGE`, `COST`, `COUPON`, `ID_UNIT`, `COST_PURCHASE`, `COUPON_PURCHASE`) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')", _productCode, _nomination, _countInPackage, Conversion.ToString(_cost), Conversion.ToString(_coupon), _id_unit, Conversion.ToString(_costPurchase), Conversion.ToString(_couponPurchase)); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); ID = (int)command.LastInsertedId; } Journal.CreateJournal("создал", "товар " + ProductCode, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка создания товара", ex.Message); } return(result); }
/// <summary> /// Создание единицы измерения /// </summary> /// <returns>возвращает TRUE, если единица измерения создана успешно</returns> public bool CreateUnit() { bool result = false; try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"INSERT INTO `UNIT` (`NOMINATION`) VALUES ('{0}')", Nomination); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); ID = (int)command.LastInsertedId; } Journal.CreateJournal("создал", "единицу измерения " + Nomination, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка создания единицы измерения", ex.Message); } return(result); }
/// <summary> /// Создать новый аккаунт /// </summary> /// <returns>возвращает TRUE, если аккаунт успешно создан</returns> public bool CreateAccount() { bool result = false; try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string newPass = Criptex.Cript("12345"); string sql = String.Format(@"INSERT INTO `ACCOUNT` (`LOGIN`, `PASSWORD`, `SURNAME`, `NAME`, `PATRONYMIC`, `ADRESS`, `PHONE`, `SEX`, `PURCHASE_INVOICE`, `SALES_INVOICE`, `REPORTS`, `REPORT_PURCHASE_INVOICE`, `REPORT_SALES_INVOICE`, `REPORT_INCOME_EXPENSE`, `COUNTERPARTY`, `COUNTERPARTY_PROVIDER`, `COUNTERPARTY_PROVIDER_ADD`, `COUNTERPARTY_PROVIDER_EDIT`, `COUNTERPARTY_PROVIDER_DELETE`, `COUNTERPARTY_CUSTOMER`, `COUNTERPARTY_CUSTOMER_ADD`, `COUNTERPARTY_CUSTOMER_EDIT`, `COUNTERPARTY_CUSTOMER_DELETE`, `WAREHOUSE`, `WAREHOUSE_ADD_PRODUCT`, `WAREHOUSE_EDIT_PRODUCT`, `WAREHOUSE_ANNULATE_PRODUCT`, `WAREHOUSE_EDIT_COUNT`, `ADMIN_PANEL`, `ADMIN_PANEL_ADD_ACCOUNT`, `ADMIN_PANEL_EDIT_ACCOUNT`, `ADMIN_PANEL_DELETE_ACCOUNT`, `ADMIN_PANEL_SET_NUMERATOR`, `ADMIN_PANEL_JOURNAL`, `IS_ANNULATED`, `REPORT_UN_ISSUE_PURCHASE_INVOICE`, `REPORT_UN_ISSUE_SALES_INVOICE`, `CODE`) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', '{22}', '{23}', '{24}', '{25}', '{26}', '{27}', '{28}', '{29}', '{30}', '{31}', '{32}', '{33}', '{34}', '{35}', '{36}', '{37}')", Login, newPass, PersonalData.Surname, PersonalData.Name, PersonalData.Patronymic, Criptex.Cript(PersonalData.Adress), Criptex.Cript(PersonalData.Phone), Conversion.ToString(PersonalData.Sex), Conversion.ToString(InvoiceData.PurchaseInvoice), Conversion.ToString(InvoiceData.SalesInvoice), Conversion.ToString(ReportsData.Reports), Conversion.ToString(ReportsData.ReportPurchaseInvoice), Conversion.ToString(ReportsData.ReportSalesInvoice), Conversion.ToString(ReportsData.ReportIncomeExpense), Conversion.ToString(CounterpartyData.Counterparty), Conversion.ToString(CounterpartyData.CounterpartyProvider), Conversion.ToString(CounterpartyData.CounterpartyProviderAdd), Conversion.ToString(CounterpartyData.CounterpartyProviderEdit), Conversion.ToString(CounterpartyData.CounterpartyProviderDelete), Conversion.ToString(CounterpartyData.CounterpartyCustomer), Conversion.ToString(CounterpartyData.CounterpartyCustomerAdd), Conversion.ToString(CounterpartyData.CounterpartyCustomerEdit), Conversion.ToString(CounterpartyData.CounterpartyCustomerDelete), Conversion.ToString(WarehouseData.Warehouse), Conversion.ToString(WarehouseData.WarehouseAddProduct), Conversion.ToString(WarehouseData.WarehouseEditProduct), Conversion.ToString(WarehouseData.WarehouseAnnulateProduct), Conversion.ToString(WarehouseData.WarehouseEditCount), Conversion.ToString(AdminPanelData.AdminPanel), Conversion.ToString(AdminPanelData.AdminPanelAddAccount), Conversion.ToString(AdminPanelData.AdminPanelEditAccount), Conversion.ToString(AdminPanelData.AdminPanelDeleteAccount), Conversion.ToString(AdminPanelData.AdminPanelSetNumerator), Conversion.ToString(AdminPanelData.AdminPanelJournal), 0, Conversion.ToString(ReportsData.ReportUnIssuePurchaseInvoice), Conversion.ToString(ReportsData.ReportUnIssueSalesInvoice), PersonalData.Code); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); ID = (int)command.LastInsertedId; } Journal.CreateJournal("создал", "пользователя " + _login, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка создания пользователя", ex.Message); } return(result); }
/// <summary> /// Аннулирование единицы измерения /// </summary> /// <returns>возвращает TRUE, если единица измерения аннулирована успешно</returns> public bool AnnulateUnit() { bool result = false; try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"UPDATE `UNIT` SET `IS_ANNULATED` = '1' WHERE `UNIT`.`ID` = {0}", ID); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } Journal.CreateJournal("аннулировал", "единицу измерения " + Nomination, connection); connection.Close(); IsAnnulated = true; } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка аннулирования единицы измерения", ex.Message); } return(result); }
/// <summary> /// Установить значение нумератора /// </summary> /// <param name="value">значение</param> /// <returns>возвращает TRUE, если значение изменено успешно</returns> public bool SetValue(int value) { bool result = false; try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"UPDATE `NUMERATOR` SET `VALUE` = '{0}' WHERE `NUMERATOR`.`ID` = {1}", value, ID); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } Journal.CreateJournal("переустановил", "значение нумератора " + Nomination, connection); connection.Close(); Value = value; } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка изменения значения нумератора", ex.Message); } return(result); }
/// <summary> /// Установить значение нумератора /// </summary> /// <param name="value">значение</param> /// <param name="isPurchase">приходная накладная</param> /// <returns>возвращает TRUE, если значение нумератора изменено успешно</returns> public static bool SetNumeratorValue(int value, bool isPurchase) { bool result = false; try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string nomination = (isPurchase) ? "Приходная накладная" : "Расходная накладная"; string sql = String.Format(@"UPDATE `NUMERATOR` SET `VALUE` = '{0}' WHERE `NUMERATOR`.`NOMINATION` = '{1}'", value, nomination); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } Journal.CreateJournal("переустановил", "значение нумератора " + nomination, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка изменения значения нумератора", ex.Message); } return(result); }
/// <summary> /// Аннулировать контрагента /// </summary> /// <returns>возвращает TRUE, если контрагент успешно аннулирован</returns> public bool AnnuateCounterparty() { bool result = false; if (_id != 0) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = @"UPDATE `COUNTERPARTY` SET `IS_ANNULATED` = '1' WHERE `COUNTERPARTY`.`ID` = " + ID.ToString(); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } IsAnnulated = true; string name = (Nomination != "") ? Nomination : Surname + " " + Name; Journal.CreateJournal("аннулировал", "контрагента " + name, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка аннулирования контрагента", ex.Message); } } else { Dialog.ErrorMessage(null, "Не указан ID контрагента"); } return(result); }
/// <summary> /// Реадктировать аккаунт /// </summary> /// <returns>возвращает TRUE, если аккаунт успешно отредактирован</returns> public bool EditAccount() { bool result = false; if (_id != 0) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"UPDATE `ACCOUNT` SET `LOGIN` = '{0}', `SURNAME` = '{1}', `NAME` = '{2}', `PATRONYMIC` = '{3}', `ADRESS` = '{4}', `PHONE` = '{5}', `SEX` = '{6}', `PURCHASE_INVOICE` = '{7}', `SALES_INVOICE` = '{8}', `REPORTS` = '{9}', `REPORT_PURCHASE_INVOICE` = '{10}', `REPORT_SALES_INVOICE` = '{11}', `REPORT_INCOME_EXPENSE` = '{12}', `COUNTERPARTY` = '{13}', `COUNTERPARTY_PROVIDER` = '{14}', `COUNTERPARTY_PROVIDER_ADD` = '{15}', `COUNTERPARTY_PROVIDER_EDIT` = '{16}', `COUNTERPARTY_PROVIDER_DELETE` = '{17}', `COUNTERPARTY_CUSTOMER` = '{18}', `COUNTERPARTY_CUSTOMER_ADD` = '{19}', `COUNTERPARTY_CUSTOMER_EDIT` = '{20}', `COUNTERPARTY_CUSTOMER_DELETE` = '{21}', `WAREHOUSE` = '{22}', `WAREHOUSE_ADD_PRODUCT` = '{23}', `WAREHOUSE_EDIT_PRODUCT` = '{24}', `WAREHOUSE_ANNULATE_PRODUCT` = '{25}', `WAREHOUSE_EDIT_COUNT` = '{26}', `ADMIN_PANEL` = '{27}', `ADMIN_PANEL_ADD_ACCOUNT` = '{28}', `ADMIN_PANEL_EDIT_ACCOUNT` = '{29}', `ADMIN_PANEL_DELETE_ACCOUNT` = '{30}', `ADMIN_PANEL_SET_NUMERATOR` = '{31}', `ADMIN_PANEL_JOURNAL` = '{32}', `REPORT_UN_ISSUE_PURCHASE_INVOICE` = '{33}', `REPORT_UN_ISSUE_SALES_INVOICE` = '{34}', `CODE` = '{35}' WHERE `ACCOUNT`.`ID` = {36}", Login, PersonalData.Surname, PersonalData.Name, PersonalData.Patronymic, Criptex.Cript(PersonalData.Adress), Criptex.Cript(PersonalData.Phone), Conversion.ToString(PersonalData.Sex), Conversion.ToString(InvoiceData.PurchaseInvoice), Conversion.ToString(InvoiceData.SalesInvoice), Conversion.ToString(ReportsData.Reports), Conversion.ToString(ReportsData.ReportPurchaseInvoice), Conversion.ToString(ReportsData.ReportSalesInvoice), Conversion.ToString(ReportsData.ReportIncomeExpense), Conversion.ToString(CounterpartyData.Counterparty), Conversion.ToString(CounterpartyData.CounterpartyProvider), Conversion.ToString(CounterpartyData.CounterpartyProviderAdd), Conversion.ToString(CounterpartyData.CounterpartyProviderEdit), Conversion.ToString(CounterpartyData.CounterpartyProviderDelete), Conversion.ToString(CounterpartyData.CounterpartyCustomer), Conversion.ToString(CounterpartyData.CounterpartyCustomerAdd), Conversion.ToString(CounterpartyData.CounterpartyCustomerEdit), Conversion.ToString(CounterpartyData.CounterpartyCustomerDelete), Conversion.ToString(WarehouseData.Warehouse), Conversion.ToString(WarehouseData.WarehouseAddProduct), Conversion.ToString(WarehouseData.WarehouseEditProduct), Conversion.ToString(WarehouseData.WarehouseAnnulateProduct), Conversion.ToString(WarehouseData.WarehouseEditCount), Conversion.ToString(AdminPanelData.AdminPanel), Conversion.ToString(AdminPanelData.AdminPanelAddAccount), Conversion.ToString(AdminPanelData.AdminPanelEditAccount), Conversion.ToString(AdminPanelData.AdminPanelDeleteAccount), Conversion.ToString(AdminPanelData.AdminPanelSetNumerator), Conversion.ToString(AdminPanelData.AdminPanelJournal), Conversion.ToString(ReportsData.ReportUnIssuePurchaseInvoice), Conversion.ToString(ReportsData.ReportUnIssueSalesInvoice), PersonalData.Code, ID); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } if (ProgramSettings.CurrentUser.ID != _id) { Journal.CreateJournal("изменил", "данные пользователя " + _login, connection); } connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка редактирования данных пользователя", ex.Message); } } else { Dialog.ErrorMessage(null, "Не указан ID пользователя"); } return(result); }
/// <summary> /// Отменить аннулирование товара /// </summary> /// <returns>возвращает TRUE если для товара аннулирование отменено успешно</returns> public bool UnAnnulateProduct() { bool result = false; if (_id != 0) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); IsAnnulated = false; string sql = String.Format(@"UPDATE `PRODUCT` SET `IS_ANNULATED` = '0' WHERE `PRODUCT`.`ID` = {0}", _id); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } Journal.CreateJournal("отменил", "аннулирование товара " + ProductCode, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка отмены аннулирования товара", ex.Message); } } else { Dialog.ErrorMessage(null, "Не указан ID товара"); } return(result); }
/// <summary> /// Редактировать данные контрагента /// </summary> /// <returns>возвращает TRUE, если контрагент успешно отредактирован</returns> public bool EditCounterparty() { bool result = false; if (_id != 0) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"UPDATE `COUNTERPARTY` SET `SURNAME` = '{0}', `NAME` = '{1}', `PATRONYMIC` = '{2}', `ADRESS` = '{3}', `PHONE` = '{4}', `NOMINATION` = '{5}', `IS_PROVIDER` = '{6}', `CODE` = '{7}' WHERE `COUNTERPARTY`.`ID` = {8}", Surname, Name, Patronymic, Conversion.ToCriptString(Adress), Conversion.ToCriptString(Phone), Nomination, Conversion.ToString(IsProvider), Code, ID); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } string name = (Nomination != "") ? Nomination : Surname + " " + Name; Journal.CreateJournal("изменил", "данные контрагента " + name, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка редактирования контрагента", ex.Message); } } else { Dialog.ErrorMessage(null, "Не указан ID контрагента"); } return(result); }
/// <summary> /// Аннулировать аккаунт /// </summary> /// <returns>возвращает TRUE, если аккаунт успешно аннулирован</returns> public bool AnnuateAccount() { bool result = false; if (_id != 0) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = @"UPDATE `ACCOUNT` SET `IS_ANNULATED` = '1' WHERE `ACCOUNT`.`ID` = " + ID.ToString(); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } IsAnnulated = true; Journal.CreateJournal("аннулировал", "пользователя " + _login, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка аннулирования пользователя", ex.Message); } } else { Dialog.ErrorMessage(null, "Не указан ID пользователя"); } return(result); }
/// <summary> /// Редактировать количество /// </summary> /// <returns>возвращает TRUE если количество отредактировано успешно</returns> public bool EditCount() { bool result = false; if (_id != 0) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"UPDATE `PRODUCT` SET `COUNT` = '{0}', `ID_UNIT` = '{1}' WHERE `PRODUCT`.`ID` = {2}", Conversion.ToString(_count), _id_unit, _id); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } Journal.CreateJournal("изменил", "количество товара " + ProductCode, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка изменения количества товара", ex.Message); } } else { Dialog.ErrorMessage(null, "Не указан ID товара"); } return(result); }
/// <summary> /// Редактирование товара /// </summary> /// <returns>возвращает TRUE если товар отредактирован успешно</returns> public bool EditProduct() { bool result = false; if (_id != 0) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = String.Format(@"UPDATE `PRODUCT` SET `PRODUCT_CODE` = '{0}', `NOMINATION` = '{1}', `COUNT_IN_PACKAGE` = '{2}', `COST` = '{3}', `COUPON` = '{4}', `ID_UNIT` = '{5}', `COST_PURCHASE` = '{6}', `COUPON_PURCHASE` = '{7}' WHERE `PRODUCT`.`ID` = {8}", _productCode, _nomination, Conversion.ToString(_countInPackage), Conversion.ToString(_cost), Conversion.ToString(_coupon), _id_unit, _costPurchase, _couponPurchase, _id); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } Journal.CreateJournal("изменил", "товар " + ProductCode, connection); connection.Close(); } result = true; } catch (Exception ex) { Dialog.ErrorMessage(null, "Ошибка редактирования товара", ex.Message); } } else { Dialog.ErrorMessage(null, "Не указан ID товара"); } return(result); }
/// <summary> /// Отменить проведение накладной /// </summary> /// <returns>возвращает TRUE, если отмена проведения накладной выполнена успешно</returns> public bool UnIssueInvoice() { bool result = false; if (_id != 0) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = string.Empty; IsIssued = false; Date = DateTime.MinValue; string table = (IsPurchase) ? "PURCHASE_INVOICE" : "SALES_INVOICE"; // Проведение накладной sql = String.Format(@"UPDATE `{0}` SET `IS_ISSUED` = '{1}', `DATE` = '{2}' WHERE `{0}`.`ID` = {3}", table, Conversion.ToString(IsIssued), Conversion.ToString(Date), _id); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } // Добавление/уменьшение товаров foreach (InvoiceItem item in Items) { sql = String.Format(@"SELECT `COUNT` FROM `PRODUCT` WHERE `PRODUCT`.`ID` = {0}", item.ID_Product); double count = 0; using (MySqlCommand command = new MySqlCommand(sql, connection)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string tempS = reader["COUNT"].ToString(); double tempD = 0; if (double.TryParse(tempS, out tempD)) { count = tempD; } else { count = 0; } } } } // Изменение количества товара if (IsPurchase) { count -= item.Count; } else { count += item.Count; } sql = String.Format(@"UPDATE `PRODUCT` SET `COUNT` = '{0}' WHERE `PRODUCT`.`ID` = {1}", count, item.ID_Product); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } } string name = (IsPurchase) ? "проведение приходной накладной " : "проведение расходной накладной "; Journal.CreateJournal("отменил", name + Number.ToString(), connection); connection.Close(); } } catch (Exception ex) { result = false; Dialog.ErrorMessage(null, "Ошибка отмены проведения накладной", ex.Message); } } else { Dialog.ErrorMessage(null, "Не указан ID накладной"); } return(result); }
/// <summary> /// Провести накладную /// </summary> /// <returns>возвращает TRUE, если накладная проведена успешно</returns> public bool IssueInvoice() { bool result = false; if (_id != 0) { result = EditInvoice(); if (result) { try { using (MySqlConnection connection = new MySqlConnection(Criptex.UnCript(ProgramSettings.ConnectionString))) { connection.Open(); string sql = string.Empty; if (Number == 0) { // Получение номера string nomination = string.Empty; if (IsPurchase) { nomination = NumeratorNames.PurchaseInvoice; } else { nomination = NumeratorNames.SalesInvoice; } sql = String.Format(@"SELECT `VALUE` FROM `NUMERATOR` WHERE `NUMERATOR`.`NOMINATION` = '{0}'", nomination); // Получение значения нумератора using (MySqlCommand command = new MySqlCommand(sql, connection)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string tempS = reader["VALUE"].ToString(); int tempI = 0; if (int.TryParse(tempS, out tempI)) { Number = tempI + 1; } else { Number = 1; } } } } // Обновление значения нумератора sql = String.Format(@"UPDATE `NUMERATOR` SET `VALUE` = '{0}' WHERE `NUMERATOR`.`NOMINATION` = '{1}'", Number, nomination); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } } IsIssued = true; string table = (IsPurchase) ? "PURCHASE_INVOICE" : "SALES_INVOICE"; // Проведение накладной sql = String.Format(@"UPDATE `{0}` SET `NUMBER` = '{1}', `IS_ISSUED` = '{2}', `DATE` = '{3}' WHERE `{0}`.`ID` = {4}", table, Number, Conversion.ToString(IsIssued), Conversion.ToString(DateTime.Today), _id); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } Date = DateTime.Today; // Добавление/уменьшение товаров foreach (InvoiceItem item in Items) { sql = String.Format(@"SELECT `COUNT` FROM `PRODUCT` WHERE `PRODUCT`.`ID` = {0}", item.ID_Product); double count = 0; using (MySqlCommand command = new MySqlCommand(sql, connection)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string tempS = reader["COUNT"].ToString(); double tempD = 0; if (double.TryParse(tempS, out tempD)) { count = tempD; } else { count = 0; } } } } // Изменение количества товара if (IsPurchase) { count += item.Count; } else { count -= item.Count; } sql = String.Format(@"UPDATE `PRODUCT` SET `COUNT` = '{0}' WHERE `PRODUCT`.`ID` = {1}", count, item.ID_Product); using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.ExecuteNonQuery(); } } string name = (IsPurchase) ? "приходную накладную " : "расходную накладную "; Journal.CreateJournal("провел", name + Number.ToString(), connection); connection.Close(); } } catch (Exception ex) { result = false; Dialog.ErrorMessage(null, "Ошибка проведения накладной", ex.Message); } } } else { Dialog.ErrorMessage(null, "Не указан ID накладной"); } return(result); }