private void btni_DataInput_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件|*.*";
            ofd.ValidateNames   = true;
            ofd.CheckPathExists = true;
            ofd.CheckFileExists = true;
            G.Setlb_QueryState("正在导入数据...");
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string fileName = ofd.FileName;
                try
                {
                    DataTable dt = ExcelHelperForCs.ImportFromExcel(fileName, "部门结构", 0);

                    foreach (DataRow item in dt.Rows)
                    {
                        TimeAttendance_Department tad = new TimeAttendance_Department()
                        {
                            DepartmentNo         = item["组别编号"].ToString(),
                            DepartmentName       = item["组别名称"].ToString(),
                            ParentDepartmentNo   = item["上级部门编号"].ToString(),
                            ParentDepartmentName = item["上级部门名称"].ToString(),
                            NumberOfStaff        = Convert.ToInt32(item["编制人数"]),
                            InTheNumberOfStaff   = Convert.ToInt32(item["在编人数"]),
                            ExceedNumberOfStaff  = Convert.ToInt32(item["超编人数"]),
                            note = item["备注"].ToString()
                        };
                        try
                        {
                            if (TadBll.insertTimeAttendance_DepartmentBll(tad, "insertTimeAttendance_Department"))
                            {
                                G.Setlb_QueryState("保存完成");
                                this.treeView1.Nodes.Clear();
                            }
                            else
                            {
                                G.Setlb_QueryState("保存失败");
                            }
                        }
                        catch
                        {
                            G.Setlb_QueryState("保存异常,请检查网络连接情况");
                        }
                    }

                    SetTreeeview();
                    G.Setlb_QueryState("导入完成");
                }
                catch (Exception ex)
                {
                    G.Setlb_QueryState("可能导入的Excle文件无法识别");
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #2
0
 private void btni_dataOut_Click(object sender, EventArgs e)
 {
     if (this.dataGridViewX1.CurrentRow == null)
     {
         MessageBox.Show("没有可导出的数据!");
         return;
     }
     ExcelHelperForCs.ExportToExcel(dataGridViewX1);
     MessageBox.Show("导出完成");
 }
Example #3
0
        private void btni_Outdata_Click(object sender, EventArgs e)
        {
            if (!(UsersHelp.systemAdimin || UsersHelp.StaffResume_DataOut))
            {
                MessageBox.Show("抱歉,您没有使用该功能的权限");
                return;
            }

            if (this.dataGridViewX1.CurrentRow == null)
            {
                MessageBox.Show("没有可导出的数据!");
                return;
            }
            ExcelHelperForCs.ExportToExcel(dataGridViewX1);
            MessageBox.Show("导出完成");
        }
Example #4
0
        void ExcelInput(string fileName, bool bl)
        {
            try
            {
                DataTable dt = ExcelHelperForCs.ImportFromExcel(fileName, "Sheet1", 0);
                List <ProjectorInformation_LD> list = new List <ProjectorInformation_LD>();
                if (bl)
                {
                    foreach (DataRow item in dt.Rows)
                    {
                        ProjectorInformation_LD ld = new ProjectorInformation_LD()
                        {
                            FuselageCode      = item[4].ToString(),
                            IlluminationValue = item[5].ToString(),
                            LuminanceTestTime = Convert.ToDateTime(item[1].ToString()),
                            WiredMAC          = item[2].ToString(),
                            wirelessMAC       = item[3].ToString(),
                            ZhiDan            = ZhiDan
                        };
                        list.Add(ld);
                    }
                    int i = 0;
                    foreach (ProjectorInformation_LD item in list)
                    {
                        i++;
                        if (pmtb.updateProjectorInformation_MainTable_LDBll(item, "updateProjectorInformation_MainTable_LD"))
                        {
                            my_context.Post(SetTextBox, "照度值写入成功!***" + " 机身码:" + item.FuselageCode + " ***时间:" + DateTime.Now.ToString() + "\r\n" + "\r\n");
                        }
                        else
                        {
                            my_context.Post(SetTextBox2, "照度值写入失败!***" + " 机身码:" + item.FuselageCode + " ***时间:" + DateTime.Now.ToString() + "\r\n" + "\r\n");
                        }

                        my_context.Post(SetLable, i.ToString() + "/" + list.Count.ToString());
                    }
                }
                else
                {
                    foreach (DataRow item in dt.Rows)
                    {
                        ProjectorInformation_LD ld = new ProjectorInformation_LD()
                        {
                            WiredMAC          = item[1].ToString(),
                            wirelessMAC       = item[2].ToString(),
                            FuselageCode      = item[3].ToString(),
                            IlluminationValue = item[4].ToString(),
                            ZhiDan            = ZhiDan
                        };
                        list.Add(ld);
                    }
                    int i = 0;
                    foreach (ProjectorInformation_LD item in list)
                    {
                        i++;
                        if (pmtb.updateProjectorInformation_MainTable_LDZ2Bll(item, "updateProjectorInformation_MainTableLDZ2"))
                        {
                            my_context.Post(SetTextBox, "照度值写入成功!***" + " 机身码:" + item.FuselageCode + " ***时间:" + DateTime.Now.ToString() + "\r\n" + "\r\n");
                        }
                        else
                        {
                            my_context.Post(SetTextBox2, "照度值写入失败!***" + " 机身码:" + item.FuselageCode + " ***时间:" + DateTime.Now.ToString() + "\r\n" + "\r\n");
                        }

                        my_context.Post(SetLable, i.ToString() + "/" + list.Count.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }