Exemplo n.º 1
0
        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            try
            {
                AssignValueToData();
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
                return;
            }
            if (this.number == -1 && this.monthCount == -1 && this.totalMoney == -1 && this.subscription == "汤" && this.client == "华" && this.startDate == DateTime.Parse("1000-1-1") && this.endDate == DateTime.Parse("1000-1-1") && this.giveDate == DateTime.Parse("1000-1-1"))
            {
                MessageBox.Show("请输入一个要批量修改的值!");
                return;
            }

            if (MessageBox.Show("是否确认要批量修改?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                BatchUpdateSelectedRows();

                MainForm.Form.CurrentDataSet = SubscribeInfoManager.RetriveDataFromTempInfo();

                this.DialogResult = DialogResult.OK;

                this.Close();
            }
        }
Exemplo n.º 2
0
        bool DeleteSelectedRows()
        {
            if (TestSelectedRows() == false)
            {
                MessageBox.Show("请选中一行进行删除!");
                return(false);
            }
            if (MessageBox.Show("删除后不能恢复,是否删除?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                for (int i = 0; i < this.currentDataSet.Tables[0].Rows.Count; i++)             //通过循环删除所有被选中的行
                {
                    if (this.dataGrid1.IsSelected(i) == true)
                    {
                        string name    = this.currentDataSet.Tables[0].Rows[i]["姓名"].ToString();
                        string company = this.currentDataSet.Tables[0].Rows[i]["公司"].ToString();
                        SubscribeInfoManager.DeleteSubscribeInfo(name, company);
                    }
                }

                this.currentDataSet = SubscribeInfoManager.RetriveDataFromTempInfo();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        private void btnSubmit_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (this.cmbRegion.SelectedValue != null)
                {
                    if (this.cmbRegion.SelectedValue.ToString().Trim() == "")
                    {
                        MessageBox.Show("地区不能为空!");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("地区不能为空!");
                    return;
                }
                GetValues();

                int id = SubscribeInfoManager.CreateSubscribeInfo(name, post, company, address, region, postcode, telephone,
                                                                  mobilePhone, startDate, endDate, giveDate, number, monthCount, totalMoney, inscribe, source, payment, invoice, client, operator1, bonus,
                                                                  localAddress, subscription);
                if (id == 1)                  //添加成功
                {
                    MainForm.Form.CurrentDataSet = SubscribeInfoManager.RetriveDataFromTempInfo();

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else                  //添加失败
                {
                    MessageBox.Show("已经存在该记录!");
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }
Exemplo n.º 4
0
        bool ImportExcelData()
        {
            openFileDialog1.Filter           = "Excel数据文件|*.xls";
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                DataSet   ds        = null;
                DataTable tempTable = null;
                try
                {
                    ds = GetData(openFileDialog1.FileName);

                    CheckTableFormat(ds.Tables[0]);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    return(false);
                }
                //到这里为止,说明Excel表中字段的结构已经正确

                //1.检查Excel中是否有重复的记录
                tempTable = CheckDataReduplicateInExcel(ds.Tables[0]);

                if (tempTable.Rows.Count > 0)
                {
                    DataSet tempDs = new DataSet();
                    tempDs.Tables.Add(tempTable);
                    //跳出一个窗体,显示Excel表格中重复的记录
                    TempForm tempForm = new TempForm("以下" + tempDs.Tables[0].Rows.Count + "条记录在Excel表中有重复,请核对后再导入");
                    tempForm.CurrentDataSet = tempDs;
                    tempForm.StartPosition  = FormStartPosition.CenterParent;
                    tempForm.ShowDialog();

                    return(false);
                }
                //2.检查Excel中是否有和数据库重复的记录
                tempTable = CheckDataReduplicateWithDatabase(ds.Tables[0]);

                if (tempTable.Rows.Count > 0)
                {
                    DataSet tempDs = new DataSet();
                    tempDs.Tables.Add(tempTable);
                    //跳出一个窗体,显示与数据库中记录重复的记录
                    TempForm tempForm = new TempForm("以下" + tempDs.Tables[0].Rows.Count + "条记录在数据库中已存在,请核对后再导入");
                    tempForm.CurrentDataSet = tempDs;
                    tempForm.StartPosition  = FormStartPosition.CenterParent;
                    tempForm.ShowDialog();

                    return(false);
                }

                //到这里可以安全的将数据导入到数据库
                ImportDataToDatabase(ds.Tables[0]);

                this.currentDataSet = SubscribeInfoManager.RetriveDataFromTempInfo();

                return(true);
            }
            return(false);
        }