예제 #1
0
        private void buttonSubmission_Click(object sender, EventArgs e)
        {
            WMSEntities wmsEntities      = new WMSEntities();
            var         worksheet        = this.reoGridControlUser.Worksheets[0];
            List <ReceiptTicketItem> ids = new List <ReceiptTicketItem>();
            bool result;

            for (int i = 0; i < this.countRow; i++)
            {
                result = (worksheet[i, this.checkColumn] as bool?) ?? false;
                if (result == true)
                {
                    int id;
                    if (int.TryParse(worksheet[i, 0].ToString(), out id) == false)
                    {
                        MessageBox.Show(worksheet[i, 0].ToString() + "加入失败");
                    }
                    else
                    {
                        ReceiptTicketItem receiptTicketItem = (from rti in wmsEntities.ReceiptTicketItem where rti.ID == id select rti).FirstOrDefault();
                        if (receiptTicketItem.State == "已收货" || receiptTicketItem.State == "送检中")
                        {
                            MessageBox.Show(receiptTicketItem.ID + " " + receiptTicketItem.State);
                            return;
                        }
                        else
                        {
                            ids.Add(receiptTicketItem);
                        }
                    }
                }
            }
            if (ids.Count == 0)
            {
                MessageBox.Show("请选择一项送检");
                return;
            }
            else
            {
                foreach (ReceiptTicketItem i in ids)
                {
                    //PutawayTicketItem putawayTicketItem = (from pti in wmsEntities.PutawayTicketItem where pti.ID == i && pti.State != "已收货" && pti.State != "送检中" select pti).FirstOrDefault();
                    if (i == null)
                    {
                        MessageBox.Show(i + "不能添加此条目送检");
                    }
                    else
                    {
                        SubmissionTicketItem submissionTicketItem = ReceiptUtilities.ReceiptTicketItemToSubmissionTicketItem(i, this.submissionTicketID);
                        wmsEntities.SubmissionTicketItem.Add(submissionTicketItem);
                        i.State = "送检中";
                    }
                }
                new Thread(() =>
                {
                    try
                    {
                        wmsEntities.SaveChanges();
                        int count = wmsEntities.Database.SqlQuery <int>("SELECT COUNT(*) FROM ReceiptTicketItem WHERE State <> '送检中' AND ReceiptTicketID = @receiptTicketID", new SqlParameter("receiptTicketID", this.receiptTicketID)).FirstOrDefault();
                        if (count == 0)
                        {
                            wmsEntities.Database.ExecuteSqlCommand("UPDATE ReceiptTicket SET State = '送检中' WHERE ID = @receiptTicketID", new SqlParameter("receiptTicketID", this.receiptTicketID));
                        }
                        wmsEntities.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("无法连接到数据库,请查看网络连接!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                        return;
                    }
                    this.Invoke(new Action(() =>
                    {
                        this.Search();
                        CallBack();
                    }));
                    MessageBox.Show("添加成功");
                }).Start();
            }
        }
예제 #2
0
        private void Search(string key, string value)
        {
            this.lableStatus.Text = "搜索中...";

            new Thread(new ThreadStart(() =>
            {
                var wmsEntities = new WMSEntities();
                PutawayTicketView[] putawayTicketView = null;
                if (key == null || value == null)        //搜索所有
                {
                    try
                    {
                        putawayTicketView = wmsEntities.Database.SqlQuery <PutawayTicketView>("SELECT * FROM PutawayTicketView WHERE WarehouseID = @warehouseID AND ProjectID = @projectID ORDER BY ID DESC", new SqlParameter[] { new SqlParameter("warehouseID", this.warehouseID), new SqlParameter("projectID", this.projectID) }).ToArray();
                    }
                    catch
                    {
                        MessageBox.Show("无法连接到数据库,请查看网络连接!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    double tmp;
                    //if (Double.TryParse(value, out tmp) == false) //不是数字则加上单引号
                    //{
                    //    value = "'" + value + "'";
                    //}
                    try
                    {
                        putawayTicketView = wmsEntities.Database.SqlQuery <PutawayTicketView>(String.Format("SELECT * FROM PutawayTicketView WHERE {0} = @key AND WarehouseID = @warehouseID AND ProjectID = @projectID ORDER BY ID DESC", key), new SqlParameter[] { new SqlParameter("@key", value), new SqlParameter("@warehouseID", this.warehouseID), new SqlParameter("@projectID", this.projectID) }).ToArray();
                    }
                    catch (EntityException)
                    {
                        MessageBox.Show("查询的值不合法,请输入正确的值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("无法连接到数据库,请查看网络连接!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                        return;
                    }
                }
                this.reoGridControlUser.Invoke(new Action(() =>
                {
                    this.lableStatus.Text = "搜索完成";
                    var worksheet         = this.reoGridControlUser.Worksheets[0];
                    worksheet.DeleteRangeData(RangePosition.EntireRange);
                    int n = 0;
                    for (int i = 0; i < putawayTicketView.Length; i++)
                    {
                        PutawayTicketView curReceiptTicketView = putawayTicketView[i];
                        if (curReceiptTicketView.State == "作废")
                        {
                            continue;
                        }
                        object[] columns = Utilities.GetValuesByPropertieNames(curReceiptTicketView, (from kn in ReceiptMetaData.putawayTicketKeyName select kn.Key).ToArray());
                        for (int j = 0; j < worksheet.Columns; j++)
                        {
                            if (columns[j] == null)
                            {
                                worksheet[n, j] = columns[j];
                            }
                            else
                            {
                                worksheet[n, j] = columns[j].ToString();
                            }
                        }
                        n++;
                    }
                }));
                if (putawayTicketView.Length == 0)
                {
                    int m = ReceiptUtilities.GetFirstColumnIndex(ReceiptMetaData.submissionTicketKeyName);

                    //this.reoGridControl1.Worksheets[0][6, 8] = "32323";
                    this.reoGridControlUser.Worksheets[0][0, m] = "没有查询到符合条件的记录";
                }
            })).Start();
        }