/// <summary>
        /// 从服务器中获得图片
        /// </summary>
        /// <param name="savePath">图片保存相对路径</param>
        /// <param name="pl">显示图片的容器</param>
        public void getPic_Server(string filepath, Panel pl)
        {
            if (string.IsNullOrEmpty(filepath))
            {
                return;
            }
            int    port  = 2010;
            string ipsrv = "127.0.0.1";
            string sport = DataAccRes.AppSettings("Granity文件服务");
            string conn  = DataAccRes.DefaultDataConnInfo.Value;

            if (!string.IsNullOrEmpty(sport))
            {
                try { port = Convert.ToInt32(sport); }
                catch { return; }
            }
            Regex regIP = new Regex(@"server=([\w.\(\)]*)(;|\\)");

            if (regIP.IsMatch(conn))
            {
                Match mt = regIP.Match(conn);
                if (mt.Groups.Count > 1)
                {
                    ipsrv = mt.Groups[1].Value.ToLower();
                }
                if ("(local)" == ipsrv || "127.0.0.1" == ipsrv)
                {
                    ipsrv = Dns.GetHostName();
                }
                ipsrv = Dns.GetHostAddresses(ipsrv)[0].ToString();
            }
            CommiTarget target = new CommiTarget(ipsrv, port, CommiType.TCP);

            target.setProtocol(CmdFileTrans.PTL);
            CmdFileTrans cmd = new CmdFileTrans(false);

            cmd.GetFile(filepath);
            CommiManager.GlobalManager.SendCommand(target, cmd);
            if (cmd.EventWh.WaitOne(new TimeSpan(0, 0, 15), false))
            {
                byte[] data = cmd.FileContext;
                if (data.Length < 1)
                {
                    return;
                }
                MemoryStream stream = new MemoryStream(data);
                pl.BackgroundImage = Image.FromStream(stream);
            }
        }
Exemple #2
0
        /// <summary>-
        /// 保存设备
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbSave_Click(object sender, EventArgs e)
        {
            this.validateFeeTab();
            DataTable tabpark  = this.ds.Tables["停车场管理"];
            DataTable tabfee   = this.ds.Tables["收费标准"];
            DataTable tabdspan = this.ds.Tables["收费标准时段"];
            DataTable tabdtime = this.ds.Tables["收费标准时刻"];

            DataTable[] tablist   = { tabpark, tabfee, tabdspan, tabdtime };
            bool        isSuccess = this.Query.BeginTransaction();
            string      msg       = "";

            if (!isSuccess)
            {
                msg = "保存失败,无法打开事务!";
            }
            else
            {
                foreach (DataTable tab in tablist)
                {
                    NameObjectList[] psins = ParamManager.createParam(tab, DataRowState.Added);
                    NameObjectList[] psupt = ParamManager.createParam(tab, DataRowState.Modified);
                    NameObjectList[] psdel = ParamManager.createParam(tab, DataRowState.Deleted);
                    isSuccess = this.Query.ExecuteNonQuery(tab.TableName, psins, psupt, psdel);
                    if (!isSuccess)
                    {
                        msg = "保存失败,请检查数据是否合法!";
                        break;
                    }
                }
            }
            if (!isSuccess)
            {
                this.Query.RollbackAndClose();
            }
            else
            {
                this.Query.Commit();
                this.Query.Close();
                foreach (DataTable tab in tablist)
                {
                    tab.AcceptChanges();
                }
                //发出通讯更新设备
                int    port  = 2010;
                string sport = DataAccRes.AppSettings("Granity文件服务");
                if (!string.IsNullOrEmpty(sport))
                {
                    try { port = Convert.ToInt32(sport); }
                    catch { return; }
                }
                string conn  = DataAccRes.DefaultDataConnInfo.Value;
                Regex  regIP = new Regex(@"server=([\w.\(\)]*)(;|\\)");
                string ipsrv = "127.0.0.1";
                if (regIP.IsMatch(conn))
                {
                    Match mt = regIP.Match(conn);
                    if (mt.Groups.Count > 1)
                    {
                        ipsrv = mt.Groups[1].Value.ToLower();
                    }
                    if ("(local)" == ipsrv || "127.0.0.1" == ipsrv)
                    {
                        ipsrv = Dns.GetHostName();
                    }
                    ipsrv = Dns.GetHostAddresses(ipsrv)[0].ToString();
                }
                CmdFileTrans cmd = new CmdFileTrans(false);
                cmd.ExtRefreshDevice();
                CommiTarget target = new CommiTarget(ipsrv, port, CommiType.TCP);
                CommiManager.GlobalManager.SendCommand(target, cmd);
            }
            if (!isSuccess)
            {
                MessageBox.Show(msg, "保存提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                MessageBox.Show("保存成功!", "保存提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }