Esempio n. 1
0
        private string ConvertJsonString(string str)
        {
            try
            {
                //格式化json字符串
                JsonSerializer serializer = new JsonSerializer();
                TextReader     tr         = new StringReader(str);
                JsonTextReader jtr        = new JsonTextReader(tr);
                object         obj        = serializer.Deserialize(jtr);
                if (obj != null)
                {
                    StringWriter   textWriter = new StringWriter();
                    JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
                    {
                        Formatting  = Formatting.Indented,
                        Indentation = 4,
                        IndentChar  = ' '
                    };
                    serializer.Serialize(jsonWriter, obj);
                    return(textWriter.ToString());
                }

                return(str);
            }
            catch (Exception ex)
            {
                DSkinMessageBox.Show(ex.ToString());
                return("");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 打印
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dSkinButton2_Click(object sender, EventArgs e)
 {
     try
     {
         //文件中包含名
         string FileName = dSkinGridList1.SelectedItem.Cells[1].Value.ToString();
         string f1name   = Regex.Replace(FileName.Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "") + ".prn";
         string smallDir = "";
         GetFile(DirName, f1name, ref smallDir);
         //  DSkinMessageBox.Show("文件在" + smallDir);
         var FileSum = dSkinGridList1.SelectedItem.Cells[3].Value.ToString();
         int asum    = int.Parse(FileSum) / 2;
         for (int i = 0; i < asum; i++)
         {
             @Pdfpath = smallDir;
             string ZeberNmae = ConfigurationManager.AppSettings["ZeberNmae"];
             if (PrintCode.SendFileToPrinter(ZeberNmae, smallDir))
             {
                 Console.WriteLine("文件已成功发送至打印队列!", "提示信息");
             }
         }
         // DSkinMessageBox.Show(FileSum);
     }
     catch (Exception ex)
     {
         DSkinMessageBox.Show("请选择要打印的数字");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 保存文章
        /// </summary>
        /// <returns>是否保存成功</returns>
        private bool SaveArticle()
        {
            bool success;
            var  article = GetArticle();

            // 如果Article为null,则是新增文章
            if (Article == null)
            {
                var result = _articleApi.Insert(article);

                success = result.IsSuccess();
                DSkinMessageBox.Show(success ? "新增文章成功" : result.Message, "新增文章");
            }

            // 否则是编辑文章
            else
            {
                article.Id = Article.Id;
                var result = _articleApi.Update(article);

                success = result.IsSuccess();
                DSkinMessageBox.Show(success ? "修改文章成功" : result.Message, "修改文章");
            }

            // 成功时调用
            if (success)
            {
                SuccessAction?.Invoke();
            }

            return(success);
        }
Esempio n. 4
0
 private void loadData(bool status = false)
 {
     if ((next <= DateTime.Now && is_update == false) || status)
     {
         is_update = true;
         DateTime now = last = DateTime.Now;
         next = now.AddHours(2);
         IniHelper.Instance.WriteString("Setting", "last", now.ToString("yyyy-MM-dd HH:mm:ss"));
         IniHelper.Instance.WriteString("Setting", "next", next.ToString("yyyy-MM-dd HH:mm:ss"));
         //开始获取数据
         re = Common.JsonHelper.JSONString <Result>(Action(city));
         //re = Weather.getWeather(city);
         if (re.status != 200)
         {
             DSkinMessageBox.Show(re.message);
             this.Close();
         }
         fo.result = re;
         dSkinPictureBox1.Image = System.Drawing.Image.FromFile(Weather.changeImg(re.data.forecast[0].type));
         label1.Text            = re.cityInfo.city;
         label2.Text            = re.data.wendu;
         dSkinLabel1.Text       = now.ToString("MM-dd");
         dSkinLabel2.Text       = re.data.forecast[0].week;
         dSkinLabel3.Text       = Common.TimeHelper.GetChineseDateTime(now);
         dSkinLabel4.Text       = re.data.forecast[0].type + "    " + re.data.forecast[0].low.Replace("低温", "").Replace(" ", "").Replace("℃", "") + " ~" + re.data.forecast[0].high.Replace("高温", "").Replace(" ", "").Replace("℃", "") + "℃";
         dSkinLabel5.Text       = re.data.forecast[0].fx + "    " + re.data.forecast[0].fl;
         dSkinLabel6.Text       = "更新时间    " + re.cityInfo.updateTime;
         //获取数据结束
         is_update = false;
     }
 }
Esempio n. 5
0
 private void dSkinButton1_Click(object sender, EventArgs e)
 {
     if (!dSkinCheckBox1.Checked && !Directory.Exists(this.dSkinTextBox1.Text))
     {
         DSkinMessageBox.Show("目录不存在");
         return;
     }
     for (int i = 0; i < dSkinGridList1.RowCount; i++)
     {
         if (dSkinCheckBox1.Checked)
         {
             if (!Directory.Exists("temp"))
             {
                 Directory.CreateDirectory("temp");
             }
         }
         // DSkinMessageBox.Show(dSkinGridList1.Rows[i].Cells[1].Value.ToString());
         Common.ImageHelper.CompressImage(
             dSkinGridList1.Rows[i].Cells[1].Value.ToString(),
             dSkinCheckBox1.Checked? ("temp/" + dSkinGridList1.Rows[i].Cells[0].Value.ToString()) : (this.dSkinTextBox1.Text + "/" + dSkinGridList1.Rows[i].Cells[0].Value.ToString()),
             dSkinTrackBar1.Value,
             Convert.ToInt32(dSkinNumericUpDown1.Value)
             );
         if (dSkinCheckBox1.Checked)
         {
             if (!Directory.Exists("temp"))
             {
                 Directory.CreateDirectory("temp");
             }
             File.Copy("temp/" + dSkinGridList1.Rows[i].Cells[0].Value.ToString(), dSkinGridList1.Rows[i].Cells[1].Value.ToString(), true);
             File.Delete("temp/" + dSkinGridList1.Rows[i].Cells[0].Value.ToString());
         }
         dSkinGridList1.Rows[i].Cells[2].Value = "完成";
     }
 }
Esempio n. 6
0
 private void ExitButton_Click(object sender, EventArgs e)
 {
     if (DSkinMessageBox.Show("确定要放弃编辑并关闭吗?", "放弃编辑并关闭",
                              MessageBoxButtons.OKCancel) == DialogResult.OK)
     {
         Close();
     }
 }
Esempio n. 7
0
        private void dSkinButton2_Click(object sender, EventArgs e)
        {
            string str = dSkinChatRichTextBox1.Text;

            if (!Common.JsonHelper.IsJson(str))
            {
                DSkinMessageBox.Show("不是JSON数据");
                return;
            }
            dSkinChatRichTextBox1.Text = "";
            dSkinChatRichTextBox1.AppendText(JsonConvert.SerializeObject(Common.JsonHelper.ExtractObj(str)));
        }
Esempio n. 8
0
 public FrmMain(string str = "")
 {
     InitializeComponent();
     if (!Common.JsonHelper.IsJson(str))
     {
         dSkinChatRichTextBox1.Text = str;
         DSkinMessageBox.Show("不是JSON数据");
         return;
     }
     dSkinChatRichTextBox1.Text = "";
     dSkinChatRichTextBox1.AppendText(ConvertJsonString(str));
 }
Esempio n. 9
0
        private void getResult(int type = 0, string str = "")
        {
            BaseController baseController = new BaseController();

            if (img == null)
            {
                DSkinMessageBox.Show("请先选择图片");
                return;
            }
            string result = baseController.AdvancedGeneralDemo(img, type, str);

            new FrmResult(result).ShowDialog();
        }
Esempio n. 10
0
        public static Result getWeather(string cityid = "")
        {
            string baseurl = "http://t.weather.itboy.net/api/weather/city/";
            Result result  = new Result();
            string str     = Common.HttpHelper.Get(baseurl + cityid);

            result = Common.JsonHelper.JSONString <Result>(str);
            if (result.status != 200)
            {
                DSkinMessageBox.Show(result.message);
                return(null);
            }
            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// 删除当前选中的文章
        /// </summary>
        private void DeleteArticle()
        {
            if (DSkinMessageBox.Show($"确定要删除 {_selectArticle.Title} 吗?", "删除文章",
                                     MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            var result = _articleApi.Delete(_selectArticle.Id);

            DSkinMessageBox.Show(result.IsSuccess() ? "删除成功" : result.Message, "删除文章");

            // 如果删除成功,刷新文章列表
            if (result.IsSuccess())
            {
                RequestArticles(_pageNum);
            }
        }
Esempio n. 12
0
        private void SaveAndExitButton_Click(object sender, EventArgs e)
        {
            if (!CheckArticle())
            {
                return;
            }

            if (DSkinMessageBox.Show("确定要保存并关闭吗?", "保存并关闭",
                                     MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            if (SaveArticle())
            {
                Close();
            }
        }
Esempio n. 13
0
        public static Result getExpress(string typee, string order)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("key", key);
            dic.Add("id", typee);
            dic.Add("order", order);
            dic.Add("ord", ord);
            dic.Add("show", show);
            string str    = Common.HttpHelper.Post(url, dic);
            Result result = Common.JsonHelper.JSONString <Result>(str);

            if (result.errCode == 0)
            {
                return(result);
            }
            switch (result.errCode)
            {
            case 1:
                DSkinMessageBox.Show("快递KEY无效");
                return(null);

            case 2:
                DSkinMessageBox.Show("快递代号无效");
                return(null);

            case 3:
                DSkinMessageBox.Show("访问次数达到最大额度");
                return(null);

            case 4:
                DSkinMessageBox.Show("查询服务器返回错误即返回状态码非200");
                return(null);

            case 5:
                DSkinMessageBox.Show("查询执行出错");
                return(null);

            default:
                DSkinMessageBox.Show("接口错误");
                return(null);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        private void Login(string username, string password)
        {
            var result = _authApi.Login(username, password);

            if (!result.IsSuccess())
            {
                DSkinMessageBox.Show(result.Message, "登陆失败", MessageBoxButtons.OK);
            }
            else
            {
                // 保存设置
                SaveSettings(result.Entity.Token);
                DialogResult = DialogResult.OK;

                // 调用登陆成功方法
                LoginAction?.Invoke(result.Entity.User);

                Close();
            }
        }
Esempio n. 15
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            // 表单验证
            var username = UsernameTextBox.Text;

            if (username.Trim() == string.Empty)
            {
                DSkinMessageBox.Show("用户名不能为空", "不能为空", MessageBoxButtons.OK);
                return;
            }

            var password = PasswordTextBox.Text;

            if (password.Trim() == string.Empty)
            {
                DSkinMessageBox.Show("密码不能为空", "不能为空", MessageBoxButtons.OK);
                return;
            }

            Login(username, password);
        }
Esempio n. 16
0
        /// <summary>
        /// 表单验证
        /// </summary>
        /// <returns>表单验证是否通过</returns>
        private bool CheckArticle()
        {
            if (!CheckTextBox(TitleTextBox))
            {
                DSkinMessageBox.Show("文章标题不能为空", "不能为空");
                return(false);
            }

            if (!CheckTextBox(SubTitleTextBox))
            {
                DSkinMessageBox.Show("文章副标题不能为空", "不能为空");
                return(false);
            }

            if (!CheckTextBox(ContentTextBox))
            {
                DSkinMessageBox.Show("文章内容不能为空", "不能为空");
                return(false);
            }

            return(true);
        }
Esempio n. 17
0
        private void  除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dSkinTreeView1.SelectedNode == null)
            {
                return;
            }
            int           cate_id = Convert.ToInt32(dSkinTreeView1.SelectedNode.Tag.ToString());
            StringBuilder sql     = new StringBuilder();

            sql.Append("select count(*) from password_category where pid=" + cate_id);
            DataSet ds = Common.SQLiteHelper.ExecuteDataSet(sql.ToString(), CommandType.Text);

            foreach (DataRow mDr in ds.Tables[0].Rows)
            {
                if (!Common.StrHelper.checkEquals(mDr[0].ToString(), "0"))
                {
                    DSkinMessageBox.Show("有下级数据,禁止删除");
                    return;
                }
            }
            sql = new StringBuilder();
            sql.Append("select count(*) from password where cate_id=" + cate_id);
            ds = Common.SQLiteHelper.ExecuteDataSet(sql.ToString(), CommandType.Text);
            foreach (DataRow mDr in ds.Tables[0].Rows)
            {
                if (!Common.StrHelper.checkEquals(mDr[0].ToString(), "0"))
                {
                    DSkinMessageBox.Show("有密码数据,禁止删除");
                    return;
                }
            }
            sql = new StringBuilder();
            sql.Append("delete from password_category where id=" + cate_id);
            Common.SQLiteHelper.ExecuteNonQuery(sql.ToString(), CommandType.Text);
            LoadCate();
        }