private void SyncItems() { int num; DataTable dataSource = this.grdItems.DataSource as DataTable; if (dataSource != null) { foreach (DataRow row in dataSource.Rows) { InvoiceAutoItem item = this.invoiceAuto.Items.Find((InvoiceAutoItem it) => it.Id_party == (long)row["ID_LOT"]); if (item == null) { continue; } foreach (DataColumn column in dataSource.Columns) { string columnName = column.ColumnName; string str = columnName; if (columnName != null && (str == "ID_LOT" || str == "GOODS_NAME" || str == "SCALING" || str == "SOLD" || str == "REMAIN" || str == "STORE_QUANTITY" || str == "LEFT_QUANTITY") || !int.TryParse(column.ColumnName, out num) || num < 0 || num >= item.Quantities.Count) { continue; } item.Quantities[num] = (decimal)row[column]; } } } foreach (InvoiceAutoItem invoiceAutoItem in this.invoiceAuto.Items) { DataRow leftQuantity = dataSource.Rows.Find(invoiceAutoItem.Id_party); if (leftQuantity == null) { continue; } for (int i = 0; i < invoiceAutoItem.Quantities.Count; i++) { if (!this.chStore.GetItemChecked(i)) { invoiceAutoItem.Quantities[i] = new decimal(0); } else { leftQuantity[i.ToString()] = invoiceAutoItem.Quantities[i]; } } leftQuantity["LEFT_QUANTITY"] = invoiceAutoItem.Left_quantity; } this.grdItems.BindingSource.ResetCurrentItem(); }
private void buttonStore_Click(object sender, EventArgs e) { if (this.pluginBox1.RowItem.Id == (long)0) { return; } StockSelectWrapper stockSelectWrapper = new StockSelectWrapper(); stockSelectWrapper.StockFilter.StoreId = this.pluginBox1.RowItem.Id; if (stockSelectWrapper.Show() == System.Windows.Forms.DialogResult.OK) { StockRecord stockRecord = StockSelectWrapper.GetStockRecord(stockSelectWrapper.GridController.SelectedRow()); InvoiceAutoItem invoiceAutoItem = new InvoiceAutoItem() { Id_goods = stockRecord.IdGoods, Id_party = stockRecord.IdLot }; foreach (InvoiceAutoItem item in this.invoiceAuto.Items) { if (item.Id_goods != invoiceAutoItem.Id_goods || item.Id_party != invoiceAutoItem.Id_party) { continue; } return; } GOODS_BL bL = (GOODS_BL)BLProvider.Instance.GetBL(typeof(GOODS_BL)); invoiceAutoItem.Goods_name = ((GOODS)bL.Load(invoiceAutoItem.Id_goods)).NAME; LOT_BL lOTBL = (LOT_BL)BLProvider.Instance.GetBL(typeof(LOT_BL)); LOT lOT = lOTBL.Load(invoiceAutoItem.Id_party); if (lOT.QUANTITY_REM <= new decimal(0)) { return; } invoiceAutoItem.Store_quantity = lOT.QUANTITY_REM; invoiceAutoItem.Id_scale_ratio = lOT.ID_SCALING_RATIO; SCALING_RATIO_BL sCALINGRATIOBL = (SCALING_RATIO_BL)BLProvider.Instance.GetBL(typeof(SCALING_RATIO_BL)); SCALING_RATIO sCALINGRATIO = (SCALING_RATIO)sCALINGRATIOBL.Load(invoiceAutoItem.Id_scale_ratio); invoiceAutoItem.Scale_ratio_name = string.Concat(sCALINGRATIO.SCALING_RATIO_TEXT, ' ', sCALINGRATIO.UNIT_NAME); this.plInvoice.SetId((long)0); this.invoiceAuto.Items.Add(invoiceAutoItem); this.TransformData(); this.grdItems.BindingSource.CurrencyManager.Refresh(); } }
private void TransformData() { int num; int num1; foreach (InvoiceAutoItem item in this.invoiceAuto.Items) { item.Quantities.Clear(); for (int i = 0; i < this.chStore.Items.Count; i++) { item.Quantities.Add(new decimal(0)); } } /// 2019 /// простой расчет заказа Zakaz(); DataTable dataSource = this.grdItems.DataSource as DataTable; if (dataSource != null) { foreach (DataRow row in dataSource.Rows) { InvoiceAutoItem invoiceAutoItem = this.invoiceAuto.Items.Find((InvoiceAutoItem it) => it.Id_party == (long)row["ID_LOT"]); if (invoiceAutoItem == null) { continue; } foreach (DataColumn column in dataSource.Columns) { string columnName = column.ColumnName; string str = columnName; if (columnName != null && (str == "ID_LOT" || str == "GOODS_NAME" || str == "SCALING" || str == "REMAIN" || str == "SOLD" || str == "STORE_QUANTITY" || str == "LEFT_QUANTITY") || !int.TryParse(column.ColumnName, out num) || num < 0 || num >= invoiceAutoItem.Quantities.Count) { continue; } invoiceAutoItem.Quantities[num] = (decimal)row[column]; } } } DataTable dataTable = new DataTable(); DataColumn dataColumn = dataTable.Columns.Add("ID_LOT", typeof(long)); dataColumn.ReadOnly = true; dataTable.PrimaryKey = new DataColumn[] { dataColumn }; dataTable.Columns.Add("GOODS_NAME", typeof(string)).ReadOnly = true; dataTable.Columns.Add("SCALING", typeof(string)).ReadOnly = true; dataTable.Columns.Add("STORE_QUANTITY", typeof(decimal)).ReadOnly = true; dataTable.Columns.Add("LEFT_QUANTITY", typeof(decimal)); /*2019*/ dataTable.Columns.Add("SOLD", typeof(decimal)).ReadOnly = true; // продано за месяц в аптеке dataTable.Columns.Add("REMAIN", typeof(decimal)).ReadOnly = true; // сколько осталось в аптеке /*2019*/ if (this.invoiceAuto.Items.Count > 0) { InvoiceAutoItem item1 = this.invoiceAuto.Items[0]; for (int j = 0; j < item1.Quantities.Count; j++) { if (this.chStore.GetItemChecked(j)) { dataTable.Columns.Add(j.ToString(), typeof(decimal)); } } } this.grdItems.DataGridView.Columns.Clear(); this.grdItems.DataSource = dataTable; foreach (DataColumn column1 in dataTable.Columns) { DataGridViewColumn dataGridViewColumn = null; if (column1.DataType == typeof(string)) { DataGridViewTextBoxCell2 dataGridViewTextBoxCell2 = new DataGridViewTextBoxCell2() { ValueType = typeof(string) }; dataGridViewColumn = new DataGridViewColumn(dataGridViewTextBoxCell2) { Tag = new MetaGeColumnString() }; } if (column1.DataType == typeof(decimal) || column1.DataType == typeof(long)) { dataGridViewColumn = new DataGridViewColumn(new DataGridViewNumericCell()); dataGridViewColumn.CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight; dataGridViewColumn.CellTemplate.Style.Format = "N0"; dataGridViewColumn.Tag = new MetaGeColumnNumeric(); } if (dataGridViewColumn == null) { continue; } dataGridViewColumn.DataPropertyName = column1.ColumnName; this.grdItems.DataGridView.Columns.Add(dataGridViewColumn); } foreach (DataGridViewColumn dataGridViewColumn1 in this.grdItems.DataGridView.Columns) { string dataPropertyName = dataGridViewColumn1.DataPropertyName; string str1 = dataPropertyName; if (dataPropertyName != null) { if (str1 == "ID_LOT") { dataGridViewColumn1.Visible = false; continue; } else if (str1 == "GOODS_NAME") { dataGridViewColumn1.HeaderText = "Товар"; dataGridViewColumn1.DisplayIndex = 0; dataGridViewColumn1.Frozen = true; continue; } else if (str1 == "SCALING") { dataGridViewColumn1.HeaderText = "Единица измерения"; dataGridViewColumn1.DisplayIndex = 1; dataGridViewColumn1.Frozen = true; continue; } else if (str1 == "STORE_QUANTITY") { dataGridViewColumn1.HeaderText = "На складе"; dataGridViewColumn1.DisplayIndex = 2; dataGridViewColumn1.Frozen = true; continue; } else if (str1 == "LEFT_QUANTITY") { dataGridViewColumn1.HeaderText = "Не распределено"; dataGridViewColumn1.DisplayIndex = 3; dataGridViewColumn1.Frozen = true; dataGridViewColumn1.ReadOnly = true; continue; } else if (str1 == "SOLD") { dataGridViewColumn1.HeaderText = "Продано"; dataGridViewColumn1.DisplayIndex = 4; dataGridViewColumn1.Frozen = true; dataGridViewColumn1.ReadOnly = true; continue; } else if (str1 == "REMAIN") { dataGridViewColumn1.HeaderText = "Остаток в аптеке"; dataGridViewColumn1.DisplayIndex = 5; dataGridViewColumn1.Frozen = true; dataGridViewColumn1.ReadOnly = true; continue; } } //название склада в заголовок колонки if (!int.TryParse(dataGridViewColumn1.DataPropertyName, out num1) || !this.storeDict.ContainsKey(num1)) { continue; } dataGridViewColumn1.HeaderText = this.storeDict[num1]; } foreach (InvoiceAutoItem invoiceAutoItem1 in this.invoiceAuto.Items) { DataRow idParty = dataTable.NewRow(); idParty["ID_LOT"] = invoiceAutoItem1.Id_party; idParty["GOODS_NAME"] = invoiceAutoItem1.Goods_name; idParty["SCALING"] = invoiceAutoItem1.Scale_ratio_name; idParty["STORE_QUANTITY"] = invoiceAutoItem1.Store_quantity; idParty["SOLD"] = invoiceAutoItem1.Sold; idParty["REMAIN"] = invoiceAutoItem1.Remain; for (int k = 0; k < invoiceAutoItem1.Quantities.Count; k++) { if (!this.chStore.GetItemChecked(k)) { invoiceAutoItem1.Quantities[k] = new decimal(0); } else { idParty[k.ToString()] = invoiceAutoItem1.Quantities[k]; } } idParty["LEFT_QUANTITY"] = invoiceAutoItem1.Left_quantity; dataTable.Rows.Add(idParty); } this.grdItems.BindingSource.ResetBindings(true); this.grdItems.DataGridView.AutoResizeColumns(); }