Пример #1
0
        private void FormStockInfoModify_Load(object sender, EventArgs e)
        {
            if (this.mode == FormMode.ALTER && this.stockInfoID == -1)
            {
                throw new Exception("未设置源库存信息");
            }

            Utilities.CreateEditPanel(this.tableLayoutPanelTextBoxes, StockInfoViewMetaData.KeyNames);

            if (this.mode == FormMode.ALTER)
            {
                StockInfoView stockInfoView = null;
                try
                {
                    stockInfoView = (from s in this.wmsEntities.StockInfoView
                                     where s.ID == this.stockInfoID
                                     select s).Single();
                }
                catch
                {
                    MessageBox.Show("加载数据失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }
                Utilities.CopyPropertiesToTextBoxes(stockInfoView, this);
            }
        }
Пример #2
0
        private void textBoxComponentName_Click(object sender, EventArgs e)
        {
            if (this.formSelectStockInfo == null)
            {
                this.formSelectStockInfo = new FormSelectStockInfo(this.projectID, this.warehouseID);

                formSelectStockInfo.SetSelectFinishedCallback((selectedStockInfoID) =>
                {
                    this.curStockInfoID = selectedStockInfoID;
                    if (!this.IsDisposed)
                    {
                        this.Invoke(new Action(() =>
                        {
                            textBoxComponentName.Text = "加载中...";
                        }));
                    }
                    new Thread(new ThreadStart(() =>
                    {
                        WMSEntities wmsEntities     = new WMSEntities();
                        StockInfoView stockInfoView = null;
                        Supply supply = null;
                        try
                        {
                            stockInfoView = (from s in wmsEntities.StockInfoView
                                             where s.ID == selectedStockInfoID
                                             select s).FirstOrDefault();
                            supply = (from s in wmsEntities.Supply where s.ID == stockInfoView.SupplyID select s).FirstOrDefault();
                        }
                        catch
                        {
                            MessageBox.Show("刷新数据失败,请检查网络连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        this.Invoke(new Action(() =>
                        {
                            Utilities.CopyPropertiesToTextBoxes(stockInfoView, this);
                            TextBox textBoxUnit       = (TextBox)this.Controls.Find("textBoxUnit", true)[0];
                            TextBox textBoxUnitAmount = (TextBox)this.Controls.Find("textBoxUnitAmount", true)[0];
                            if (supply != null && string.IsNullOrWhiteSpace(textBoxUnit.Text) && string.IsNullOrWhiteSpace(textBoxUnitAmount.Text))
                            {
                                textBoxUnit.Text = supply.DefaultShipmentUnit;
                                if (supply.DefaultShipmentUnitAmount != null)
                                {
                                    textBoxUnitAmount.Text = Utilities.DecimalToString(supply.DefaultShipmentUnitAmount.Value);
                                }
                            }
                        }));
                    })).Start();
                });
            }

            formSelectStockInfo.ShowDialog();
        }
        private void Search()
        {
            string key   = null;
            string value = null;

            if (this.toolStripComboBoxSelect1.SelectedIndex != 0)
            {
                key = (from kn in StockInfoViewMetaData.KeyNames
                       where kn.Name == this.toolStripComboBoxSelect1.SelectedItem.ToString()
                       select kn.Key).First();
                value = this.textBoxSearchValue.Text;
            }

            this.labelStatus.Text = "正在搜索中...";
            var worksheet = this.reoGridControlComponen.Worksheets[0];

            worksheet[0, 0] = "加载中...";
            new Thread(new ThreadStart(() =>
            {
                StockInfoView[] stockInfoViews = null;
                string sql = "SELECT * FROM StockInfoView WHERE 1=1";
                List <SqlParameter> parameters = new List <SqlParameter>();


                if (key != null && value != null) //查询条件不为null则增加查询条件
                {
                    sql += "AND " + key + " = @value ";
                    parameters.Add(new SqlParameter("value", value));
                }
                sql           += " ORDER BY ID DESC"; //倒序排序
                stockInfoViews = wmsEntities.Database.SqlQuery <StockInfoView>(sql, parameters.ToArray()).ToArray();
                this.reoGridControlComponen.Invoke(new Action(() =>
                {
                    this.labelStatus.Text = "搜索完成";
                    worksheet.DeleteRangeData(RangePosition.EntireRange);
                    if (stockInfoViews.Length == 0)
                    {
                        worksheet[0, 1] = "没有查询到符合条件的记录";
                    }
                    for (int i = 0; i < stockInfoViews.Length; i++)
                    {
                        StockInfoView curStockInfoView = stockInfoViews[i];
                        object[] columns = Utilities.GetValuesByPropertieNames(curStockInfoView, (from kn in StockInfoViewMetaData.KeyNames select kn.Key).ToArray());
                        for (int j = 0; j < worksheet.Columns; j++)
                        {
                            worksheet[i, j] = columns[j] == null ? "" : columns[j].ToString();
                        }
                    }
                }));
            })).Start();
        }