private void SaveDataToDatabase()
 {
     try
     {
         if (import == null || importDetails == null)
         {
             pcloader.Invoke(new MethodInvoker(delegate
             {
                 pcloader.Visible = false;
             }));
             MessageBox.Show("importMapWorkMember is null or ImportMapWorkMemberDetails is null");
         }
         else
         {
             ctx.ExceptionWorks.Add(import);
             foreach (var item in importDetails)
             {
                 ctx.ExceptionWorkDetails.Add(item);
             }
             ctx.SaveChanges();
             statusTripMain.Invoke(new MethodInvoker(delegate
             {
                 tssLblInfo.Text = "Save data to database be successfull";
             }));
         }
     }
     catch (Exception)
     {
         pcloader.Invoke(new MethodInvoker(delegate
         {
             pcloader.Visible = false;
         }));
         MessageBox.Show("Exist or error");
     }
 }
Example #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         int id    = -1;
         int count = 0;
         for (int i = 0; i < dgvMain.Rows.Count; i++)
         {
             if (dgvMain.Rows[i].Cells[0].Value != null && (bool)dgvMain.Rows[i].Cells[0].Value == true)
             {
                 count++;
                 id = (int)dgvMain.Rows[i].Cells["Id"].Value;
                 if (count > 1)
                 {
                     MessageBox.Show("Please choise only one record!");
                     return;
                 }
             }
         }
         if (id == -1)
         {
             MessageBox.Show("Please must choise one record!");
             return;
         }
         CurrenContractObject = ctx.ContractObjects.Where(s => s.Id == id).First();
         if (CurrenContractObject == null)
         {
             MessageBox.Show("Eror: recode is null");
             return;
         }
         var confirmResult = MessageBox.Show("Are you sure to delete this record?",
                                             "Confirm Delete!!",
                                             MessageBoxButtons.YesNo);
         if (confirmResult == DialogResult.Yes)
         {
             ctx.ContractObjects.Remove(CurrenContractObject);
             int check = ctx.SaveChanges();
             if (check < 1)
             {
                 MessageBox.Show("Delete is error");
             }
             else
             {
                 LoadDta();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.ToString());
     }
 }
 private void SaveDataToDatabase()
 {
     try
     {
         if (distributionData == null || distributionDataItems == null)
         {
             pcloader.Invoke(new MethodInvoker(delegate
             {
                 pcloader.Visible = false;
             }));
             MessageBox.Show("importMapWorkMember is null or ImportMapWorkMemberDetails is null");
         }
         else
         {
             //if (distributionData != null)
             //{
             //    distributionData.MemberBHId = guidBhMember;
             //    distributionData.ImportMapWorkMemberId = guidWorkMember;
             //    distributionData.ExceptionWorkId = guidExceptWorkMember;
             //}
             ctx.DistributionDatas.Add(distributionData);
             foreach (var item in distributionDataItems)
             {
                 item.Royalty = decimal.Round(item.Royalty, 6);
                 ctx.DistributionDataItems.Add(item);
             }
             ctx.SaveChanges();
             statusTripMain.Invoke(new MethodInvoker(delegate
             {
                 tssLblInfo.Text = "Save data to database be successfull";
             }));
         }
     }
     catch (Exception ex)
     {
         pcloader.Invoke(new MethodInvoker(delegate
         {
             pcloader.Visible = false;
         }));
         MessageBox.Show(ex.ToString());
     }
 }
