Beispiel #1
0
        private void FuncationRegiste()  //注册控件相关事件
        {
            #region 窗体加载事件
            Load += delegate
            {
                dgv_table.ReadOnly = false;
                foreach (DataGridViewColumn dgvc in dgv_table.Columns)
                {
                    if (dgvc == drchk_check)
                    {
                        continue;
                    }
                    dgvc.ReadOnly = true;
                }
            };
            #endregion

            #region 添加按钮事件
            AddEvent += delegate
            {
                var uc = new UCMaintainThreeGuarantyEdit {
                    UCForm = this, windowStatus = WindowStatus.Add
                };
                uc.addUserControl(uc, "三包服务单-新增", "UCMaintainThreeGuarantyAdd", Tag.ToString(), Name);
            };
            #endregion

            #region  制按钮事件
            CopyEvent += delegate
            {
                var tgid     = "";
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                var uc = new UCMaintainThreeGuarantyEdit {
                    UCForm = this, TgId = tgid, windowStatus = WindowStatus.Copy
                };
                uc.addUserControl(uc, "三包服务单-复制", "UCMaintainThreeGuarantyCopy", Tag.ToString(), Name);
            };
            #endregion

            #region 编辑按钮事件
            EditEvent += delegate
            {
                var tgid     = "";
                var dataView = GetCheckRows();
                if (dataView != null && dataView.Count > 0)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                var uc = new UCMaintainThreeGuarantyEdit {
                    UCForm = this, TgId = tgid, windowStatus = WindowStatus.Edit
                };
                uc.addUserControl(uc, "三包服务单-编辑", "UCMaintainThreeGuarantyEdit", Tag.ToString(), Name);
            };
            #endregion

            #region  除按钮事件
            DeleteEvent += delegate
            {
                var selectedRows = GetCheckRows();
                if (MessageBoxEx.Show("确认要删除吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var comField = new Dictionary <string, string> {
                    { "enable_flag", "0" }
                };
                var flag = DBHelper.BatchUpdateDataByIn("删除三包服务单", TableName, comField, "tg_id", selectedRows.ToArray());
                if (flag)
                {
                    BindPageData();
                    if (dgv_table.Rows.Count > 0)
                    {
                        dgv_table.CurrentCell = dgv_table.Rows[0].Cells[0];
                    }
                    MessageBoxEx.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBoxEx.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 激活作废按钮事件
            InvalidOrActivationEvent += delegate
            {
                if (MessageBoxEx.Show("确认要" + btnActivation.Caption + "吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var selectedRows = GetCheckRows();
                var flag         = false;
                foreach (var selectedRow in selectedRows)
                {
                    var dvt       = DBHelper.GetTable("获得三包服务单前一个状态", "tb_maintain_three_guaranty_BackUp", "info_status", "tg_id='" + selectedRow + "'", "", "order by Record_id_UpdateTime desc");
                    var oldStatus = DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG;
                    if (dvt.Rows.Count > 0)
                    {
                        var dr = dvt.Rows[0];
                        oldStatus = CommonCtrl.IsNullToString(dr["info_status"]);
                    }
                    flag = DBHelper.Submit_AddOrEdit("作废或激活三包服务单", TableName, "tg_id", selectedRow,
                                                     new Dictionary <string, string>
                    {
                        {
                            "info_status", btnActivation.Caption == "作废"  ? DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF : oldStatus
                        },
                        {
                            "update_by", GlobalStaticObj.UserID
                        },
                        {
                            "update_name", GlobalStaticObj.UserName
                        },
                        {
                            "update_time", Common.LocalDateTimeToUtcLong(GlobalStaticObj.CurrentDateTime).ToString()
                        }
                    });
                }
                if (flag)
                {
                    BindPageData();
                    if (dgv_table.Rows.Count > 0)
                    {
                        dgv_table.CurrentCell = dgv_table.Rows[0].Cells[0];
                    }
                    MessageBoxEx.Show(btnActivation.Caption + "成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBoxEx.Show(btnActivation.Caption + "失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 提交按钮事件
            btnSubmit.Click += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    var cg = 0;
                    var sb = 0;
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        var tgid      = CommonCtrl.IsNullToString(rowView["tg_id"]);
                        var status    = CommonCtrl.IsNullToString(rowView["info_status"]);
                        var serviceNo = CommonCtrl.IsNullToString(rowView["service_no"]);
                        var dicFields = new Dictionary <string, string>();
                        dicFields.Add("info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ);
                        if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG && String.IsNullOrEmpty(serviceNo))
                        {
                            dicFields.Add("service_no", CommonUtility.GetNewNo(DataSources.EnumProjectType.ThreeGuarantyService));
                        }
                        var result = DBHelper.Submit_AddOrEdit("三包服务单提交", "tb_maintain_three_guaranty", "tg_id", tgid, dicFields);
                        if (result)
                        {
                            cg++;
                        }
                        else
                        {
                            sb++;
                        }
                    }
                    if (cg != 0)
                    {
                        BindPageData();
                    }
                    var msg = "三包服务单提交操作成功";
                    if (sb != 0 && cg == 0)
                    {
                        msg = "三包服务单提交失败";
                    }
                    else if (cg != 0 && sb == 0)
                    {
                        msg = "三包服务单提交成功";
                    }
                    else
                    {
                        msg += ",但存在" + sb + "条提交失败的单据";
                    }
                    MessageBoxEx.Show(msg, "操作提示");
                }
                else
                {
                    MessageBoxEx.Show("无法获取到选择的数据,请选择需要操作的数据", "操作提示");
                }
            };
            #endregion

            #region 审核按钮事件
            VerifyEvent += delegate
            {
                var tgid     = "";
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                var form = new UCMaintainThreeGuarantyVerify(tgid);
                form.UcForm = this;
                var result = form.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    BindPageData();
                }
            };
            #endregion

            #region  报厂家/总公司按钮事件
            CommitEvent += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                if (MessageBoxEx.Show("确认要将三包服务单上报宇通吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var tgid     = "";
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                else
                {
                    return;
                }
                var resultStr = Submit2Company(tgid, "100000001");
                MessageBoxEx.Show(String.IsNullOrEmpty(resultStr) ? "三包服务单上报厂家成功!" : "三包服务单上报厂家失败!", "操作提示");
                BindPageData();
            };
            #endregion

            #region 撤销按钮事件
            RevokeEvent += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                if (MessageBoxEx.Show("确认要撤销已提交的单据吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var selectedRowsYt    = GetCheckRowsByYt();
                var selectedRows      = GetCheckRows();
                var canSubmit2Company = false;
                if (selectedRowsYt != null && selectedRowsYt.Count > 0)
                {
                    var orderStatus = DBHelper.GetSingleValue("获取三包服务单状态", TableName, "info_status", String.Format("tg_id = '{0}'", selectedRows[0]), "");
                    if (orderStatus == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ)
                    {
                        bool flag = DBHelper.Submit_AddOrEdit("撤销三包服务单", "tb_maintain_three_guaranty", "tg_id", selectedRows[0],
                                                              new Dictionary <string, string>
                        {
                            {
                                "info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG
                            }
                        });
                        if (flag)
                        {
                            BindPageData("enable_flag = '1'");
                            MessageBoxEx.Show("撤销成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBoxEx.Show("撤销失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else if (orderStatus == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHTG)
                    {
                        var resultStr = DBHelper.WebServHandlerByObj("查询三包服务单状态", EnumWebServFunName.SearchOrderStatus, selectedRowsYt[0]);
                        if (resultStr == "100000001" || String.IsNullOrEmpty(resultStr))
                        {
                            Submit2Company(selectedRows[0], selectedRowsYt[0], "100000002");
                            var flag = DBHelper.Submit_AddOrEdit("撤销三包服务单", "tb_maintain_three_guaranty", "tg_id", selectedRows[0],
                                                                 new Dictionary <string, string>
                            {
                                {
                                    "info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ
                                }
                            });
                            if (flag)
                            {
                                BindPageData("enable_flag = '1'");
                                MessageBoxEx.Show("撤销成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBoxEx.Show("撤销失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            MessageBoxEx.Show("此单据已被引用,无法撤销!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBoxEx.Show("请选择需要撤销的单据信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 导入按钮事件
            ImportEvent += delegate
            {
                //var callbackImport = new UCRepairCallbackImport();
                //callbackImport.Fetchuc = this;
                //callbackImport.strTag = "1";
                //callbackImport.ShowDialog();
            };
            #endregion

            #region 查询按钮事件
            btn_query.Click += delegate
            {
                BindPageData();
            };
            #endregion

            #region 清除按钮事件
            btn_clear.Click += delegate
            {
                txt_service_no.Caption              = txt_service_no_yt.Caption = String.Empty;
                txt_vehicle_no.Text                 = String.Empty;
                txt_depot_no.Caption                = String.Empty;
                txt_customer_code.Text              = String.Empty;
                txt_customer_name.Caption           = String.Empty;
                cbo_bill_type_yt.SelectedIndex      = 0;
                cbo_info_status.SelectedIndex       = 0;
                cbo_approve_status_yt.SelectedIndex = 0;
                dtp_repairs_time_s.Value            = DateTime.Now.AddMonths(-1);
                dtp_repairs_time_e.Value            = DateTime.Now.AddDays(1);
                dtp_approval_date_s.Value           = DateTime.Now.AddMonths(-1);
                dtp_approval_date_e.Value           = DateTime.Now.AddDays(1);
            };
            #endregion

            #region 数据翻页
            pageQ.PageIndexChanged += delegate
            {
                BindPageData();
            };
            #endregion

            #region 数据表数据选择
            dgv_table.CellDoubleClick += delegate(object sender, DataGridViewCellEventArgs args)
            {
                if (args.RowIndex < 0)
                {
                    return;
                }
                var tgid = dgv_table.Rows[args.RowIndex].Cells["drtxt_tg_id"].Value.ToString();
                if (String.IsNullOrEmpty(tgid))
                {
                    MessageBoxEx.Show("无效的结算单信息", "操作提示");
                    return;
                }
                var uc = new UCMaintainThreeGuarantyViewDetail {
                    TgId = tgid, UCForm = this
                };
                uc.addUserControl(uc, "三包服务单-详细信息", "UCMaintainThreeGuarantyViewDetail" + uc.TgId, Tag.ToString(), Name);
            };
            #endregion

            #region 数据表格单元格数据转换
            dgv_table.CellFormatting += (sender, args) => ConvertDataGridColumnsData(args);
            #endregion

            #region 根据选择的数据判断功能按钮的显示状态
            dgv_table.CellMouseUp += delegate
            {
                var dataView  = GetSelectedRowData();
                var listField = GetCheckRows();
                if (dataView == null || listField.Count == 0)
                {
                    //btnAdd, btnCopy, btnDelete, btnInvalidOrActivation, btnVerify, btnSave, btnCommit, btnCancel, btnExport, btnImport, btn_Revoke, btnView, btnPrint, btnSet
                    btnCopy.Enabled       = false;
                    btnEdit.Enabled       = false;
                    btnDelete.Enabled     = false;
                    btnActivation.Enabled = false;
                    btnCommit.Enabled     = btnSubmit.Enabled = btnVerify.Enabled = false;
                }
                else
                {
                    var cg    = 0;
                    var shwtg = 0;
                    var shtg  = 0;
                    var ytj   = 0;
                    var yzf   = 0;
                    foreach (DataRowView drv in dataView)
                    {
                        var status = drv["info_status"].ToString();
                        if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG)
                        {
                            cg++;
                        }
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHWTG)
                        {
                            shwtg++;
                        }
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHTG)
                        {
                            shtg++;
                        }
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ)
                        {
                            ytj++;
                        }
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF)
                        {
                            yzf++;
                        }
                    }

                    #region 编辑
                    if (listField.Count == 1 && (cg + shwtg) == listField.Count)
                    {
                        btnEdit.Enabled = true;
                    }
                    else
                    {
                        btnEdit.Enabled = false;
                    }
                    //提交
                    if (listField.Count >= 1 && (cg + shwtg) == listField.Count)
                    {
                        btnSubmit.Enabled = true;
                    }
                    else
                    {
                        btnSubmit.Enabled = false;
                    }
                    #endregion

                    #region  制
                    if (listField.Count == 1)
                    {
                        btnCopy.Enabled = true;
                    }
                    #endregion

                    #region  除
                    if (listField.Count >= 1 && (cg + shwtg + yzf) == listField.Count)
                    {
                        btnDelete.Enabled = true;
                    }
                    else
                    {
                        btnDelete.Enabled = false;
                    }
                    #endregion

                    #region 作废/激活
                    var zf = 0;
                    var jh = 0;
                    if (listField.Count == 1)
                    {
                        foreach (DataRowView rowView in dataView) //作废/激活
                        {
                            if (rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG ||
                                rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHWTG)
                            {
                                zf++;
                            }
                            else if (rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF)
                            {
                                jh++;
                            }
                        }
                        if (zf == 0 && jh != 0)
                        {
                            btnActivation.Enabled = true;
                            btnActivation.Caption = "激活";
                            btnActivation.Width   = 60;
                        }
                        else if (zf != 0 && jh == 0)
                        {
                            btnActivation.Enabled = true;
                            btnActivation.Caption = "作废";
                            btnActivation.Width   = 60;
                        }
                        else
                        {
                            btnActivation.Enabled = false;
                            btnActivation.Caption = "作废/激活";
                            btnActivation.Width   = 90;
                        }
                    }
                    else
                    {
                        btnActivation.Enabled = false;
                        btnActivation.Caption = "作废/激活";
                        btnActivation.Width   = 90;
                    }
                    #endregion

                    #region 审核
                    if (UIAssistants.ThreeServiceAudit && listField.Count == 1)
                    {
                        btnVerify.Enabled = ytj == listField.Count;
                    }
                    else
                    {
                        btnVerify.Enabled = false;
                    }
                    #endregion

                    #region  报厂家/总公司

                    if (UIAssistants.ThreeServiceAudit)
                    {
                        if (listField.Count == 1 && listField.Count == shtg)
                        {
                            btnCommit.Enabled = true;
                        }
                        else
                        {
                            btnCommit.Enabled = false;
                        }
                    }
                    else
                    {
                        if (listField.Count == 1 && listField.Count == ytj)
                        {
                            btnCommit.Enabled = true;
                        }
                        else
                        {
                            btnCommit.Enabled = false;
                        }
                    }
                    #endregion

                    #region 撤销
                    if (listField.Count == 1 && cg == 0)
                    {
                        btnRevoke.Enabled = true;
                    }
                    else
                    {
                        btnRevoke.Enabled = false;
                    }
                    #endregion
                }
            };
            #endregion
        }
        private void FuncationRegiste()  //注册控件相关事件
        {
            #region 窗体加载事件
            Load += delegate
            {
                dgv_table.ReadOnly = false;
                foreach (DataGridViewColumn dgvc in dgv_table.Columns)
                {
                    if (dgvc == drchk_check)
                    {
                        continue;
                    }
                    dgvc.ReadOnly = true;
                }
            };
            #endregion

            #region 添加按钮事件
            AddEvent += delegate
            {
                var uc = new UCMaintainThreeGuarantyEdit { UCForm = this, windowStatus = WindowStatus.Add };
                uc.addUserControl(uc, "三包服务单-新增", "UCMaintainThreeGuarantyAdd", Tag.ToString(), Name);
            };
            #endregion

            #region 复制按钮事件
            CopyEvent += delegate
            {
                var tgid = "";
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                var uc = new UCMaintainThreeGuarantyEdit { UCForm = this, TgId = tgid, windowStatus = WindowStatus.Copy };
                uc.addUserControl(uc, "三包服务单-复制", "UCMaintainThreeGuarantyCopy", Tag.ToString(), Name);
            };
            #endregion

            #region 编辑按钮事件
            EditEvent += delegate
            {
                var tgid = "";
                var dataView = GetCheckRows();
                if (dataView != null && dataView.Count > 0)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                var uc = new UCMaintainThreeGuarantyEdit { UCForm = this, TgId = tgid, windowStatus = WindowStatus.Edit };
                uc.addUserControl(uc, "三包服务单-编辑", "UCMaintainThreeGuarantyEdit", Tag.ToString(), Name);
            };
            #endregion

            #region 删除按钮事件
            DeleteEvent += delegate
            {
                var selectedRows = GetCheckRows();
                if (MessageBoxEx.Show("确认要删除吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var comField = new Dictionary<string, string> {{"enable_flag", "0"}};
                var flag = DBHelper.BatchUpdateDataByIn("删除三包服务单", TableName, comField, "tg_id", selectedRows.ToArray());
                if (flag)
                {
                    BindPageData();
                    if (dgv_table.Rows.Count > 0)
                    {
                        dgv_table.CurrentCell = dgv_table.Rows[0].Cells[0];
                    }
                    MessageBoxEx.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBoxEx.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 激活作废按钮事件
            InvalidOrActivationEvent += delegate
            {
                if (MessageBoxEx.Show("确认要" + btnActivation.Caption + "吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var selectedRows = GetCheckRows();
                var flag = false;
                foreach (var selectedRow in selectedRows)
                {
                    var dvt = DBHelper.GetTable("获得三包服务单前一个状态", "tb_maintain_three_guaranty_BackUp", "info_status", "tg_id='" + selectedRow + "'", "", "order by Record_id_UpdateTime desc");
                    var oldStatus = DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG;
                    if (dvt.Rows.Count > 0)
                    {
                        var dr = dvt.Rows[0];
                        oldStatus = CommonCtrl.IsNullToString(dr["info_status"]);
                    }
                    flag = DBHelper.Submit_AddOrEdit("作废或激活三包服务单", TableName, "tg_id", selectedRow,
                        new Dictionary<string, string>
                        {
                            {
                                "info_status",  btnActivation.Caption == "作废"  ? DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF : oldStatus
                            },
                            {
                                "update_by", GlobalStaticObj.UserID
                            },
                            {
                                "update_name", GlobalStaticObj.UserName
                            },
                            {
                                "update_time", Common.LocalDateTimeToUtcLong(GlobalStaticObj.CurrentDateTime).ToString()
                            }
                        });
                }
                if (flag)
                {
                    BindPageData();
                    if (dgv_table.Rows.Count > 0)
                    {
                        dgv_table.CurrentCell = dgv_table.Rows[0].Cells[0];
                    }
                    MessageBoxEx.Show(btnActivation.Caption + "成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBoxEx.Show(btnActivation.Caption + "失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 提交按钮事件
            btnSubmit.Click += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    var cg = 0;
                    var sb = 0;
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        var tgid = CommonCtrl.IsNullToString(rowView["tg_id"]);
                        var status = CommonCtrl.IsNullToString(rowView["info_status"]);
                        var serviceNo = CommonCtrl.IsNullToString(rowView["service_no"]);
                        var dicFields = new Dictionary<string, string>();
                        dicFields.Add("info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ);
                        if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG && String.IsNullOrEmpty(serviceNo))
                            dicFields.Add("service_no", CommonUtility.GetNewNo(DataSources.EnumProjectType.ThreeGuarantyService));
                        var result = DBHelper.Submit_AddOrEdit("三包服务单提交", "tb_maintain_three_guaranty", "tg_id", tgid, dicFields);
                        if (result) cg++;
                        else sb++;
                    }
                    if (cg != 0)
                    {
                        BindPageData();
                    }
                    var msg = "三包服务单提交操作成功";
                    if (sb != 0 && cg == 0)
                    {
                        msg = "三包服务单提交失败";
                    }
                    else if (cg != 0 && sb == 0)
                    {
                        msg = "三包服务单提交成功";
                    }
                    else
                    {
                        msg += ",但存在"+ sb +"条提交失败的单据";
                    }
                    MessageBoxEx.Show(msg, "操作提示");
                }
                else
                {
                    MessageBoxEx.Show("无法获取到选择的数据,请选择需要操作的数据", "操作提示");
                }
            };
            #endregion

            #region 审核按钮事件
            VerifyEvent += delegate
            {
                var tgid = "";
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                var form = new UCMaintainThreeGuarantyVerify(tgid);
                form.UcForm = this;
                var result = form.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    BindPageData();
                }
            };
            #endregion

            #region 上报厂家/总公司按钮事件
            CommitEvent += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                if (MessageBoxEx.Show("确认要将三包服务单上报宇通吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var tgid = "";
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                else
                {
                    return;
                }
                var resultStr = Submit2Company(tgid, "100000001");
                MessageBoxEx.Show(String.IsNullOrEmpty(resultStr) ? "三包服务单上报厂家成功!" : "三包服务单上报厂家失败!", "操作提示");
                BindPageData();
            };
            #endregion

            #region 撤销按钮事件
            RevokeEvent += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                if (MessageBoxEx.Show("确认要撤销已提交的单据吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var selectedRowsYt = GetCheckRowsByYt();
                var selectedRows = GetCheckRows();
                var canSubmit2Company = false;
                if (selectedRowsYt != null && selectedRowsYt.Count > 0)
                {
                    var orderStatus = DBHelper.GetSingleValue("获取三包服务单状态", TableName, "info_status", String.Format("tg_id = '{0}'", selectedRows[0]), "");
                    if (orderStatus == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ)
                    {
                        bool flag = DBHelper.Submit_AddOrEdit("撤销三包服务单", "tb_maintain_three_guaranty", "tg_id", selectedRows[0],
                            new Dictionary<string, string>
                            {
                                {
                                    "info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG
                                 }
                            });
                        if (flag)
                        {
                            BindPageData("enable_flag = '1'");
                            MessageBoxEx.Show("撤销成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBoxEx.Show("撤销失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else if (orderStatus == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHTG)
                    {
                        var resultStr = DBHelper.WebServHandlerByObj("查询三包服务单状态", EnumWebServFunName.SearchOrderStatus, selectedRowsYt[0]);
                        if (resultStr == "100000001" || String.IsNullOrEmpty(resultStr))
                        {
                            Submit2Company(selectedRows[0], selectedRowsYt[0], "100000002");
                            var flag = DBHelper.Submit_AddOrEdit("撤销三包服务单", "tb_maintain_three_guaranty", "tg_id", selectedRows[0],
                            new Dictionary<string, string>
                            {
                                {
                                    "info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ
                                }
                            });
                            if (flag)
                            {
                                BindPageData("enable_flag = '1'");
                                MessageBoxEx.Show("撤销成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBoxEx.Show("撤销失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            MessageBoxEx.Show("此单据已被引用,无法撤销!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBoxEx.Show("请选择需要撤销的单据信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 导入按钮事件
            ImportEvent += delegate
            {
                //var callbackImport = new UCRepairCallbackImport();
                //callbackImport.Fetchuc = this;
                //callbackImport.strTag = "1";
                //callbackImport.ShowDialog();
            };
            #endregion

            #region 查询按钮事件
            btn_query.Click += delegate
            {
                BindPageData();
            };
            #endregion

            #region 清除按钮事件
            btn_clear.Click += delegate
            {
                txt_service_no.Caption = txt_service_no_yt.Caption = String.Empty;
                txt_vehicle_no.Text = String.Empty;
                txt_depot_no.Caption = String.Empty;
                txt_customer_code.Text = String.Empty;
                txt_customer_name.Caption = String.Empty;
                cbo_bill_type_yt.SelectedIndex = 0;
                cbo_info_status.SelectedIndex = 0;
                cbo_approve_status_yt.SelectedIndex = 0;
                dtp_repairs_time_s.Value = DateTime.Now.AddMonths(-1);
                dtp_repairs_time_e.Value = DateTime.Now.AddDays(1);
                dtp_approval_date_s.Value = DateTime.Now.AddMonths(-1);
                dtp_approval_date_e.Value = DateTime.Now.AddDays(1);
            };
            #endregion

            #region 数据翻页
            pageQ.PageIndexChanged += delegate
            {
                BindPageData();
            };
            #endregion

            #region 数据表数据选择
            dgv_table.CellDoubleClick += delegate(object sender, DataGridViewCellEventArgs args)
            {

                if (args.RowIndex < 0) return;
                var tgid = dgv_table.Rows[args.RowIndex].Cells["drtxt_tg_id"].Value.ToString();
                if (String.IsNullOrEmpty(tgid))
                {
                    MessageBoxEx.Show("无效的结算单信息", "操作提示");
                    return;
                }
                var uc = new UCMaintainThreeGuarantyViewDetail {TgId = tgid, UCForm = this};
                uc.addUserControl(uc, "三包服务单-详细信息", "UCMaintainThreeGuarantyViewDetail" + uc.TgId, Tag.ToString(), Name);
            };
            #endregion

            #region 数据表格单元格数据转换
            dgv_table.CellFormatting += (sender, args) => ConvertDataGridColumnsData(args);
            #endregion

            #region 根据选择的数据判断功能按钮的显示状态
            dgv_table.CellMouseUp += delegate
            {
                var dataView = GetSelectedRowData();
                var listField = GetCheckRows();
                if (dataView == null || listField.Count == 0)
                {
                    //btnAdd, btnCopy, btnDelete, btnInvalidOrActivation, btnVerify, btnSave, btnCommit, btnCancel, btnExport, btnImport, btn_Revoke, btnView, btnPrint, btnSet
                    btnCopy.Enabled = false;
                    btnEdit.Enabled = false;
                    btnDelete.Enabled = false;
                    btnActivation.Enabled = false;
                    btnCommit.Enabled = btnSubmit.Enabled = btnVerify.Enabled = false;
                }
                else
                {
                    var cg = 0;
                    var shwtg = 0;
                    var shtg = 0;
                    var ytj = 0;
                    var yzf = 0;
                    foreach (DataRowView drv in dataView)
                    {
                        var status = drv["info_status"].ToString();
                        if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG) cg++;
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHWTG) shwtg++;
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHTG) shtg++;
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ) ytj++;
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF) yzf++;
                    }

                    #region 编辑
                    if (listField.Count == 1 && (cg+shwtg) == listField.Count)
                    {
                        btnEdit.Enabled = true;
                    }
                    else
                    {
                        btnEdit.Enabled = false;
                    }
                    //提交
                    if (listField.Count >= 1 && (cg + shwtg) == listField.Count)
                    {
                        btnSubmit.Enabled = true;
                    }
                    else
                    {
                        btnSubmit.Enabled = false;
                    }
                    #endregion

                    #region 复制
                    if (listField.Count == 1 )
                    {
                        btnCopy.Enabled = true;
                    }
                    #endregion

                    #region 删除
                    if (listField.Count >= 1 && (cg+shwtg+yzf) == listField.Count)
                    {
                        btnDelete.Enabled = true;
                    }
                    else
                    {
                        btnDelete.Enabled = false;
                    }
                    #endregion

                    #region 作废/激活
                    var zf = 0;
                    var jh = 0;
                    if (listField.Count == 1)
                    {
                        foreach (DataRowView rowView in dataView) //作废/激活
                        {
                            if (rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG ||
                                rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHWTG)
                            {
                                zf ++;
                            }
                            else if (rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF)
                            {
                                jh++;
                            }
                        }
                        if (zf == 0 && jh != 0)
                        {
                            btnActivation.Enabled = true;
                            btnActivation.Caption = "激活";
                            btnActivation.Width = 60;
                        }
                        else if (zf != 0 && jh == 0)
                        {
                            btnActivation.Enabled = true;
                            btnActivation.Caption = "作废";
                            btnActivation.Width = 60;
                        }
                        else
                        {
                            btnActivation.Enabled = false;
                            btnActivation.Caption = "作废/激活";
                            btnActivation.Width = 90;
                        }
                    }
                    else
                    {
                        btnActivation.Enabled = false;
                        btnActivation.Caption = "作废/激活";
                        btnActivation.Width = 90;
                    }
                    #endregion

                    #region 审核
                    if (UIAssistants.ThreeServiceAudit && listField.Count == 1)
                    {
                        btnVerify.Enabled = ytj == listField.Count;
                    }
                    else
                    {
                        btnVerify.Enabled = false;
                    }
                    #endregion

                    #region 上报厂家/总公司

                    if (UIAssistants.ThreeServiceAudit)
                    {
                        if (listField.Count == 1 && listField.Count == shtg)
                        {
                            btnCommit.Enabled = true;
                        }
                        else
                        {
                            btnCommit.Enabled = false;
                        }
                    }
                    else
                    {
                        if (listField.Count == 1 && listField.Count == ytj)
                        {
                            btnCommit.Enabled = true;
                        }
                        else
                        {
                            btnCommit.Enabled = false;
                        }
                    }
                    #endregion

                    #region 撤销
                    if (listField.Count == 1 && cg == 0)
                    {
                        btnRevoke.Enabled = true;
                    }
                    else
                    {
                        btnRevoke.Enabled = false;
                    }
                    #endregion
                }
            };
            #endregion
        }
        private void FuncationRegiste()  //注册控件相关事件
        {
            #region 窗体加载事件
            Load += delegate
            {
                dgv_table.ReadOnly = false;
                foreach (DataGridViewColumn dgvc in dgv_table.Columns)
                {
                    if (dgvc == drchk_check)
                    {
                        continue;
                    }
                    dgvc.ReadOnly = true;
                }
            };
            #endregion

            #region 添加按钮事件
            AddEvent += delegate
            {
                //var uc = new UCMaintainThreeGuarantyAddOrEdit();
                //uc.addUserControl(uc, "三包服务单-新增", "UCMaintainThreeGuarantyAdd", Tag.ToString(), Name);

                var uc = new UCMaintainThreeGuarantyEdit { UCForm = this, windowStatus = WindowStatus.Add };
                uc.addUserControl(uc, "三包服务单-新增", "UCMaintainThreeGuarantyAdd", Tag.ToString(), Name);
            };
            #endregion

            #region 复制按钮事件
            CopyEvent += delegate
            {
                var tgid = "";
                var dataView = GetCheckRows();
                if (dataView != null && dataView.Count > 0)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }

                    var uc = new UCMaintainThreeGuarantyEdit { UCForm = this, TgId = tgid, windowStatus = WindowStatus.Copy };
                    uc.addUserControl(uc, "三包服务单-复制", "UCMaintainThreeGuarantyCopy", Tag.ToString(), Name);
                }
                else
                {
                    MessageBoxEx.Show("请选择需要操作的数据!", "操作提示");
                }
            };
            #endregion

            #region 编辑按钮事件
            EditEvent += delegate
            {
                var tgid = "";
                var dataView = GetCheckRows();
                if (dataView != null && dataView.Count > 0)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }

                    var uc = new UCMaintainThreeGuarantyEdit { UCForm = this, TgId = tgid, windowStatus = WindowStatus.Edit };
                    uc.addUserControl(uc, "三包服务单-编辑", "UCMaintainThreeGuarantyEdit", Tag.ToString(), Name);
                }
                else
                {
                    MessageBoxEx.Show("请选择需要操作的数据!", "操作提示");
                }
            };
            #endregion

            #region 删除按钮事件
            DeleteEvent += delegate
            {
                var selectedRows = GetCheckRows();
                if (MessageBoxEx.Show("确认要删除吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var comField = new Dictionary<string, string> {{"enable_flag", "0"}};
                var flag = DBHelper.BatchUpdateDataByIn("删除三包服务单", TableName, comField, "tg_id", selectedRows.ToArray());
                if (flag)
                {
                    BindPageData();
                    if (dgv_table.Rows.Count > 0)
                    {
                        dgv_table.CurrentCell = dgv_table.Rows[0].Cells[0];
                    }
                    MessageBoxEx.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBoxEx.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 激活作废按钮事件
            InvalidOrActivationEvent += delegate
            {
                if (MessageBoxEx.Show("确认要" + btnActivation.Caption + "吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var selectedRows = GetCheckRows();
                var flag = false;
                foreach (var selectedRow in selectedRows)
                {
                    var dvt = DBHelper.GetTable("获得三包服务单前一个状态", "tb_maintain_three_guaranty_BackUp", "info_status", "tg_id='" + selectedRow + "'", "", "order by Record_id_UpdateTime desc");
                    var oldStatus = DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG;
                    if (dvt.Rows.Count > 0)
                    {
                        var dr = dvt.Rows[0];
                        oldStatus = CommonCtrl.IsNullToString(dr["info_status"]);
                    }
                    flag = DBHelper.Submit_AddOrEdit("作废或激活三包服务单", TableName, "tg_id", selectedRow,
                        new Dictionary<string, string>
                        {
                            {
                                "info_status",  btnActivation.Caption == "作废"  ? DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF : oldStatus
                            },
                            {
                                "update_by", GlobalStaticObj.UserID
                            },
                            {
                                "update_name", GlobalStaticObj.UserName
                            },
                            {
                                "update_time", Common.LocalDateTimeToUtcLong(GlobalStaticObj.CurrentDateTime).ToString()
                            }
                        });
                }
                if (flag)
                {
                    BindPageData();
                    if (dgv_table.Rows.Count > 0)
                    {
                        dgv_table.CurrentCell = dgv_table.Rows[0].Cells[0];
                    }
                    MessageBoxEx.Show(btnActivation.Caption + "成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBoxEx.Show(btnActivation.Caption + "失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 提交按钮事件
            btnSubmit.Click += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    var cg = 0;
                    var sb = 0;
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        var tgid = CommonCtrl.IsNullToString(rowView["tg_id"]);
                        var preId = CommonCtrl.IsNullToString(rowView["pre_order_id"]);
                        var fullCount = DBHelper.GetSingleValue("", "tr_order_relation", "count(*)",
                            "pre_order_id = '" + preId + "' and post_order_name = 'tb_maintain_three_guaranty' and post_item_order_id is null",
                            "");
                        if (Convert.ToInt32(fullCount) > 0)
                        {
                            MessageBoxEx.Show("前置单据已经被引用,无法再次引用!");
                            return;
                        }
                        var dmtCheck = DBHelper.GetTable("维修用料数据", "tb_maintain_three_guaranty_material_detail", "*", string.Format(" tg_id='{0}'", tgid), "", "");
                        if (dmtCheck.Rows.Count > 0)
                        {
                            foreach (DataRow dataRowView in dmtCheck.Rows)
                            {
                                var materialCount = DBHelper.GetSingleValue("", "tr_order_relation", "count(*)", "pre_order_id = '" + preId + "' and post_item_order_id = '" + CommonCtrl.IsNullToString(dataRowView["pre_order_id"]) + "'","");
                                if (Convert.ToInt32(materialCount) > 0)
                                {
                                    if (Convert.ToInt32(fullCount) > 0)
                                    {
                                        MessageBoxEx.Show("前置单据的维修用料已经被引用,无法再次引用!");
                                        return;
                                    }
                                }
                            }
                        }
                        var dptCheck = DBHelper.GetTable("维修项目数据", "tb_maintain_three_guaranty_item", "*", string.Format(" tg_id='{0}'", tgid), "", "");
                        if (dptCheck.Rows.Count > 0)
                        {
                            foreach (DataRow dataRowView in dptCheck.Rows)
                            {
                                var materialCount = DBHelper.GetSingleValue("", "tr_order_relation", "count(*)", "pre_order_id = '" + preId + "' and post_item_order_id = '" + CommonCtrl.IsNullToString(dataRowView["pre_order_id"]) + "'", "");
                                if (Convert.ToInt32(materialCount) > 0)
                                {
                                    if (Convert.ToInt32(fullCount) > 0)
                                    {
                                        MessageBoxEx.Show("前置单据的维修项目已经被引用,无法再次引用!");
                                        return;
                                    }
                                }
                            }
                        }
                        var status = CommonCtrl.IsNullToString(rowView["info_status"]);
                        var serviceNo = CommonCtrl.IsNullToString(rowView["service_no"]);
                        var dicFields = new Dictionary<string, string>();
                        dicFields.Add("info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ);
                        if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG && String.IsNullOrEmpty(serviceNo))
                            dicFields.Add("service_no", CommonUtility.GetNewNo(DataSources.EnumProjectType.ThreeGuarantyService));
                        var result = DBHelper.Submit_AddOrEdit("三包服务单提交", "tb_maintain_three_guaranty", "tg_id", tgid, dicFields);
                        if (result)
                        {
                            cg++;
                            
                            //维修用料
                            var dmt = DBHelper.GetTable("维修用料数据", "tb_maintain_three_guaranty_material_detail", "*", string.Format(" tg_id='{0}'", tgid), "", "");
                            if (dmt.Rows.Count > 0)
                            {
                                foreach (DataRow dataRowView in dmt.Rows)
                                {
                                    var dmtFields = new Dictionary<String, String>();
                                    dmtFields.Add("order_relation_id", Guid.NewGuid().ToString());

                                    dmtFields.Add("pre_order_id", preId);
                                    dmtFields.Add("pre_order_name", "tb_maintain_info");
                                    dmtFields.Add("post_order_id", tgid);
                                    dmtFields.Add("post_order_name", "tb_maintain_three_guaranty");

                                    dmtFields.Add("pre_item_order_id", CommonCtrl.IsNullToString(dataRowView["pre_order_id"]));
                                    dmtFields.Add("pre_item_order_name", "tb_maintain_material_detail");

                                    dmtFields.Add("post_item_order_id", CommonCtrl.IsNullToString(dataRowView["material_id"]));
                                    dmtFields.Add("post_item_order_name", "tb_maintain_three_guaranty_material_detail");

                                    //dmtFields.Add("create_time", DBHelper.GetCurrentTime().ToUniversalTime().Ticks.ToString());

                                    DBHelper.Submit_AddOrEdit("三包服务单关联维修单信息", "tr_order_relation", "order_relation", String.Empty, dmtFields);
                                }
                            }
                            //维修项目
                            var dpt = DBHelper.GetTable("维修项目数据", "tb_maintain_three_guaranty_item", "*", string.Format(" tg_id='{0}'", tgid), "", "");
                            if (dpt.Rows.Count > 0)
                            {
                                foreach (DataRow dataRowView in dpt.Rows)
                                {
                                    var dptFields = new Dictionary<String, String>();
                                    dptFields.Add("order_relation_id", Guid.NewGuid().ToString());

                                    dptFields.Add("pre_order_id", preId);
                                    dptFields.Add("pre_order_name", "tb_maintain_info");
                                    dptFields.Add("post_order_id", tgid);
                                    dptFields.Add("post_order_name", "tb_maintain_three_guaranty");

                                    dptFields.Add("pre_item_order_id", CommonCtrl.IsNullToString(dataRowView["pre_order_id"]));
                                    dptFields.Add("pre_item_order_name", "tb_maintain_item");

                                    dptFields.Add("post_item_order_id", CommonCtrl.IsNullToString(dataRowView["item_id"]));
                                    dptFields.Add("post_item_order_name", "tb_maintain_three_guaranty_item");

                                    //dmtFields.Add("create_time", DBHelper.GetCurrentTime().ToUniversalTime().Ticks.ToString());

                                    DBHelper.Submit_AddOrEdit("三包服务单关联维修单信息", "tr_order_relation", "order_relation", String.Empty, dptFields);
                                }
                            }
                            try
                            {
                                var dmtCount = DBHelper.GetSingleValue("获取维修单维修用料数量", "tb_maintain_material_detail", "count(*)", String.Format("maintain_id = '{0}'", preId), "");
                                var dptCount = DBHelper.GetSingleValue("获取维修单维修项目数量", "tb_maintain_info", "count(*)", String.Format("maintain_id = '{0}'", preId), "");
                                var reOrderCount = DBHelper.GetSingleValue("获取维修单维修项目数量", "tr_order_relation", "COUNT(*)", String.Format("pre_order_id = '{0}' and post_order_name = 'tb_maintain_three_guaranty'", preId), "");
                                if (Convert.ToInt32(dmtCount) + Convert.ToInt32(dptCount) == Convert.ToInt32(reOrderCount))
                                {
                                    var dmtFields = new Dictionary<String, String>();
                                    dmtFields.Add("order_relation_id", Guid.NewGuid().ToString());

                                    dmtFields.Add("pre_order_id", preId);
                                    dmtFields.Add("pre_order_name", "tb_maintain_info");
                                    //dmtFields.Add("post_order_id", tgid);
                                    dmtFields.Add("post_order_name", "tb_maintain_three_guaranty");
                                    //dmtFields.Add("create_time", DBHelper.GetCurrentTime().ToUniversalTime().Ticks.ToString());

                                    DBHelper.Submit_AddOrEdit("三包服务单关联维修单信息", "tr_order_relation", "order_relation", String.Empty, dmtFields);
                                }
                            }
                            catch (Exception ex)
                            {
                                GlobalStaticObj.GlobalLogService.WriteLog(ex);
                            }
                        }
                        else sb++;
                    }
                    if (cg != 0)
                    {
                        BindPageData();
                    }
                    var msg = "三包服务单提交操作成功";
                    if (sb != 0 && cg == 0)
                    {
                        msg = "三包服务单提交失败";
                    }
                    else if (cg != 0 && sb == 0)
                    {
                        msg = "三包服务单提交成功";
                    }
                    else
                    {
                        msg += ",但存在"+ sb +"条提交失败的单据";
                    }
                    MessageBoxEx.Show(msg, "操作提示");
                }
                else
                {
                    MessageBoxEx.Show("无法获取到选择的数据,请选择需要操作的数据", "操作提示");
                }
            };
            #endregion

            #region 审核按钮事件
            VerifyEvent += delegate
            {
                var tgid = "";
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                var form = new UCMaintainThreeGuarantyVerify(tgid);
                form.UcForm = this;
                var result = form.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    BindPageData();
                }
            };
            #endregion

            #region 上报厂家/总公司按钮事件
            CommitEvent += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                if (MessageBoxEx.Show("确认要将三包服务单上报宇通吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var tgid = "";
                var dataView = GetCheckRows();
                if (dataView != null)
                {
                    foreach (DataRowView rowView in GetSelectedRowData())
                    {
                        tgid = rowView["tg_id"].ToString();
                        break;
                    }
                }
                else
                {
                    return;
                }
                //var process = new ProcessOperator();
                //#region 匿名方法,后台线程执行调用
                //process.BackgroundWork = delegate()
                //{
                    var resultStr = Submit2Company(tgid, "100000001");
                    MessageBoxEx.Show(String.IsNullOrEmpty(resultStr) ? "三包服务单上报厂家成功!" : resultStr, "操作提示");
                    BindPageData();
                //};
                //#endregion
                //process.MessageInfo = "正在执行中...";
                //#region 匿名方法,后台线程执行完调用
                //process.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(
                //        delegate(object osender, BackgroundWorkerEventArgs be)
                //        {
                //            if (be.BackGroundException != null)
                //            {
                //                GlobalStaticObj.GlobalLogService.WriteLog("三包单上报", be.BackGroundException);
                //            }
                //        }
                //    );
                //#endregion
                //process.Start();
            };
            #endregion

            #region 撤销按钮事件
            RevokeEvent += delegate
            {
                if (!GlobalStaticObj.IsDefaultAcc)
                {
                    MessageBoxEx.ShowWarning("不是主账套信息,不允许进行操作!");
                    return;
                }
                if (MessageBoxEx.Show("确认要撤销已提交的单据吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
                var selectedRowsYt = GetCheckRowsByYt();
                var selectedRows = GetCheckRows();
                if (selectedRowsYt != null && selectedRowsYt.Count > 0)
                {
                    var orderStatus = DBHelper.GetSingleValue("获取三包服务单状态", TableName, "info_status", String.Format("tg_id = '{0}'", selectedRows[0]), "");
                    if (orderStatus == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ)
                    {
                        bool flag = DBHelper.Submit_AddOrEdit("撤销三包服务单", "tb_maintain_three_guaranty", "tg_id", selectedRows[0],
                            new Dictionary<string, string>
                            {
                                {
                                    "info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG
                                 }
                            });
                        if (flag)
                        {
                            var preId = String.Empty;
                            foreach (DataRowView rowView in GetSelectedRowData())
                            {
                                preId = CommonCtrl.IsNullToString(rowView["pre_order_id"]);
                            }
                            DBHelper.BatchDeleteDataByWhere("删除订单关系表信息", "tr_order_relation", String.Format("pre_order_id = '{0}' and post_order_name = 'tb_maintain_three_guaranty' and post_item_order_name is null", preId));
                            DBHelper.BatchDeleteDataByWhere("删除订单关系表信息", "tr_order_relation", String.Format("pre_order_id = '{0}' and post_order_id = '{1}'", preId, selectedRows[0]));
                            BindPageData();
                            MessageBoxEx.Show("撤销成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBoxEx.Show("撤销失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else if (orderStatus == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHTG)
                    {
                        var resultStr = DBHelper.WebServHandlerByObj("查询三包服务单状态", EnumWebServFunName.SearchOrderStatus, selectedRowsYt[0]);
                        if (resultStr == "100000001" || String.IsNullOrEmpty(resultStr))
                        {
                            var process = new ProcessOperator();
                            #region 匿名方法,后台线程执行调用
                            process.BackgroundWork = delegate()
                            {
                                Submit2Company(selectedRows[0], selectedRowsYt[0], "100000002");
                            };
                            #endregion
                            process.MessageInfo = "正在执行中...";
                            #region 匿名方法,后台线程执行完调用
                            process.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(
                                    delegate(object osender, BackgroundWorkerEventArgs be)
                                    {
                                        if (be.BackGroundException != null)
                                        {
                                            GlobalStaticObj.GlobalLogService.WriteLog("三包单上报", be.BackGroundException);
                                        }
                                    }
                                );
                            #endregion
                            process.Start();
                            var flag = DBHelper.Submit_AddOrEdit("撤销三包服务单", "tb_maintain_three_guaranty", "tg_id", selectedRows[0],
                            new Dictionary<string, string>
                            {
                                {
                                    "info_status", DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ
                                }
                            });
                            if (flag)
                            {
                                MessageBoxEx.Show("撤销成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                BindPageData();
                            }
                            else
                            {
                                MessageBoxEx.Show("撤销失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            MessageBoxEx.Show("此单据已被引用,无法撤销!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBoxEx.Show("请选择需要撤销的单据信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            };
            #endregion

            #region 导入按钮事件
            ImportEvent += delegate
            {
                //var callbackImport = new UCRepairCallbackImport();
                //callbackImport.Fetchuc = this;
                //callbackImport.strTag = "1";
                //callbackImport.ShowDialog();
            };
            #endregion

            #region 查询按钮事件
            pnl_search.QueryClick += (sender, args) => BindPageData();
            #endregion

            #region 数据翻页
            pageQ.PageIndexChanged += delegate
            {
                BindPageData();
            };
            #endregion

            #region 数据表数据选择
            dgv_table.CellDoubleClick += delegate(object sender, DataGridViewCellEventArgs args)
            {

                if (args.RowIndex < 0) return;
                var tgid = dgv_table.Rows[args.RowIndex].Cells["drtxt_tg_id"].Value.ToString();
                if (String.IsNullOrEmpty(tgid))
                {
                    MessageBoxEx.Show("无效的结算单信息", "操作提示");
                    return;
                }
                var uc = new UCMaintainThreeGuarantyViewDetail {TgId = tgid, UCForm = this};
                uc.addUserControl(uc, "三包服务单-详细信息", "UCMaintainThreeGuarantyViewDetail" + uc.TgId, Tag.ToString(), Name);
            };
            #endregion

            #region 数据表格单元格数据转换
            dgv_table.CellFormatting += (sender, args) => ConvertDataGridColumnsData(args);
            #endregion

            #region 根据选择的数据判断功能按钮的显示状态
            dgv_table.CellMouseUp += delegate
            {
                var dataView = GetSelectedRowData();
                var listField = GetCheckRows();
                if (dataView == null || listField.Count == 0)
                {
                    //btnAdd, btnCopy, btnDelete, btnInvalidOrActivation, btnVerify, btnSave, btnCommit, btnCancel, btnExport, btnImport, btn_Revoke, btnView, btnPrint, btnSet
                    btnCopy.Enabled = false;
                    btnEdit.Enabled = false;
                    btnDelete.Enabled = false;
                    btnActivation.Enabled = false;
                    btnCommit.Enabled = btnSubmit.Enabled = btnVerify.Enabled = false;
                }
                else
                {
                    var cg = 0;
                    var shwtg = 0;
                    var shtg = 0;
                    var ytj = 0;
                    var yzf = 0;
                    foreach (DataRowView drv in dataView)
                    {
                        var status = drv["info_status"].ToString();
                        if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG) cg++;
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHWTG) shwtg++;
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHTG) shtg++;
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YTJ) ytj++;
                        else if (status == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF) yzf++;
                    }

                    #region 编辑
                    if (listField.Count == 1 && (cg+shwtg) == listField.Count)
                    {
                        btnEdit.Enabled = true;
                    }
                    else
                    {
                        btnEdit.Enabled = false;
                    }
                    //提交
                    if (listField.Count >= 1 && (cg + shwtg) == listField.Count)
                    {
                        btnSubmit.Enabled = true;
                    }
                    else
                    {
                        btnSubmit.Enabled = false;
                    }
                    #endregion

                    #region 复制
                    if (listField.Count == 1 )
                    {
                        btnCopy.Enabled = true;
                    }
                    #endregion

                    #region 删除
                    if (listField.Count >= 1 && (cg+shwtg+yzf) == listField.Count)
                    {
                        btnDelete.Enabled = true;
                    }
                    else
                    {
                        btnDelete.Enabled = false;
                    }
                    #endregion

                    #region 作废/激活
                    var zf = 0;
                    var jh = 0;
                    if (listField.Count == 1)
                    {
                        foreach (DataRowView rowView in dataView) //作废/激活
                        {
                            if (rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_CG ||
                                rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_SHWTG)
                            {
                                zf ++;
                            }
                            else if (rowView["info_status"].ToString() == DbDic2Enum.SYS_SERVICE_INFO_STATUS_YZF)
                            {
                                jh++;
                            }
                        }
                        if (zf == 0 && jh != 0)
                        {
                            btnActivation.Enabled = true;
                            btnActivation.Caption = "激活";
                            btnActivation.Width = 60;
                        }
                        else if (zf != 0 && jh == 0)
                        {
                            btnActivation.Enabled = true;
                            btnActivation.Caption = "作废";
                            btnActivation.Width = 60;
                        }
                        else
                        {
                            btnActivation.Enabled = false;
                            btnActivation.Caption = "作废/激活";
                            btnActivation.Width = 90;
                        }
                    }
                    else
                    {
                        btnActivation.Enabled = false;
                        btnActivation.Caption = "作废/激活";
                        btnActivation.Width = 90;
                    }
                    #endregion

                    #region 审核
                    if (UIAssistants.ThreeServiceAudit && listField.Count == 1)
                    {
                        btnVerify.Enabled = ytj == listField.Count;
                    }
                    else
                    {
                        btnVerify.Enabled = false;
                    }
                    #endregion

                    #region 上报厂家/总公司

                    if (UIAssistants.ThreeServiceAudit)
                    {
                        if (listField.Count == 1 && listField.Count == shtg)
                        {
                            btnCommit.Enabled = true;
                        }
                        else
                        {
                            btnCommit.Enabled = false;
                        }
                    }
                    else
                    {
                        if (listField.Count == 1 && listField.Count == ytj)
                        {
                            btnCommit.Enabled = true;
                        }
                        else
                        {
                            btnCommit.Enabled = false;
                        }
                    }
                    #endregion

                    #region 撤销
                    if (listField.Count == 1 && cg == 0)
                    {
                        btnRevoke.Enabled = true;
                    }
                    else
                    {
                        btnRevoke.Enabled = false;
                    }
                    #endregion
                }
            };
            #endregion
        }