示例#1
0
        static void SetLineColor(ListViewItem item, RequestItem request)
        {
            Color backColor = Color.White;
            Color foreColor = Color.Black;

            if (request.State == "sync")
            {
                backColor = Color.DarkGreen;
                foreColor = GetForeColor();
            }
            else if (request.State == "dontsync")
            {
                backColor = Color.DarkBlue;
                foreColor = GetForeColor();
            }
            else if (request.State != null && request.State.Contains("error"))
            {
                backColor = Color.DarkRed;
                foreColor = GetForeColor();
            }

            // TODO: Action为 "borrow" 的,LinkID 为空的,显示为黄色?

            item.BackColor = backColor;
            item.ForeColor = foreColor;

            Color GetForeColor()
            {
                if (request.Action == "borrow" && string.IsNullOrEmpty(request.LinkID) == true)
                {
                    return(Color.Yellow);
                }
                return(Color.White);
            }
        }
示例#2
0
        static void SetLine(ListViewItem item, RequestItem request)
        {
            // testing
            // request.State = null;

            string action_info = "";

            if (request.Action == "borrow")
            {
                var borrow_info = request.GetBorrowInfo();
                if (borrow_info != null)
                {
                    string returning_date = "";
                    if (string.IsNullOrEmpty(borrow_info.LatestReturnTime) == false)
                    {
                        if (DateTimeUtil.TryParseRfc1123DateTimeString(borrow_info.LatestReturnTime, out DateTime time) == true)
                        {
                            returning_date = time.ToString();
                        }
                        else
                        {
                            returning_date = $"时间字符串 '{borrow_info.LatestReturnTime}' 格式错误";
                        }
                    }
                    action_info = $"应还时间: {returning_date}";
                }
            }
            else
            {
                var return_info = request.GetReturnInfo();
                if (return_info != null &&
                    string.IsNullOrEmpty(return_info.OverdueString) == false)
                {
                    action_info = $"超期情况: {return_info.OverdueString}";
                }
            }

            ListViewUtil.ChangeItemText(item, COLUMN_ID, request.ID.ToString());
            ListViewUtil.ChangeItemText(item, COLUMN_PII, request.PII);
            ListViewUtil.ChangeItemText(item, COLUMN_BOOKTITLE, request.Entity?.Title);
            ListViewUtil.ChangeItemText(item, COLUMN_ACTION, request.Action);
            ListViewUtil.ChangeItemText(item, COLUMN_OPERATOR, request.OperatorID);
            ListViewUtil.ChangeItemText(item, COLUMN_NAME, request.Operator?.PatronName);

            ListViewUtil.ChangeItemText(item, COLUMN_OPERTIME, request.OperTime.ToString());
            ListViewUtil.ChangeItemText(item, COLUMN_STATE, request.State);
            ListViewUtil.ChangeItemText(item, COLUMN_ERRORCODE, request.SyncErrorCode);
            ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, request.SyncErrorInfo);
            ListViewUtil.ChangeItemText(item, COLUMN_SYNCCOUNT, request.SyncCount.ToString());
            ListViewUtil.ChangeItemText(item, COLUMN_SYNCOPERTIME, request.SyncOperTime.ToString());
            ListViewUtil.ChangeItemText(item, COLUMN_ACTIONINFO, action_info);

            ListViewUtil.ChangeItemText(item, COLUMN_LINKID, request.LinkID);
            ListViewUtil.ChangeItemText(item, COLUMN_BATCHNO, request.BatchNo);
            ListViewUtil.ChangeItemText(item, COLUMN_TOSHELFNO, request.CurrentShelfNo);
            ListViewUtil.ChangeItemText(item, COLUMN_TOLOCATION, request.Location);
            ListViewUtil.ChangeItemText(item, COLUMN_TRANSFERDIRECTION, request.TransferDirection);
            item.Tag = request;
            SetLineColor(item, request);
        }
示例#3
0
        // 刷新一行的显示
        void RefreshLine(int id, RequestItem request_item)
        {
            // 先定位到这一行
            ListViewItem item = ListViewUtil.FindItem(this.listView_records, id.ToString(), COLUMN_ID);

            if (item == null)
            {
                return;
            }
            SetLine(item, request_item);
        }
示例#4
0
        async void MenuItem_modifyState_Click(object sender, EventArgs e)
        {
            string strError = "";

            string new_state = InputDlg.GetInput(this, "修改状态", "新状态值", "dontsync", this.Font);

            if (new_state == null)
            {
                return;
            }
            try
            {
                SetInfoRequest request = new SetInfoRequest();
                request.Operation = "setHistory";
                request.Entities  = new List <Entity>();

                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    RequestItem tag = item.Tag as RequestItem;
                    tag.State = new_state;
                    Record record = new Record {
                        Data = JsonConvert.SerializeObject(tag)
                    };
                    request.Entities.Add(new Entity
                    {
                        Action    = "change:state",
                        NewRecord = record
                    });
                }

                var connection = await ConnectionPool.GetConnectionAsync(this.comboBox_query_myAccount.Text);

                var result = await connection.SetInfoAsyncLite(this.comboBox_query_shelfAccount.Text,
                                                               request,
                                                               TimeSpan.FromSeconds(10),
                                                               default);

                if (result.Value == -1)
                {
                    strError = result.ErrorInfo;
                    goto ERROR1;
                }

                // 报错
                List <string> errors          = new List <string>();
                List <string> succeed_records = new List <string>();
                if (result.Entities != null)
                {
                    foreach (var entity in result.Entities)
                    {
                        if (string.IsNullOrEmpty(entity.ErrorInfo) == false)
                        {
                            errors.Add(entity.ErrorInfo);
                        }
                        else
                        {
                            succeed_records.Add(entity.NewRecord?.Data);
                        }
                    }
                }

                // 刷新成功修改了的行
                foreach (var record in succeed_records)
                {
                    if (string.IsNullOrEmpty(record))
                    {
                        continue;
                    }
                    var item = JsonConvert.DeserializeObject <RequestItem>(record);
                    RefreshLine(item.ID, item);
                }

                if (errors.Count > 0)
                {
                    MessageDialog.Show(this, $"出错:\r\n{StringUtil.MakePathList(errors, "\r\n")}");
                }
                return;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }

ERROR1:
            MessageBox.Show(this, strError);
        }