示例#1
0
        //执行数据库操作
        private void SignSql(int id)
        {
            int       flag    = 0;
            DataMysql datasql = new DataMysql();

            datasql.dataCon();
            //    string cmdStr = "Select time from signlog";
            string  cmdStr = "Select * from signlog where id = '" + id.ToString() + "'";
            DataSet ds;

            ds = datasql.getDataSet(cmdStr);
            int j = 0;

            j = ds.Tables[0].Rows.Count;
            string[] timedata = new string[j];
            j = 0;
            foreach (DataRow Row in ds.Tables[0].Rows)
            {
                timedata[j] = Convert.ToString(Row["signid"]);
                j++;
            }
            string time = id.ToString() + DateTime.Now.ToString("yyyy-MM-dd");

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (timedata[i].Equals(time))
                {
                    flag = 1;
                }
            }
            string  cmdStrname = "Select name from user where id = '" + id.ToString() + "'";
            DataSet dsa;

            dsa = datasql.getDataSet(cmdStrname);
            if (flag == 0)
            {
                string sign     = id.ToString() + DateTime.Now.ToString("yyyy-MM-dd");
                string signtime = DateTime.Now.ToLocalTime().ToString();
                string insert   = "insert into signlog (id,signid,flag,signtime,daytime) values ( '" + id.ToString() + "','" + sign + "','1','" + signtime + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "')";


                if (datasql.sqlExec(insert))
                {
                    MessageBox.Show("恭喜您:" + dsa.Tables[0].Rows[0][0].ToString() + " 签到成功");
                }
            }
            else
            {
                MessageBox.Show("尊敬的用户:" + dsa.Tables[0].Rows[0][0].ToString() + " 您今天已经签到无需再次签到");
            }
        }
示例#2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (!(String.IsNullOrEmpty(path[0])))
            {
                string url = "https://www.ylesb.com/csimg/pound.php";
                try
                {
                    WebClient client = new WebClient();
                    client.Credentials = CredentialCache.DefaultCredentials;
                    client.Headers.Add("Content-Type", "application/form-data");        //注意头部必须是form-data
                    string filename = idtb.Text + Path.GetFileName(path[0]);
                    client.QueryString["file_name"] = filename;
                    byte[] fileb = client.UploadFile(new Uri(url), "POST", path[0]);
                    string res   = Encoding.UTF8.GetString(fileb);
                }
                catch (Exception ex)
                {
                    AppendText(ex.Message);
                }

                DataMysql datasql = new DataMysql();
                datasql.dataCon();
                string imgname = "https://www.ylesb.com/csimg/" + idtb.Text + Path.GetFileName(path[0]);
                string update  = "update user set faceimg ='" + imgname + "' where id='" + idtb.Text + "'";
                if (datasql.sqlExec(update))
                {
                    AppendText("更新成功,请访问'" + imgname + "'查看是否本人\n");
                    imageLists.Images.Clear();
                    imageList.Items.Clear();
                    imagesFeatureList.Clear();
                    imagePathList.Clear();
                    idtb.Text = "";
                }
                else
                {
                    AppendText("录入失败,网络出现异常,请稍后再试!");
                    imageLists.Images.Clear();
                    imageList.Items.Clear();
                    imagesFeatureList.Clear();
                    imagePathList.Clear();
                    idtb.Text = "";
                }
            }
            else
            {
                MessageBox.Show("您未选择录入图片,请选择后提交!");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (!(String.IsNullOrEmpty(path[0])))
            {
                if (!(String.IsNullOrEmpty(idtb.Text)))
                {
                    if (!(String.IsNullOrEmpty(nametb.Text)))
                    {
                        DataMysql data = new DataMysql();
                        data.dataCon();
                        string  cmdStr = "Select * from user where id='" + idtb.Text + "'";
                        DataSet ds;
                        ds = data.getDataSet(cmdStr);
                        if (ds.Tables[0].Rows.Count == 1)
                        {
                            MessageBox.Show("已经添加过此员工了,请勿重复添加!");
                            AppendText("已经添加过此员工了,请勿重复添加!");
                            imageLists.Images.Clear();
                            imageList.Items.Clear();
                            imagesFeatureList.Clear();
                            imagePathList.Clear();
                            idtb.Text   = "";
                            nametb.Text = "";
                        }
                        else
                        {
                            string url = "https://www.ylesb.com/csimg/pound.php";
                            try
                            {
                                WebClient client = new WebClient();
                                client.Credentials = CredentialCache.DefaultCredentials;
                                client.Headers.Add("Content-Type", "application/form-data");//注意头部必须是form-data
                                string filename = idtb.Text + Path.GetFileName(path[0]);
                                client.QueryString["file_name"] = filename;
                                byte[] fileb = client.UploadFile(new Uri(url), "POST", path[0]);
                                string res   = Encoding.UTF8.GetString(fileb);
                            }
                            catch (Exception ex)
                            {
                                AppendText(ex.Message);
                            }

                            DataMysql datasql = new DataMysql();
                            datasql.dataCon();
                            string imgname = "https://www.ylesb.com/csimg/" + idtb.Text + Path.GetFileName(path[0]);
                            string insert  = "insert into user (id,name,faceimg) values ( '" + idtb.Text + "','" + nametb.Text + "','" + imgname + "')";
                            if (datasql.sqlExec(insert))
                            {
                                AppendText("录入成功,请访问'" + imgname + "'查看是否本人\n");
                                imageLists.Images.Clear();
                                imageList.Items.Clear();
                                imagesFeatureList.Clear();
                                imagePathList.Clear();
                                idtb.Text   = "";
                                nametb.Text = "";
                            }
                            else
                            {
                                AppendText("录入失败,网络出现异常,请稍后再试!");
                                imageLists.Images.Clear();
                                imageList.Items.Clear();
                                imagesFeatureList.Clear();
                                imagePathList.Clear();
                                idtb.Text   = "";
                                nametb.Text = "";
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("您未输入员工姓名,请输入后提交!");
                    }
                }
                else
                {
                    MessageBox.Show("您未输入员工ID,请输入后提交!");
                }
            }
            else
            {
                MessageBox.Show("您未选择录入图片,请选择后提交!");
            }
        }