小编kam*_*ame的帖子

如何使用openfile对话框在c#windows窗体中的byte []中获取文件

我想检索邮件附件并将其存储,bytes[]以便我可以将它们插入到列附件varbinary类型的表中.在Windows窗体中我正在使用OpenFileDialog,我不知道如何在一个byte[]类型中获取文件的字节,以便我可以将其插入到SQLServer中的表中.

这是代码:

namespace fyp8
{
    public partial class ComposeMail : Form1
    {
        ArrayList alAttachments;
        MailMessage mmsg;
        string conn = @"Data source=(local);Initial Catalog=fyp;Integrated Security=true";


        public ComposeMail()
        {
            InitializeComponent();
        }

        private void ComposeMail_Load(object sender, EventArgs e)
        {

        }

        private void btnAttachment_Click(object sender, EventArgs e)
        {
            OpenFileDialog odflg = new OpenFileDialog();
            odflg.ShowDialog();
            if (odflg.ShowDialog() == DialogResult.OK)
            {

                try
                {
                    txtAttachments.Text = odflg.FileName;

                }

                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
        }

        private void btnSend_Click(object sender, …
Run Code Online (Sandbox Code Playgroud)

c# winforms

1
推荐指数
1
解决办法
3616
查看次数

Math.Acos 不工作?

当我运行我的程序时,我试图使用余弦逆。所以我使用 Math.Acos()。

我愿意:

Console.WriteLine(Math.Acos(0.8).ToString());
Run Code Online (Sandbox Code Playgroud)

我想得到的价值是:36.869897645844

但我得到的值是:0.643501108793284

Math.Acos 方法有问题吗?

c# math

1
推荐指数
1
解决办法
3748
查看次数

git:无法将文件添加到 github

我发现了一些类似的问题。但我找不到解决办法。

我使用以下命令将包含文件和子文件夹的文件夹添加到我的本地存储库:

git add .
Run Code Online (Sandbox Code Playgroud)

然后用:

git commit -m "comment"
Run Code Online (Sandbox Code Playgroud)

我得到:

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)

问题是,我在github上找不到文件。有任何想法吗?

编辑:

git push -u git@github.com:kamekame/wolke master
Run Code Online (Sandbox Code Playgroud)

给出:

To git@github.com:kamekame/wolke
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:kamekame/wolke'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. …
Run Code Online (Sandbox Code Playgroud)

git github add

1
推荐指数
1
解决办法
3676
查看次数

Greasemonkey:突出显示HTML文件中的许多单词

我想用Greasemonkey来突出两个词,例如"巴塞尔,伯尔尼".如果我只使用巴塞尔,则以下版本有效.不是很好,但足够好.但是,当我使用两个单词时,突出显示不起作用.

// ==UserScript==
// @name        highlight-some-words
// @description highlight some words in html
// @grant       none
// ==/UserScript==

document.body.innerHTML= document.body.innerHTML.replace(/Basel|Bern/g, function(m){
    return '<span style="background-color:lightgreen">'+m+'</span>'
});
Run Code Online (Sandbox Code Playgroud)

编辑:有趣的是,该脚本适用于stackoverflow.com但不适用于google.com.为什么?那么如何修改脚本呢?

html javascript greasemonkey highlight

1
推荐指数
1
解决办法
1713
查看次数

AttributeError:module'ctypes.wintypes'没有属性'create_unicode_buffer'

这是我的代码的一部分:

import os

def _get_appdata_path():
    import ctypes
    from ctypes import wintypes, windll
    CSIDL_APPDATA = 26
    _SHGetFolderPath = windll.shell32.SHGetFolderPathW
    _SHGetFolderPath.argtypes = [wintypes.HWND,
                                 ctypes.c_int,
                                 wintypes.HANDLE,
                                 wintypes.DWORD,
                                 wintypes.LPCWSTR]
    path_buf = wintypes.create_unicode_buffer(wintypes.MAX_PATH)
    result = _SHGetFolderPath(0, CSIDL_APPDATA, 0, 0, path_buf)
    return path_buf.value
Run Code Online (Sandbox Code Playgroud)

但是当我打电话时,wintypes.create_unicode_buffer()我得到了错误:

AttributeError: module 'ctypes.wintypes' has no attribute 'create_unicode_buffer'
Run Code Online (Sandbox Code Playgroud)

我使用的是Python 3.5.1.我能做什么?

python ctypes compiler-errors python-3.5

1
推荐指数
1
解决办法
1732
查看次数

从python中的字符串中提取年份

我该如何解析foll.在python中提取年份:

'years since 1250-01-01 0:0:0'
Run Code Online (Sandbox Code Playgroud)

答案应该是1250

python regex

1
推荐指数
2
解决办法
5285
查看次数

计算错误,使用+代替-

由于培训原因,我想编写一个小计算器。为什么要计算10-6 = 16而不是10-6 = 4?

我得到了错误:

Assertion Failed!
Expression: calc("10-6") == 4 && "could not do substraction"
Run Code Online (Sandbox Code Playgroud)

这是我的代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include <ctype.h>

double calc(char * input);
double extract_first_integer(char * input);
double extract_last_integer(char * input);
char extract_operand(char * input);

int main()
{
   assert(calc("10-6") == 4 && "could not do substraction");

   return 0;
}

double calc(char * input){
   double num1 = extract_first_integer(input);
   double num2 = extract_last_integer(input);
   char operand = extract_operand(input);
   printf("operand is %c\n", operand); …
Run Code Online (Sandbox Code Playgroud)

c math

1
推荐指数
1
解决办法
82
查看次数

Python:对列表进行排序

我想对数组 c 进行排序。但我没有得到答案 a、b、c、d。相反,我得到了 a、b、d、c。我能做什么,对整个数组进行排序,而不仅仅是一行?

编辑:我想对数字进行排序。并且连接的字母应该与排序的数字具有相同的顺序。对不起,我的问题不清楚。也许我应该先加入数字和字母。像这样:[['a',1]['b',2]....

a = ['a','b','d','c']
b = [1,2,4,3]
c = [[],[]]
c[0]=a
c[1]=b
c[1].sort()
print(c)
Run Code Online (Sandbox Code Playgroud)

python sorting list

0
推荐指数
1
解决办法
2900
查看次数

使用Python的Euler Project No. 2

有人能告诉我为什么这应该是错的吗?

#Each new term in the Fibonacci sequence is generated
#by adding the previous two terms. By starting with 1 and 2,
#the first 10 terms will be:
#1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
#Find the sum of all the even-valued terms in the sequence
#which do not exceed four million.


sum=2

list = [1,2]
for x in range(2,100):
    a = list[x-2]+list[x-1]
    print(a)
    list.append(a)
    if a % 2 == 0:
        sum += a
        print('sum', sum) …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
2
解决办法
553
查看次数

Matlab:用biot-savarts法计算的磁场

这是使用biot-savart定律计算磁场的代码.我希望得到一些tipps来优化这段代码.遗憾的是我使用德语:(我再也不会这样做了.:)

tic
clear all; clc; clf
skalierungsfaktor = 10^-6; % vom m-Bereich zum mm-Bereich wg. T = Vs / m^2
I = 1; % in A
konstante = 10^-10; % mu0 / (4 pi) in Vs / (A mm) % Faktor 10^3 kleiner wg. mm statt m
matrix = 30;
B = zeros(200,200,200,5);
zaehler = 0; % für Zeitmessung
xmax = matrix;
ymax = matrix;
zmax = 1;
radius = 9; % Spulenradius in mm
genauigkeit = 5; % 1 …
Run Code Online (Sandbox Code Playgroud)

optimization matlab physics

0
推荐指数
1
解决办法
5666
查看次数