예제 #1
1
        public bool GenericEditEvent(IEditable _geditForm, BindingSource actualEvents, bool isNew = false)
        {
            ulog = UserLog.Instance;

            try
            {
                DataRowView eventDataRowView;
                eventDataRowView = (isNew == false) ? (DataRowView)actualEvents.Current : (DataRowView)actualEvents.AddNew();
                if (eventDataRowView == null)
                    throw new Exception("Нет записей для редактирования.");

                using (IEditable editForm = _geditForm)
                {
                    if (editForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        actualEvents.EndEdit();

                        DateTime dt;
                        string _edit = (isNew == false) ? "Изменено " : "Добавлено ";

                        if (eventDataRowView.Row.Table.Columns.Contains("ActionDate"))
                        {
                            dt = Convert.ToDateTime(eventDataRowView["ActionDate"]);
                            _edit += "мероприятие на " + dt.ToShortDateString() + ".";
                        }
                        else if (eventDataRowView.Row.Table.Columns.Contains("DayID"))
                        {
                            _edit += "календарное мероприятие. День недели: " + DatabaseConstant.LocalDayOfWeek[Convert.ToInt32(eventDataRowView["DayID"]) - 1] + ".";
                        }

                        ulog.Message(_edit, UserLogMessageLevel.Warning);
                        return true;
                    }
                    else
                    {
                        actualEvents.CancelEdit();
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                ulog.Message(ex.Message, UserLogMessageLevel.Error);
                return false;
            }
        }
예제 #2
0
        /// <summary>
        /// 选择导入数据
        /// </summary>
        /// <param name="dsDetail">导入目标数据源</param>
        /// <param name="reportno">查询编号</param>
        /// <param name="fields">导入的字段,e.g: a=b,c=d 其中a和c为目标数据源中的字段,b和d为选择数据源中的字段,多个用英文逗号“,”进行分割</param>
        /// <param name="where">选择数据源的过滤条件</param>
        /// <param name="isautoselect">是否默认选中所有数据</param>
        public void SelectData(BindingSource dsDetail, string reportno, string fields, string where,bool isautoselect)
        {
            //数据选择窗体
            frmCommSelectForm frm = new frmCommSelectForm(reportno, where, isautoselect);
            frm.StartPosition = FormStartPosition.CenterParent;
            frm.WindowState = FormWindowState.Normal;
            frm.ReportNo = reportno;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                //解析需要设置值的字段
                string[] fieldstring = Public.GetSplitString(fields, ",");
                List<string> ValueFields = new List<string>();
                List<string> DataFields = new List<string>();
                foreach (string s in fieldstring)
                {
                    string[] ss = Public.GetSplitString(s, "=");
                    DataFields.Add(ss[0]);
                    ValueFields.Add(ss[1]);
                }

                //插入数据
                foreach (DataRow dr in frm.ResultData)
                {
                    dsDetail.AddNew();
                    for (int i = 0; i < DataFields.Count; i++)
                    {
                        ((DataRowView)dsDetail.Current).Row[DataFields[i]] = dr[ValueFields[i]];
                    }
                    dsDetail.EndEdit();
                }
            }
        }
        private void OnAddNew(object sender, EventArgs e)
        {
            if (bindingSource != null)
            {
                bindingSource.AddNew();
            }

            OnRefreshItems();
        }
예제 #4
0
 /// <devdoc>
 ///     Adds new item to BindingSource's list when the AddNewItem is clicked.
 /// </devdoc>
 private void OnAddNew(object sender, EventArgs e)
 {
     if (Validate())
     {
         if (bindingSource != null)
         {
             bindingSource.AddNew();
             RefreshItemsInternal();
         }
     }
 }
예제 #5
0
        public Form1()
        {
            InitializeComponent();

            BindingSource bs = new BindingSource();
            bs.DataSource = typeof(bab);
            bs.AddNew();

            dataLayoutControl1.AutoRetrieveFields = true;
            dataLayoutControl1.DataSource = bs;
        }
예제 #6
0
        public bool GenericEditAction(IEditable _geditForm, BindingSource actualActions, BindingSource groupHeadersList, bool isNew = false)
        {
            ulog = UserLog.Instance;
            try
            {
                DataRowView actionDataRowView;
                actionDataRowView = (isNew == false) ? (DataRowView)actualActions.Current : (DataRowView)actualActions.AddNew();
                if (actionDataRowView == null)
                    throw new Exception("Нет записей для редактирования.");

                using (IEditable editActForm = _geditForm)
                {//открываем форму и сохраняем изменения
                    if (editActForm.ShowDialog() == DialogResult.OK)
                    {
                        actualActions.EndEdit();
                        return true;
                    }
                    else
                    {
                        actualActions.CancelEdit();
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                actualActions.CancelEdit();
                ulog.Message(ex.Message, UserLogMessageLevel.Error);
                return false;
            }
            finally
            {
                groupHeadersList.RemoveFilter();
                groupHeadersList.Filter = "[InList] = 1";
            }
        }
예제 #7
0
        public static BindingSource GetBindBox(string TSQL, IDbConnection myConn)
        {
            bool mustClose = false;
            if (myConn == null)
            {
                mustClose = true;
                myConn = clsConn.getConnOLE();
            }
            if (myConn.State != ConnectionState.Open)
                myConn.Open();

            DataSet myDS = GetDataSet(TSQL, myConn as OleDbConnection);
            if (mustClose) myConn.Close();
            BindingSource myBind = new BindingSource();
            //
            myBind.DataSource = myDS;
            myBind.DataMember = myDS.Tables[0].ToString();
            myBind.AddNew();
            //Thêm 1 dòng trắng cuối cùng của list
            //
            return myBind;
        }
예제 #8
0
 private void LoadCboDonViTrucThuoc()
 {
     DataTable dvlist = donvi.GetActiveDonVi();
     BindingSource bs = new BindingSource();
     bs.DataSource = dvlist;
     bs.AddNew();
     comB_TrucThuoc.DataSource = bs;
     comB_TrucThuoc.DisplayMember = "ten_don_vi";
     comB_TrucThuoc.ValueMember = "id";
 }
예제 #9
0
파일: mia.cs 프로젝트: INGENIUSCuba/c--code
        // el Bs de persona, el bs del elemento a tratar, el dgv del elemento a tratar
        // el maximo del id de el elemento a tratar
        // el elemnto donde quiro pararme al adicionar un elemento(nombre)
        // el nombre del id que tiene el dgv a tratar(id)
        // el nombre q tiene id id perosna en la tabla especifica
        public static void inserta_persona(BindingSource persona, BindingSource bs, DataGridView dgv, int max, string nombre, string id, string id_detalle)
        {
            if (dgv.Rows.Count > 0) dgv.CurrentCell = dgv.CurrentRow.Cells[nombre];

            if (max >= 10000)  max = max + 1;
            else  max = Convert.ToInt32(Convert.ToString(mia.id_centro) + "0001");

            bs.AddNew();
            dgv.Rows[dgv.Rows.Count - 1].Cells[id].Value = max;
            dgv.CurrentCell = dgv.CurrentRow.Cells[nombre];

            DataRowView view = (DataRowView)persona.Current;
            dgv.Rows[dgv.Rows.Count - 1].Cells[id_detalle].Value = view["id"].ToString();
            dgv.Focus();
        }
예제 #10
0
파일: mia.cs 프로젝트: INGENIUSCuba/c--code
        public static void inserta_asesoria(BindingSource bs, DataGridView dgv, ToolStripButton bn, int max, string nombre, string id)
        {
            if (dgv.Rows.Count > 0)
            {
                bn.Enabled = true;
                dgv.CurrentCell = dgv.CurrentRow.Cells[nombre];
            }

            if (max >= 10000) max = max + 1;
            else max = Convert.ToInt32(Convert.ToString(mia.id_centro) + "0001");

            bs.AddNew();
            dgv.Rows[dgv.Rows.Count - 1].Cells[id].Value = max;
            dgv.CurrentCell = dgv.CurrentRow.Cells[nombre];
        }
예제 #11
0
        private void Salvar_Click(object sender, EventArgs e)
        {
            string AdicionarAoHistorico = "";

            if (index == -1)
            {
                if (Nome.Text == "")
                {
                    MessageBox.Show("Insira um nome!", "erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (AulasPagas.Text == "")
                {
                    MessageBox.Show("Insira um número de aulas!", "erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if ((CodigoRFID == "" || CodigoRFID == "0" || CodigoRFID == "-2") && checkBox1.Checked)
                {
                    MessageBox.Show("nenhum cartão foi lido!", "erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                int resultado;
                if (!int.TryParse(AulasPagas.Text, out resultado))
                {
                    MessageBox.Show("há algo errado com a formatação do número de aulas! Talvez haja um espaço sobrando entre os caracteres.", "erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (comboBox1.SelectedIndex == -1)
                {
                    MessageBox.Show("Selecione o gênero do(a) aluno(a)!", "erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (!int.TryParse(NumeroCartao.Text, out resultado))
                {
                    if (NumeroCartao.Text != "")
                    {
                        MessageBox.Show("há algo errado com a formatação do número do cartão! Talvez haja um espaço sobrando entre os caracteres.", "erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        NumeroCartao.Text = "0";
                    }
                }
                else if (resultado == 0)
                {
                    if (MessageBox.Show("Deixar o número do cartão do aluno como 0 pode dificultar caso o aluno confuda seu cartão. Certeza que quer deixar assim?", "Cuidado!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                    {
                        return;
                    }
                }
            }
            else
            {
                if ((string)Aluno[colunas.Nome] != Nome.Text)
                {
                    AdicionarAoHistorico += "\n\tNome mudado de:\n\t\t" + (string)Aluno[colunas.Nome] + "\n\tpara:\n\t\t" + Nome.Text;
                }
                if ((string)Aluno[colunas.CodigoRFID] != CodigoRFID)
                {
                    AdicionarAoHistorico += "\n\tCartão atualizado";
                }
                if ((bool)Aluno[colunas.AlunoAtivo] != checkBox1.Checked)
                {
                    if (checkBox1.Checked)
                    {
                        AdicionarAoHistorico += "\n\tAluno reativado";
                    }
                    else
                    {
                        AdicionarAoHistorico += "\n\tAluno desativado";
                    }
                }
                if ((string)Aluno[colunas.historicoMedico] != historico_med.Text)
                {
                    AdicionarAoHistorico += "\n\tHistórico médico atualizado";
                }
                if ((string)Aluno[colunas.Anotacoes] != anotacoes.Text)
                {
                    AdicionarAoHistorico += "\n\tanotações atualizadas";
                }
                if (data.Text != (string)Aluno[colunas.dataInscricao])
                {
                    AdicionarAoHistorico += "\n\tData de inscrição mudada de " + (string)Aluno[colunas.dataInscricao] + " para " + data.Text;
                }
                if (horarios.Text != (string)Aluno[colunas.HorariosAulas])
                {
                    if ((string)Aluno[colunas.HorariosAulas] == "")
                    {
                        AdicionarAoHistorico += "\n\tHorários das aulas adicionados";
                    }
                    else
                    {
                        AdicionarAoHistorico += "\n\tHorários das aulas mudados de:\n\t\t" + (string)Aluno[colunas.HorariosAulas] + "\n\tpara:\n\t\t" + horarios.Text;
                    }
                }
                if ((string)Aluno[colunas.Genero] != utilidades.genero[comboBox1.SelectedIndex])
                {
                    AdicionarAoHistorico += "\n\tGênero do aluno mudado de " + (string)Aluno[colunas.Genero] + " para " + utilidades.genero[comboBox1.SelectedIndex];
                }
                if ((string)Aluno[colunas.Email] != email.Text)
                {
                    if ((string)Aluno[colunas.Email] == "")
                    {
                        AdicionarAoHistorico += "\n\tEmail adicionado";
                    }
                    else
                    {
                        AdicionarAoHistorico += "\n\tEmail mudado de:\n\t\t" + (string)Aluno[colunas.Email] + "\n\tpara:\n\t\t" + email.Text;
                    }
                }
                if ((string)Aluno[colunas.Telefone] != telefone.Text)
                {
                    if ((string)Aluno[colunas.Telefone] == "")
                    {
                        AdicionarAoHistorico += "\n\tTelefone adicionado";
                    }
                    else
                    {
                        AdicionarAoHistorico += "\n\tTelefone mudado de:\n\t\t" + (string)Aluno[colunas.Telefone] + "\n\tpara:\n\t\t" + telefone.Text;
                    }
                }
                if ((int)Aluno[colunas.NumeroCartao] != int.Parse(NumeroCartao.Text))
                {
                    if ((int)Aluno[colunas.NumeroCartao] == 0)
                    {
                        AdicionarAoHistorico += "\n\tNúmero do cartão adicionado!";
                    }
                    else
                    {
                        AdicionarAoHistorico += "\n\tNúmero do cartão mudado de:\n\t\t" + (string)Aluno[colunas.NumeroCartao] + "\n\tpara:\n\t\t" + NumeroCartao.Text;
                    }
                }
                if ((string)Aluno[colunas.Aniversario] != Aniversario.Value.ToShortDateString())
                {
                    AdicionarAoHistorico += "\n\tAniversário do aluno mudado de " + (string)Aluno[colunas.Aniversario] + " para " + Aniversario.Text;
                }
            }
            lock (TravaAtualizacao)
            {
                if (index == -1)
                {
                    Aluno = (DataRowView)AlunosBindingSource.AddNew();
                }
                Aluno[colunas.Nome]            = Nome.Text;
                Aluno[colunas.CodigoRFID]      = CodigoRFID;
                Aluno[colunas.AulasPagas]      = int.Parse(AulasPagas.Text);
                Aluno[colunas.AlunoAtivo]      = checkBox1.Checked;
                Aluno[colunas.HorariosAulas]   = horarios.Text;
                Aluno[colunas.Genero]          = utilidades.genero[comboBox1.SelectedIndex];
                Aluno[colunas.historicoMedico] = historico_med.Text;
                Aluno[colunas.Telefone]        = telefone.Text;
                Aluno[colunas.Email]           = email.Text;
                Aluno[colunas.Anotacoes]       = anotacoes.Text;
                Aluno[colunas.dataInscricao]   = data.Text;
                Aluno[colunas.UltimaEntrada]   = string.Empty;
                if (int.TryParse(NumeroCartao.Text, out int resultado))
                {
                    Aluno[colunas.NumeroCartao] = resultado;
                }
                else
                {
                    Aluno[colunas.NumeroCartao] = 0;
                }
                Aluno[colunas.Aniversario] = Aniversario.Value.Date.ToShortDateString();

                bool     FezAniversarioEsseAno = false;
                DateTime Hoje        = DateTime.Now.Date;
                DateTime aniversario = Aniversario.Value.Date;
                if (Hoje.Month < aniversario.Month)
                {
                    FezAniversarioEsseAno = false;
                }
                else if (Hoje.Month == aniversario.Month)
                {
                    if (Hoje.Day < aniversario.Day)
                    {
                        FezAniversarioEsseAno = false;
                    }
                    else
                    {
                        FezAniversarioEsseAno = true;
                    }
                }
                else
                {
                    FezAniversarioEsseAno = true;
                }

                if (FezAniversarioEsseAno)
                {
                    Aluno[colunas.Idade] = Hoje.Year - aniversario.Year;
                }
                else
                {
                    Aluno[colunas.Idade] = Hoje.Year - aniversario.Year - 1;
                }
                if (index == -1)
                {
                    HLista.Add(new EntradaHistorico(DateTime.Now.Date, "Aluno cadastrado no dia " + DateTime.Now.ToShortDateString() + "."));
                    Aluno[colunas.Historico]        = JsonConvert.SerializeObject(HLista);
                    Aluno[colunas.HistoricoAulas]   = "-";
                    Aluno[colunas.RegistroMedicoes] = "-";
                    this.Validate();
                    this.AlunosBindingSource.EndEdit();
                    this.AlunosTableAdapterManager.UpdateAll(this.database_alunosDataSet);
                    AlunosTableAdapter.Fill(database_alunosDataSet.Alunos);
                    this.Close();
                }
                else
                {
                    int indice = HLista.FindIndex(x => x.Data == DateTime.Now.Date);
                    if (indice == -1)
                    {
                        if (AdicionarAoHistorico != "")
                        {
                            HLista.Add(new EntradaHistorico(DateTime.Now.Date, DateTime.Now.ToShortTimeString() + " - aluno editado:" + AdicionarAoHistorico));
                        }
                    }
                    else
                    {
                        HLista[indice].Entrada += "\n\n" + DateTime.Now.ToShortTimeString() + "- aluno editado:" + AdicionarAoHistorico;
                    }
                    Aluno[colunas.Historico] = JsonConvert.SerializeObject(HLista);
                    this.Validate();
                    this.AlunosBindingSource.EndEdit();
                    this.AlunosTableAdapterManager.UpdateAll(this.database_alunosDataSet);
                    HLista.Sort((x, y) => x.Data.CompareTo(y.Data));
                    HBindingSource.Clear();
                    foreach (EntradaHistorico entrada in HLista)
                    {
                        HBindingSource.Add(entrada.ParaBS());
                    }
                }
            }
            MessageBox.Show(((index == -1) ? "Aluno adicionado" : "Atualização feita") + " com sucesso!", "Sucesso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            if (index == -1)
            {
                this.Close();
            }
        }
예제 #12
-1
        private void CreateNewBlankPurchaseOrderDetail(BindingSource bill)
        {
            PurchaseOrderDetail orderDetail = (PurchaseOrderDetail)bill.AddNew();
            orderDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            orderDetail.CreateDate = DateTime.Now;
            orderDetail.UpdateDate = DateTime.Now;
            orderDetail.UpdateId = orderDetail.CreateId;
            orderDetail.DelFlg = 0;
            orderDetail.DepartmentId = CurrentDepartment.Get().DepartmentId;
            orderDetail.Quantity = 1;

            PurchaseOrderDetailPK purchaseOrderDetailPK = new PurchaseOrderDetailPK();
            purchaseOrderDetailPK.DepartmentId = CurrentDepartment.Get().DepartmentId;
            orderDetail.PurchaseOrderDetailPK = purchaseOrderDetailPK;

            // new product to test
            ProductMaster productMaster = new ProductMaster();
            orderDetail.ProductMaster = productMaster;
            Product product = new Product();
            product.ProductMaster = orderDetail.ProductMaster;
            orderDetail.Product = product;
            bill.EndEdit();
        }