void FormAdminUserEditLoad(object sender, EventArgs e) { //Создание новой записи if (this.Text == "Создать") { //... } //Изменение записи if (this.Text == "Редактировать") { // Загрузка данных из базы данных MsSQLFull UsersMySQL = new MsSQLFull(); DataSet UsersDataSet = new DataSet(); UsersDataSet.Clear(); UsersDataSet.DataSetName = "users"; UsersMySQL.SelectSqlCommand = "SELECT * FROM users WHERE (id_user = "******")"; UsersMySQL.ExecuteFill(UsersDataSet, "users"); DataTable table = UsersDataSet.Tables["users"]; DataRow row = table.Rows[0]; textBox1.Text = row["user_name"].ToString(); comboBox1.Text = row["user_right"].ToString(); textBox2.Text = row["user_pass"].ToString(); textBox3.Text = textBox2.Text; richTextBox1.Text = row["user_additionally"].ToString(); } }
/* Загрузка табличной части (на основании заказа) */ void basedTabularSection(String basedDocID) { DataSet basedDS = new DataSet(); basedDS.Clear(); basedDS.DataSetName = "tabularsection"; MsSQLFull based = new MsSQLFull(); based.SelectSqlCommand = "SELECT id_tabularSection, tabularSection_tmc, tabularSection_units, tabularSection_number, tabularSection_price, tabularSection_NDS, tabularSection_sum, tabularSection_total, tabularSection_id_doc FROM tabularsection WHERE (tabularSection_id_doc = '" + basedDocID + "')"; if (based.ExecuteFill(basedDS, "tabularsection")) { foreach (DataRow row in basedDS.Tables[0].Rows) { DataRow newRow = ComingTS_DataSet.Tables[0].NewRow(); newRow["tabularSection_tmc"] = row["tabularSection_tmc"]; newRow["tabularSection_units"] = row["tabularSection_units"]; newRow["tabularSection_number"] = row["tabularSection_number"]; newRow["tabularSection_price"] = row["tabularSection_price"]; newRow["tabularSection_NDS"] = row["tabularSection_NDS"]; newRow["tabularSection_sum"] = row["tabularSection_sum"]; newRow["tabularSection_total"] = row["tabularSection_total"]; newRow["tabularSection_id_doc"] = DocID; ComingTS_DataSet.Tables[0].Rows.Add(newRow); } } else { ClassForms.Rapid_Client.MessageConsole("Приходная Накладная: Ошибка загрузки табличной части заказа.", true); } }
/* Показать остаток на складе */ public static String BalanceShow(String _tmcName, String _actualDate) { MsSQLFull balanceMySQL = new MsSQLFull(); DataSet balanceDataSet = new DataSet(); balanceDataSet.Clear(); balanceDataSet.DataSetName = "balance"; balanceMySQL.SelectSqlCommand = "SELECT * FROM balance WHERE (balance_tmc = '" + _tmcName + "' AND balance_date <= '" + _actualDate + "')"; if (balanceMySQL.ExecuteFill(balanceDataSet, "balance")) { DataTable table = balanceDataSet.Tables["balance"]; if (table.Rows.Count > 0) { return(table.Rows[0]["balance_number"].ToString()); } else { return("--"); } } else { return("--"); } }
/*public ClassCalculation() * { * * }*/ /* Вычисление НДС */ public static String NDS(String _ndsName, String _sum) { double _nds; MsSQLFull typetaxMySQL = new MsSQLFull(); DataSet typetaxDataSet = new DataSet(); typetaxDataSet.Clear(); typetaxDataSet.DataSetName = " typetax"; typetaxMySQL.SelectSqlCommand = "SELECT * FROM typetax WHERE (typeTax_name = '" + _ndsName + "')"; if (typetaxMySQL.ExecuteFill(typetaxDataSet, "typetax")) { DataTable table = typetaxDataSet.Tables["typetax"]; if (table.Rows.Count > 0) { // НДС (в %) = Сумма без НДС * Ставка НДС / 100 _nds = ClassConversion.StringToDouble(_sum) * ClassConversion.StringToDouble(table.Rows[0]["typeTax_rating"].ToString()) / 100.00; _nds = Math.Round(_nds, 2); return(ClassConversion.StringToMoney(_nds.ToString())); } else { return("0.00"); } } else { ClassForms.Rapid_Client.MessageConsole("Заказ: Ошибка получения ставки НДС при вычислении.", true); } return("0.00"); }
/* Выполняем удаление выбранных элементов */ void removeInTable(String _tableName, String _value) { if (_tableName == "Фирмы") { _deleteMySQL.SqlCommand = "DELETE FROM firms WHERE (firm_name = '" + _value + "' AND firm_delete = 1)"; } if (_tableName == "ТМЦ") { _deleteMySQL.SqlCommand = "DELETE FROM tmc WHERE (tmc_name = '" + _value + "' AND tmc_delete = 1)"; } if (_tableName == "Склады") { _deleteMySQL.SqlCommand = "DELETE FROM store WHERE (store_name = '" + _value + "' AND store_delete = 1)"; } if (_tableName == "Ед.Изм") { _deleteMySQL.SqlCommand = "DELETE FROM units WHERE (units_name = '" + _value + "' AND units_delete = 1)"; } if (_tableName == "Вид налога") { _deleteMySQL.SqlCommand = "DELETE FROM typeTax WHERE (typeTax_name = '" + _value + "' AND typeTax_delete = 1)"; } if (_tableName == "Сотрудники") { _deleteMySQL.SqlCommand = "DELETE FROM staff WHERE (staff_name = '" + _value + "' AND staff_delete = 1)"; } if (_tableName == "План счетов") { _deleteMySQL.SqlCommand = "DELETE FROM planAccounts WHERE (planAccounts_name = '" + _value + "' AND planAccounts_delete = 1)"; } if (_tableName == "Документ") { MsSQLFull _removeDocMySQL = new MsSQLFull(); DataSet _removeDocDataSet = new DataSet(); _removeDocMySQL.SelectSqlCommand = "SELECT * FROM journal WHERE (journal_number = '" + _value + "' AND journal_delete = 1)"; _removeDocDataSet.Clear(); _removeDocDataSet.DataSetName = "journal"; if (_removeDocMySQL.ExecuteFill(_removeDocDataSet, "journal")) { _deleteMySQL.SqlCommand = "DELETE FROM tabularSection WHERE (tabularSection_id_doc = '" + _removeDocDataSet.Tables["journal"].Rows[0]["journal_id_doc"].ToString() + "')"; if (_deleteMySQL.ExecuteNonQuery()) { _deleteMySQL.SqlCommand = "DELETE FROM journal WHERE (journal_number = '" + _value + "' AND journal_delete = 1)"; if (_deleteMySQL.ExecuteNonQuery()) { listBox1.Items.Add("[" + _tableName + "] " + _value + " - - - Запись удалена!"); } } } } else { if (_deleteMySQL.ExecuteNonQuery()) { listBox1.Items.Add("[" + _tableName + "] " + _value + " - - - Запись удалена!"); } } }
/* Загрузка данных из таблицы фирмы*/ void TmcDataLoad(String tmcName) { MsSQLFull tmcMySQL = new MsSQLFull(); DataSet tmcDataSet = new DataSet(); tmcDataSet.Clear(); tmcDataSet.DataSetName = "tmc"; tmcMySQL.SelectSqlCommand = "SELECT * FROM tmc WHERE (tmc_name = '" + tmcName + "')"; if (tmcMySQL.ExecuteFill(tmcDataSet, "tmc")) { DataTable table = tmcDataSet.Tables["tmc"]; if (table.Rows.Count > 0) { // Наименование ТМЦ textBox2.Text = table.Rows[0]["tmc_units"].ToString(); // Количество ТМЦ на складе textBox3.Text = "1.00"; label9.Text = "Остаток на складе: " + ClassBalance.BalanceShow(textBox1.Text, ActualDate) + " "; // Цена (покупка или продажа) if (BuyOrSell) { textBox4.Text = ClassConversion.StringToMoney(table.Rows[0]["tmc_buy"].ToString()); } else { textBox4.Text = ClassConversion.StringToMoney(table.Rows[0]["tmc_sale"].ToString()); } // Вид НДС textBox5.Text = table.Rows[0]["tmc_type_tax"].ToString(); //Вычисление Calculation(); } else { //ТМЦ не найден textBox2.Clear(); textBox3.Text = "0.00"; textBox4.Text = "0.00"; textBox5.Text = ClassSelectConst.constantValue("Вид НДС"); textBox6.Text = "0.00"; textBox7.Text = "0.00"; textBox8.Text = "0.00"; } } else { ClassForms.Rapid_Client.MessageConsole("Заказ: Ошибка при загрузке данных о тмц.", true); } }
/* Обновление данных в остатках ----------------------------------------*/ /* Увеличение остатков */ public static void BalancePlus(DataSet ResourceDS) { MsSQLFull _mySql = new MsSQLFull(); DataSet _dataSet = new DataSet(); _dataSet.Clear(); _dataSet.DataSetName = "balance"; _mySql.SelectSqlCommand = "SELECT id_balance, balance_tmc, balance_date, balance_number FROM balance"; _mySql.InsertSqlCommand = "INSERT INTO balance (balance_tmc, balance_date, balance_number) VALUES (@balance_tmc, @balance_date, @balance_number)"; _mySql.InsertParametersAdd("@balance_tmc", SqlDbType.VarChar, 250, "balance_tmc", UpdateRowSource.None); _mySql.InsertParametersAdd("@balance_date", SqlDbType.Date, 10, "balance_date", UpdateRowSource.None); _mySql.InsertParametersAdd("@balance_number", SqlDbType.Float, 10, "balance_number", UpdateRowSource.None); _mySql.UpdateSqlCommand = "UPDATE balance SET balance_tmc = @balance_tmc, balance_date = @balance_date, balance_number = @balance_number WHERE (id_balance = @id_balance)"; _mySql.UpdateParametersAdd("@balance_tmc", SqlDbType.VarChar, 250, "balance_tmc", UpdateRowSource.None); _mySql.UpdateParametersAdd("@balance_date", SqlDbType.Date, 10, "balance_date", UpdateRowSource.None); _mySql.UpdateParametersAdd("@balance_number", SqlDbType.Float, 10, "balance_number", UpdateRowSource.None); _mySql.UpdateParametersAdd("@id_balance", SqlDbType.SmallInt, 11, "id_balance", UpdateRowSource.None); _mySql.DeleteSqlCommand = "DELETE FROM balance WHERE (id_balance = @id_balance)"; _mySql.DeleteParametersAdd("@id_balance", SqlDbType.SmallInt, 11, "id_balance", UpdateRowSource.None); if (_mySql.ExecuteFill(_dataSet, "balance")) { // Ввод остатков foreach (DataRow rowTS in ResourceDS.Tables["tabularsection"].Rows) { foreach (DataRow rowBalance in _dataSet.Tables["balance"].Rows) { if (rowTS["tabularSection_tmc"].ToString() == rowBalance["balance_tmc"].ToString()) { double sum = ClassConversion.StringToDouble(rowBalance["balance_number"].ToString()) + ClassConversion.StringToDouble(rowTS["tabularSection_number"].ToString()); rowBalance["balance_number"] = sum; } } } if (_mySql.ExecuteUpdate(_dataSet, "balance")) { ClassForms.Rapid_Client.MessageConsole("Остатки: Успешное обновление остатков.", false); } else { ClassForms.Rapid_Client.MessageConsole("Остатки: Ошибка ввод и сохранения новых остатков.", true); } } else { ClassForms.Rapid_Client.MessageConsole("Остатки: Ошибка обращения к остаткам.", true); } }
/*Возвращает значение выбранной константы */ public static String constantValue(String constName) { MsSQLFull _constMySQL = new MsSQLFull(); DataSet _constDataSet = new DataSet(); _constDataSet.Clear(); _constDataSet.DataSetName = "constants"; _constMySQL.SelectSqlCommand = "SElECT * FROM constants WHERE (const_name = '" + constName + "')"; if (_constMySQL.ExecuteFill(_constDataSet, "constants")) { DataTable table = _constDataSet.Tables["constants"]; return(table.Rows[0]["const_value"].ToString()); } else { return(""); } }
/* Загрузка данных из таблицы фирмы*/ void FirmSellerDataLoad(String firmName) { MsSQLFull firmMySQL = new MsSQLFull(); DataSet firmDataSet = new DataSet(); firmDataSet.Clear(); firmDataSet.DataSetName = "firms"; firmMySQL.SelectSqlCommand = "SELECT * FROM firms WHERE (firm_name = '" + firmName + "')"; if (firmMySQL.ExecuteFill(firmDataSet, "firms")) { DataTable table = firmDataSet.Tables["firms"]; if (table.Rows.Count > 0) { textBox4.Text = table.Rows[0]["firm_details"].ToString() + System.Environment.NewLine + "Адрес и телефон:" + System.Environment.NewLine + table.Rows[0]["firm_address_phone"].ToString(); } } else { ClassForms.Rapid_Client.MessageConsole("Приходная Накладная: Ошибка при загрузке данных о фирме.", true); } }
/* Остатки после удаления документа */ public static void BalanceRemoval(String docID, bool actionPlus) { MsSQLFull _mySql = new MsSQLFull(); DataSet _dataSet = new DataSet(); _dataSet.Clear(); _dataSet.DataSetName = "tabularsection"; _mySql.SelectSqlCommand = "SELECT tabularsection.*, journal.* FROM tabularsection, journal WHERE (journal.id_journal = " + docID + " AND tabularsection.tabularSection_id_doc = journal.journal_id_doc)"; if (_mySql.ExecuteFill(_dataSet, "tabularsection")) { if (actionPlus) { BalancePlus(_dataSet); } else { BalanceMinus(_dataSet); } } else { ClassForms.Rapid_Client.MessageConsole("Остатки: Ошибка обращения к табличной части документа.", true); } }