Example #4
0
        private void SaveDataToDB(string[] idList, Distibution distibution)
        {
            try
            {
                if (idList.Length > 0 && distibution != null)
                {
                    VcpmcContext vcpmcContext = new VcpmcContext();

                    //vcpmcContext.SaveChanges();
                    long count = 0;
                    for (int i = 0; i < idList.Length; i++)
                    {
                        foreach (var item in distributionDatas)
                        {
                            if (item.Id.ToString() == idList[i])
                            {
                                //3.save detail
                                foreach (var item2 in item.DistributionDataItems)
                                {
                                    vcpmcContext.DistributionDataItems.Add(item2);
                                    count++;
                                }
                                //2.save master2
                                //TODO
                                //item.DistibutionId = distibution.Id;
                                item.StatusSaveDataToDatabase = true;
                                vcpmcContext.DistributionDatas.Add(item);
                                break;
                            }
                        }
                        //break;
                    }
                    //
                    //1.save master
                    distibution.TotalRecord = count;
                    vcpmcContext.Distibutions.Add(distibution);

                    vcpmcContext.SaveChanges();
                    distibution = null;
                    dgvListFile.Invoke(new MethodInvoker(delegate
                    {
                        for (int i = 0; i < dgvListFile.RowCount; i++)
                        {
                            if ((bool)dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Value == true)
                            {
                                dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.BackColor = Color.Green;
                                dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.ForeColor = Color.White;
                            }
                            else
                            {
                                dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.BackColor = Color.Red;
                                dgvListFile.Rows[i].Cells["StatusSaveDataToDatabase"].Style.ForeColor = Color.White;
                            }
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (_ctx == null)
                {
                    MessageBox.Show("Connect database is error!");
                    return;
                }
                GetDataFromUI();
                if (_updataType == UpdataType.Add)
                {
                    //add
                    _ctx.ContractObjects.Add(_contractObjects);
                    //save change
                    int check = _ctx.SaveChanges();
                    if (check < 1)
                    {
                        MessageBox.Show("Edit data is error");
                        return;
                    }
                }
                else if (_updataType == UpdataType.Edit)
                {
                    var item = (from s in _ctx.ContractObjects
                                where
                                s.Id == _contractObjects.Id
                                select s
                                ).FirstOrDefault();
                    if (item == null)
                    {
                        MessageBox.Show("Not find in the table, don't update!");
                        return;
                    }
                    else
                    {
                        #region Common
                        item.Customer = _contractObjects.Customer;
                        item.Address  = _contractObjects.Address;
                        item.District = _contractObjects.District;
                        item.Phone    = _contractObjects.Phone;
                        item.Contact  = _contractObjects.Contact;
                        item.TaxCode  = _contractObjects.TaxCode;
                        #endregion

                        #region Contract
                        item.License        = _contractObjects.License;
                        item.ContractNumber = _contractObjects.ContractNumber;
                        item.Field          = _contractObjects.Field;

                        item.ContractTime = _contractObjects.ContractTime;
                        item.StartTime    = _contractObjects.StartTime;
                        item.EndTime      = _contractObjects.EndTime;

                        item.NameSign = _contractObjects.NameSign;
                        item.Vat      = _contractObjects.Vat;
                        item.Value    = _contractObjects.Value;

                        item.Address2     = _contractObjects.Address2;
                        item.Note         = _contractObjects.Note;
                        item.IsReSigned   = _contractObjects.IsReSigned;
                        item.NoteReSigned = _contractObjects.NoteReSigned;
                        #endregion

                        #region Position
                        item.Ground  = _contractObjects.Ground;
                        item.Badger  = _contractObjects.Badger;
                        item.Floor1  = _contractObjects.Floor1;
                        item.Floor2  = _contractObjects.Floor2;
                        item.Floor3  = _contractObjects.Floor3;
                        item.Floor4  = _contractObjects.Floor4;
                        item.Floor5  = _contractObjects.Floor5;
                        item.Floor6  = _contractObjects.Floor6;
                        item.Floor7  = _contractObjects.Floor7;
                        item.Floor8  = _contractObjects.Floor8;
                        item.Floor9  = _contractObjects.Floor9;
                        item.Floor10 = _contractObjects.Floor10;
                        item.Terrace = _contractObjects.Terrace;

                        item.CountGround  = _contractObjects.CountGround;
                        item.CountBadger  = _contractObjects.CountBadger;
                        item.CountFloor1  = _contractObjects.CountFloor1;
                        item.CountFloor2  = _contractObjects.CountFloor2;
                        item.CountFloor3  = _contractObjects.CountFloor3;
                        item.CountFloor4  = _contractObjects.CountFloor4;
                        item.CountFloor5  = _contractObjects.CountFloor5;
                        item.CountFloor6  = _contractObjects.CountFloor6;
                        item.CountFloor7  = _contractObjects.CountFloor7;
                        item.CountFloor8  = _contractObjects.CountFloor8;
                        item.CountFloor9  = _contractObjects.CountFloor9;
                        item.CountFloor10 = _contractObjects.CountFloor10;
                        item.CountTerrace = _contractObjects.CountTerrace;
                        #endregion
                        //save change
                        int check = _ctx.SaveChanges();
                        if (check < 0)
                        {
                            MessageBox.Show("Edit data is error");
                            return;
                        }
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.ToString()}");
            }
        }